var goellner = {
  
  switch_optionImages : {
    changeOptionimage : function(attribute_id,option_id)
    {
      if(typeof($$('.product-large-image img')[0]) != 'undefined')
      { 
        if(typeof(this.originalImage)=='undefined')
          this.originalImage = $$('.product-large-image img')[0].src;
        
        if(typeof($$('.a'+attribute_id+'_o'+option_id)[0])!='undefined')
          $$('.product-large-image img')[0].src = $$('.a'+attribute_id+'_o'+option_id)[0].rev;
        else
          $$('.product-large-image img')[0].src = this.originalImage;
      }
      
      options = spConfig.getAttributeOptions(attribute_id);
      
      if(typeof(options)!='undefined')
      {
        for(i=0; i<spConfig.getAttributeOptions(attribute_id).length; i++)
        {
          if(spConfig.getAttributeOptions(attribute_id)[i].id == option_id)
          {
      
            if(typeof($$('.not-available')[0])!='undefined')
            {
              console.debug(spConfig.getAttributeOptions(attribute_id)[i]);

              $$('.not-available')[0].setStyle({display:parseInt(spConfig.getAttributeOptions(attribute_id)[i].qty)<=0?'inline':'none'});
              $$('.is-deliverable')[0].setStyle({display:parseInt(spConfig.getAttributeOptions(attribute_id)[i].qty)<=0?'none':'inline'});
              
              if(parseInt(spConfig.getAttributeOptions(attribute_id)[i].qty)<=0)
                $$('.add-to-cart').each(function(el,i) { el.setStyle({display:'none'}); });
              else
                $$('.add-to-cart').each(function(el,i) { el.setStyle({display:'block'}); });
            }
    
            break;
          }
        }
      }
    }
  },
  
  decorateProductList : function(addMouseOver)
  {
    if(typeof(addMouseOver)!='undefined' || addMouseOver!==true)
      addMouseOver = false;
      
    $$(".products-list .item .the-image").each( function(input,index) {
      /*
          // add a tooltip to the product list item
           new Tooltip(
            input, {
              backgroundColor: "#fff",
              borderColor: "#fff", 
              textColor: "#000",
              textShadowColor: "#FFF",
              opacity: 0.9
            }
          );
      */

      // add a slideshow to the item...
      if(typeof(input.rev)!="undefined")
      {
        if(input.rev != null && input.rev!='')
        { 
          if((images = unescape(input.rev).split('|')).length>1)
          { 
            input.getElementsByTagName('img')[0].id = 'slideshow'+index;
            
            images = unescape(input.rev).split('|');
            images.push(images[0]);
            images.shift();
  
            input.slideshow = new Widget.Fader(
              input.getElementsByTagName('img')[0].id,
              images,
              {
                fadeInDuration: 0.5,
                fadeOutDuration: 0.05,
                displayDuration: 2,
                autoStart: false              
              }
            );  
  
            if(addMouseOver)
            {
              input.up('li').observe('mouseenter',function(e){ 
                if(!this.hasClassName('issliding'))
                {
                  $$(".products-list .item.has-slideshow").each(function(el,j){
                    el.removeClassName('issliding').down('.the-image').slideshow.stop();
                  });
                  
                  this.addClassName('issliding');
                  this.down('.the-image').slideshow.start();
                }
              });
      
              input.up('li').observe('mouseleave',function(e){
                if(this.hasClassName('issliding'))
                {
                  $$(".products-list .item.has-slideshow").each(function(el,j){
                    el.removeClassName('issliding').down('.the-image').slideshow.stop();
                  });
    
                  $$(".products-list .item.main-slideshow")[0].addClassName('issliding').down('.the-image').slideshow.start();
                }
              });
            }
            
            input.up('li').addClassName('has-slideshow');
          }
        }
      }
    });
  
    // start a slideshow randomly...
    if($$(".products-list .item.has-slideshow").length>0)
    {
      num = Math.floor(Math.random()*$$(".products-list .item.has-slideshow").length);
  
      $$(".products-list .item.has-slideshow")[num].addClassName('main-slideshow').addClassName('issliding').down('.the-image').slideshow.start();
  
    }
  },
  
  addExpander : function()
  {
    $$('.clip').each(function(std,el){
      if(std.getHeight() < std.select('.text')[0].getHeight())
      {
        Element.insert(std, { bottom :  new Element('span',{'class':'shader'}) });
        
        readon = new Element('a', {
          'href' : 'javascript:void(0)',
          'class' : 'read-on'
        })
        .update(goellner.translate('read on...'))
        .observe('click',function(){
          this.up().select('.clip')[0].removeClassName('clip');
          this.remove();
        });
        
        Element.insert(std, { after :  readon});
      }
    })
  },
  
  translate : function(word)
  { 
    if(LocalizedStrings)
    {
      if(LocalizedStrings[word])
      {
        return LocalizedStrings[word];
      }
    }
    return word;
  },
  
  addFilterOptions : function()
  {
    $$('.filter-options .the-label').each(function(el,i){
      if(el.next('.the-options'))
      {
        el.observe('click',function(){
          if(this.clonedDiv)
          {
            this.clonedDiv.remove();
            this.clonedDiv = null;
          }
          else
          {
            this.clonedDiv = this.next('.the-options').cloneNode(true).setStyle({
              'position':'absolute',
              'z-index':99,
              'display':'block',
              'top':this.cumulativeOffset().top+this.getDimensions().height+'px',
              'left':this.cumulativeOffset().left+'px'
            }).insert(new Element('a', { 'class': 'close', href: 'javascript:void(0)' }).update(goellner.translate('Close filter options')).observe('click',function(){ this.click()}.bind(this)));
            
            $$('body')[0].insert(this.clonedDiv);
            
            this.clonedDiv.select('.option').each(function(opt,j){
              opt.observe('click',function(){
                this.insert(new Element('div',{
                  'class'    : 'loader'
                }));
              }.bind(this));
            }.bind(this.clonedDiv));
          }
        });
      }
    });
  },
  
  minicart : function() {
   
    if(tmp = $('cart-overview'))
    {
      tmp = tmp.cloneNode(true).setStyle({
        'top':($('cart-overview').getHeight()*-1)+'px',
        'display':'block'
      });
      $('cart-overview').remove();
      $$('#page .centerme')[0].insert(tmp);
      
      $('cart-overview').mouseOver = false;
      
      $('cart-overview').fadeIn = function () {
        window.clearTimeout($('cart-overview').timer);
        
        $('cart-overview').Tweener = new Effect.Tween(
          $('cart-overview'),
          Position.cumulativeOffset($('cart-overview'))[1],
          $('header').getHeight()-10,
          {
            duration: 0.75,
            transition: Effect.Transitions.sinoidal,
            queue: { position: 'end', scope: 'sinsationsCartFading', limit: 1}
          },
          function(p) {
            Element.setStyle(this,{top : parseInt(p)+'px'});
          }
        );
      }
  
      $('cart-overview').fadeOut = function () {
        queue = Effect.Queues.get('sinsationsCartFading');
        queue.each(function(effect) { effect.cancel(); });
  
        $('cart-overview').Tweener = new Effect.Tween(
          $('cart-overview'),
          Position.cumulativeOffset($('cart-overview'))[1],
          ($('cart-overview').getHeight()*-1),
          {
            duration: 0.75,
            transition: Effect.Transitions.sinoidal
          },
          function(p) {
            Element.setStyle(this,{top : parseInt(p)+'px'});
          }
        );
      }
      
      $('minicart').observe('mouseenter', $('cart-overview').fadeIn);
      $('minicart').observe('mouseleave', function() { $('cart-overview').timer = window.setTimeout('$(\'cart-overview\').fadeOut()',500); });
      $('cart-overview').observe('mouseenter', $('cart-overview').fadeIn);
      $('cart-overview').observe('mouseleave', function() { $('cart-overview').timer = window.setTimeout('$(\'cart-overview\').fadeOut()',500); });    
    }
  },
  
  addHeaderMovie : function()
  { 
    container = 'headermovie';
    if(typeof(FLASH_DIR) == 'undefined')
      FLASH_DIR = '/skin/frontend/sinsations/default/flash/';
    
    movies = new Array();
    movies.push({ swf:'colibri.swf',width:104,height:74,x:242,y:11,bg: '#000000' });
    movies.push({ swf:'inkdrop.swf',width:141,height:84,x:245,y:0,bg: '#000000' });
    movies.push({ swf:'vines.swf',width:316,height:81,x:0,y:0,bg: '#000000' });
    
    movie = movies[Math.ceil(Math.random()*movies.length)-1];
    
    $(container).setStyle({
      position: 'absolute',
      zIndex: 1,
      top: movie.y+'px',
      left: movie.x+'px',
      width: movie.width+'px',
      height: movie.height+'px'
    });
    
    swfobject.embedSWF(FLASH_DIR+movie.swf, container+'_video', movie.width, movie.height, "8", FLASH_DIR+"playerProductInstall.swf",false, {quality:"high",wmode:"opaque",scale:"scale",salign:"tl",menu:"false",bgcolor:movie.bg}, false);
  },
  
  addBanner : function()
  {
    if($('sidebar-banner')!=null)
    {
      swfobject.embedSWF(DEFAULT_DIR+'flash/banner.swf', 'sidebar-banner', '100%', '100%', "8", false,{}, {quality:"high",wmode:"transparent",scale:"noscale",salign:"tl",menu:"false"}, false);
      if(!swfobject.hasFlashPlayerVersion("8"))
      { 
        $('sidebar-banner').insert('<img src="'+DEFAULT_DIR+'images/banner.png" /></a>');
      }
    }  
  },
  
  addMainMenuHover : function()
  {
    $$('#navigation li.level0').each(function(el,i){ 
      if(el.select('ul').length)
      {
        el.fadein = function()
        {
          this.obj = new Element('div').addClassName('mainMenuDropDown cf').setStyle({
            'display':'block',
            'opacity':0,
            'margin-left':'-1000em'
          })
          .update('<h2 class="headline '+this.select('span')[0].innerHTML.toLowerCase()+'"><span>'+this.select('span')[0].innerHTML+'</span></h2>')
          .insert(this.select('ul')[0].cloneNode(true));
          
          $('content').insert(this.obj);
          
          cnt = this.obj.childElements().length;
          for(i=0; i<cnt; i=i+5)
          {
            if(i>0)
              Element.insert(this.obj.childElements()[i],{ 'before':new Element('li', { 'class': 'breakli'}).update('&nbsp;')} );
            
          }
          height = this.obj.getHeight();
          
          this.obj.setStyle({
            'margin-left':'0',
            'height':'0'
          });

          this.obj.observe('mouseenter',function(){
            if($('navigation').timer) window.clearTimeout($('navigation').timer);
            if(this.timer) window.clearTimeout(this.timer);
          }.bind(this));
          this.obj.observe('mouseleave',function(){
            if($('navigation').timer) window.clearTimeout($('navigation').timer);
            if(this.timer) window.clearTimeout(this.timer);
            this.timer = this.fadeout.bind(this).delay(0);

          }.bind(this));

          this.obj.effect = new Effect.Morph(this.obj, {
            style:'opacity:1; height:'+height+'px',
            duration:0.4
          });
        }
        el.fadeout = function()
        {
          if(this.obj)
          {
            this.obj.effect = new Effect.Morph(this.obj, {
              style:'opacity:0; height:0px',
              duration:0.2,
              afterFinish:function(){
                try { this.remove(); } catch(e) { }
              }.bind(this.obj)
            });
          }
        }
        
        el.select('a')[0].observe('mouseenter',function(){
          if($('navigation').timer) window.clearTimeout($('navigation').timer);
          $('navigation').timer = this.up('li').fadein.bind(this.up('li')).delay(0.5);
        });
        el.select('a')[0].observe('mouseleave',function(){
          if($('navigation').timer) window.clearTimeout($('navigation').timer);
          if(this.up('li').timer) window.clearTimeout(this.up('li').timer);
          this.up('li').timer = this.up('li').fadeout.bind(this.up('li')).delay(0.3);
        });
      }
    });
  },
  
  addHomepageTeaserSlideshow : function()
  {
    $$('.homepage-teaser .products-list').each(function(el,i){
      if(el.select('li.item').length > 1)
      {
        el.currentItem = 0;
        
        el.nextItem = function()
        {
          new Effect.Morph(this.select('li.item')[this.currentItem], {
            style:'opacity:0',
            duration:0.5,
            afterFinish:function(){
              this.select('li.item')[this.currentItem].setStyle({'display':'none'});
              this.currentItem = this.currentItem<this.select('li.item').length-1 ? this.currentItem+1 : 0;
              this.select('li.item')[this.currentItem].setStyle({'display':'block','opacity':0});
              new Effect.Morph(this.select('li.item')[this.currentItem], {
                style:'opacity:1',
                afterFinish:function(){
                  this.timer = this.nextItem.delay(3);
                }.bind(this)
              });
            }.bind(this)
          });
        }.bind(el);
        el.nextItem.delay(3);
      }
    });
  },
  
  noRightClickOnImages : function()
  {
    if(document.images)
      for(i=0;i<document.images.length;i++)
        document.images[i].oncontextmenu = function() { return false; };
  },
  
  init : function()
  { 
    this.noRightClickOnImages();

    this.decorateProductList();
    this.addExpander();
    this.addFilterOptions();
    this.minicart();

    this.addHeaderMovie();
    
    this.addBanner();
    
    this.addMainMenuHover();
    
    this.addHomepageTeaserSlideshow();
  },
  
  quit : function()
  {
    // $$('.homepage-teaser .products-list').each(function(el,i){ try { window.clearTimeout(el.timer); } catch(e) { }; });
    
    // detach main menu dropdown
    try { window.clearTimeout($('navigation').timer); } catch(e) { };
    $$('#navigation li.level0').each(function(el,i){
      try { window.clearTimeout(el.timer); } catch(e) { };
      el.fadein = function() { return null; }
      try { el.fadeout(); } catch(e) { }
    });
  }
}

var opcslide = {
  updateSteps : function(){
    $$('#checkoutSteps>li').each(function(el,i){
      try {
        $$('#step-overview li')[i].className=el.className;
      } catch(e) { }
    });
  }
}

document.observe('dom:loaded', function() { goellner.init() });
Event.observe(window, 'beforeunload', function(){ goellner.quit() });


/**
* Event.simulate(@element, eventName[, options]) -> Element
*
* - @element: element to fire event on
* - eventName: name of event to fire (only MouseEvents and HTMLEvents interfaces are supported)
* - options: optional object to fine-tune event properties - pointerX, pointerY, ctrlKey, etc.
*
* $('foo').simulate('click'); // => fires "click" event on an element with id=foo
*
**/
(function(){
  
  var eventMatchers = {
    'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
    'MouseEvents': /^(?:click|mouse(?:down|up|over|move|out))$/
  }
  var defaultOptions = {
    pointerX: 0,
    pointerY: 0,
    button: 0,
    ctrlKey: false,
    altKey: false,
    shiftKey: false,
    metaKey: false,
    bubbles: true,
    cancelable: true
  }
  
  Event.simulate = function(element, eventName) {
    var options = Object.extend(defaultOptions, arguments[2] || { });
    var oEvent, eventType = null;
    
    element = $(element);
    
    for (var name in eventMatchers) {
      if (eventMatchers[name].test(eventName)) { eventType = name; break; }
    }

    if (!eventType)
      throw new SyntaxError('Only HTMLEvents and MouseEvents interfaces are supported');

    if (document.createEvent) {
      oEvent = document.createEvent(eventType);
      if (eventType == 'HTMLEvents') {
        oEvent.initEvent(eventName, options.bubbles, options.cancelable);
      }
      else {
        oEvent.initMouseEvent(eventName, options.bubbles, options.cancelable, document.defaultView,
          options.button, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
          options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, element);
      }
      element.dispatchEvent(oEvent);
    }
    else {
      options.clientX = options.pointerX;
      options.clientY = options.pointerY;
      oEvent = Object.extend(document.createEventObject(), options);
      element.fireEvent('on' + eventName, oEvent);
    }
    return element;
  }
  
  Element.addMethods({ simulate: Event.simulate });
})()





document.observe("dom:loaded", function() {
//  __pageStyles._init();
//  __roundCorners._init();
//  __toolTipImages._init();
//  __newsSlider._init();
});

var __newsSlider = {
  delaytime : 5,
  _init : function()
  {
    if($$('.blog-content').length > 0)
    {
      $$('.blog-content').each(function(el,i){
        if(el.getElementsByClassName('postWrapper'))
        { 
          items = el.getElementsByClassName('postWrapper');

          if(items.length >1)
          {
            el.slider = {
              items : items,
              current : 0,
              next : 1,
              hide : function()
              {
                if(this.current >= this.items.length-1) this.next = 0;
                else this.next++;
                
                new Effect.Fade(this.items[this.current], {
                  duration:1,
                  to:0,
                  afterFinish : function()
                  {
                    this.items[this.current].setStyle({'display':'none'});
                    this.items[this.next].setStyle({'display':'block'}).setOpacity(0);

                    new Effect.Fade(this.items[this.next], {
                      duration:1,
                      from: 0, to:1,
                      afterFinish : function()
                      {
                        this.current = this.next;
                        this.hide.bind(this).delay(__newsSlider.delaytime);
                      }.bind(this)
                    });
                  }.bind(this)
                });
              }
            };
            
            el.slider.hide.bind(el.slider).delay(__newsSlider.delaytime);
          }
        }
      })
    }
  } 
}


var __toolTipImages = {
  items : null,
  
  _init : function()
  {
    if($$('#product_addtocart_form .products-grid li').length > 0)
    {
      this.items = $$('#product_addtocart_form .products-grid li');
      this.items.each(function(el,i){
        el.observe('mouseover',function(e){
          __toolTipImages._show(this,e);
        });
        el.observe('mouseout',function(e){
          __toolTipImages._hide(this,e);
        });
      })
    }
  },
  
  _show : function(item,e)
  {
    if($('product_addtocart_form').hasClassName('multiple-add') && !this.tip)
    {
      this._hide();
      if(item.getElementsByTagName('img')[0])
      {
        this.tip = new Element('div',{
          'id'    : 'imageToolTip'
        })
        .setStyle({
          'position' : 'absolute',
          'height'   : parseInt(item.getElementsByTagName('img')[0].style.height)+'px',
          'width'    : parseInt(item.getElementsByTagName('img')[0].style.width)+'px',
          'top'      : (e.pointer().y+20)+'px',
          'left'     : (e.pointer().x+20)+'px',
          'background' : '#fff',
          'border'   : '.5em solid #fff'
        });
        
        img =  item.getElementsByTagName('img')[0].cloneNode(true); 
        Element.insert(this.tip, img);
        $$('body')[0].insert(this.tip);        

        item.observe('mousemove',function(e){
          if($('imageToolTip'))
          {
            posx = e.pointer().x - Math.round($('imageToolTip').getWidth()/5) + 20;
            if((minus = $$('body')[0].getWidth()+$$('body')[0].scrollLeft - (posx + $('imageToolTip').getWidth() + 20)) < 0)
              posx+=minus;
            else if(posx<10)
              posx = 10;               

            $('imageToolTip').setStyle({
              top: (e.pointer().y - $('imageToolTip').getHeight() - 10)+'px',
              left: (posx-$('imageToolTip').getWidth()/2)+'px'
            });
          }
        });

      }
    }
  },
  
  _hide : function(item,e)
  {
    if($('imageToolTip'))
    {
      $('imageToolTip').remove();
      this.tip = null;
    }
  },
  
  _move : function(e)
  {
  }
}


var __pageStyles = {
  _init : function()
  {
    // place the footer at the absolute bottom of the page
//    this._placeFooter();
//    window.onresize = function() { this._placeFooter(); }.bind(this);
    
    // scrollize product-grids
    $$('.products-list.scrollme').each(function(el,i){
      this._scrollize(el);
    }.bind(this));
    
    // add hover effect in ie6
    if(Prototype.Browser.IE && typeof window.XMLHttpRequest == "undefined")
    {
      $$('button').each(function(el,i){
        el.observe('mouseover',function(){ this.addClassName('highlight'); });
        el.observe('mouseout',function(){ this.removeClassName('highlight'); });
      });
    }
    
    // add cellpadding/-spacing in ie
    if(Prototype.Browser.IE)
    {
      for(i=0; i<$$('table').length; i++)
      {
        $$('table')[i].writeAttribute('cellpadding', '0');
        $$('table')[i].writeAttribute('cellspacing', '0');
      }
    }
    // restyle all selectboxes
    
/*
    $$('select').each(function(el,index){
      if(tmp = new this._styleSelectboxes(el))
      {
        el.mySelect = tmp.init();
        delete tmp;
      }
    });
*/
  },
  
  _scrollize : function(grid)
  {
    space = 0;
    
    elements = grid.getElementsByClassName('item');
    if((number = elements.length)>0)
    {
      ml = elements[0].getStyle('marginLeft'); if(ml && ml.indexOf('em')>-1) ml = parseFloat(ml)*10; else ml = parseInt(ml); 
      mr = elements[0].getStyle('marginRight'); if(mr && mr.indexOf('em')>-1) mr = parseFloat(mr)*10; else mr = parseInt(mr);

      li_width = elements[0].getWidth()+ml+mr;
      maxitems = Math.floor(grid.getWidth()/li_width);
  
      if(number > maxitems)
      {
        mt = elements[0].getStyle('marginTop'); if(mt.indexOf('em')>-1) mt = parseFloat(mt)*10; else mt = parseInt(mt);
        mb = elements[0].getStyle('marginBottom'); if(mb.indexOf('em')>-1) mb = parseFloat(mb)*10; else mb = parseInt(mb);
        li_height = elements[0].getHeight()+mt+mb;
        
        grid_width = (li_width * number);
        
        for(i=maxitems; i<number; i=i+maxitems)
        {
          elements[i].setStyle({'marginLeft':(ml+space)+'px'});
          grid_width+=space;
        }
        
        grid.setStyle({
          height : li_height+'px',
          overflow : 'hidden'
        });
    
        wrapper = new Element('div',{
          'class' : 'products-grid-wrapper'
        })
        .setStyle({
          height   : grid.getHeight()+'px',
          width    : grid.getWidth()+'px',
          overflow : 'hidden'
        });
        grid.wrap(wrapper);

        grid.setStyle({width : grid_width+'px'});
        
        pages = new Element('div',{'class':'pages'});
        
        Element.insert(wrapper,{ 'before' : pages});

        pages.pager = {
          container : pages,
          pages : Math.ceil(number/maxitems),
          cur_page : 0,
          wrapper : wrapper,
          stage : grid,
          li_width : li_width,
          maxitems : maxitems,
          space : space,
          is_moving : false,
          init : function()
          {
            this.prevButton = new Element('a',{'class':'previous current','href':'javascript:void(0)'}).update('&lt;').observe('click', function(){ this.previous() }.bind(this));
            this.nextButton = new Element('a',{'class':'next','href':'javascript:void(0)'}).update('&gt;').observe('click', function(){ this.next() }.bind(this));

            Element.insert(this.container,{ 'top' : this.prevButton } );

            for(i=0; i<this.pages; i++)
              Element.insert(this.container,{ 'bottom' : new Element('a',{'class':'page'+(i==0 ? ' current' : ''),'rel':i,'href':'javascript:void(0)'}).update(i+1).observe('click', function(){ pager.show(this.rel); }.curry(pager=this)) } );

            Element.insert(this.container,{ 'bottom' : this.nextButton } );
          },
          previous : function()
          {
            if(this.cur_page-1>=0) this.show(this.cur_page-1);
          },
          next : function()
          {
            if(this.cur_page+1<=this.pages) this.show(this.cur_page+1);
          },
          show : function(num)
          {
            num = parseInt(num);
            if(num>=0 && num<=this.pages-1 && num!=this.cur_page && !this.is_moving)
            {
              this.is_moving = true;
              t = this.container.select('a').each(function(el,i){el.removeClassName('current');});
              this.container.getElementsByClassName('page')[num].addClassName('current');
              
              tox = num>0 ? (this.li_width * maxitems) * num + (this.space*(num)) : 0;

              new Effect.Morph(this.stage, { 
                style: 'left:'+(tox*-1)+'px', 
                duration: .5,
                transition: Effect.Transitions.sinoidal,

                afterFinish:function(){ this.is_moving = false; }.bind(this)  
              });

              if(num<=0) this.prevButton.addClassName('current');
              else if(num>=this.pages) this.nextButton.addClassName('current');
              this.cur_page = num;
            }
          }
        };
        
        pages.pager.init();
      }
    }
  },
  
  _decorateCheckoutButtons : function(msg)
  {
    if(typeof(msg)=='string')
    {
      $$('.no-checkout').each(function(el,i){
        el.disabled = false;
        el.onclick = false;
        $(el).observe("click", function(){
          alert(msg);
          return false;
        }.curry(msg))
      });
    }
  },

  _styleSelectboxes : function(el)
  {
    if(el.getElementsBySelector('option').length>0)
    {
      returnObj = {
        object : el,
        options : el.getElementsBySelector('option'),
        init : function()
        {
          list = new Element('div',{
            'class' : 'selectbox'
          })
          .observe('mouseover', function(){
            this.addClassName('selected');
          })
          .observe('mouseout', function(){
            this.removeClassName('selected');
          });
          
          for(i=0; i<this.options.length; i++)
          {
            option = this.options[i];
            
            if(!option.readAttribute('selected'))
            {
              li = new Element('p',{
                'class' : 'option prior-'+(i+1),
                'rel' : i
              })
              .observe('click', function(){
                if(!this.hasClassName('selected'))
                {
                  $A(arguments)[0].mySelect.options.each(function(el,i){ el.selected = false; });
                  $A(arguments)[0].mySelect.options[this.readAttribute('rel')].selected = true;
                  if($A(arguments)[0].onchange) $A(arguments)[0].onchange();
                }
              }.curry(this.object))
              .observe('mouseover', function(){
                this.addClassName('selected');
              })
              .observe('mouseout', function(){
                this.removeClassName('selected');
              })
              .update(option.text);
              
              Element.insert(list,li);
            }
            else
            {
              li = new Element('p',{
                'class' : 'header'
              })
              .update('<span>'+option.text+'</span>');
              
              Element.insert(list,{ 'top': li });
            }
          }
          Element.insert(this.object, { 'before': list} );
  //        this.object.setStyle('display','none');
  
  
  
          return this;
        }
      }
      return returnObj;
    }
    return null;
  }
}

__roundCorners = {
  elements_with_borders : new Array(
                            // {id:'.products-grid .item',c:['tl','tr','bl','br'],b:false},
                            {id:'#submenu',c:['tl','tr','t','bl','br','b'],b:false},
                            {id:'.page-title',c:['tl','tr','t','bl','br','b'],b:false},
                            {id:'.sidebar .block-account',c:['tl','tr','t','bl','br','b'],b:false}                            
                          ),
  _init : function(){
    if(Prototype.Browser.IE && typeof window.XMLHttpRequest != "undefined")
    {
      for(i=0; i<this.elements_with_borders.length; i++)
      {
        if($$(this.elements_with_borders[i].id).length>0)
        {
          for(j=0; j<$$(this.elements_with_borders[i].id).length; j++)
          {
            for(k=0; k<this.elements_with_borders[i].c.length; k++)
            { 
              Element.insert($$(this.elements_with_borders[i].id)[j],{ 'bottom' : new Element('span', {'class':'rc'+(this.elements_with_borders[i].b ? ' wb' : '')+' '+this.elements_with_borders[i].c[k]}) } );
            }
          }
        }
      }      
    }    
  }
}


var switch_optionImages = {
  changeOptionimage : function(attribute_id,option_id)
  {
    
    if(typeof($$('.product-large-image img')[0]) != 'undefined')
    { 
      if(typeof(switch_optionImages.originalImage)=='undefined')
        switch_optionImages.originalImage = $$('.product-large-image img')[0].src;
      
      if(typeof($$('.a'+attribute_id+'_o'+option_id)[0])!='undefined')
        $$('.product-large-image img')[0].src = $$('.a'+attribute_id+'_o'+option_id)[0].rev;
      else
        $$('.product-large-image img')[0].src = switch_optionImages.originalImage;
    }
    
    options = spConfig.getAttributeOptions(attribute_id);
    
    if(typeof(options)!='undefined')
    {
      for(i=0; i<spConfig.getAttributeOptions(attribute_id).length; i++)
      {
        if(spConfig.getAttributeOptions(attribute_id)[i].id == option_id)
        {
    
          if(typeof($$('.not-deliverable')[0])!='undefined')
          {
            if(parseInt(spConfig.getAttributeOptions(attribute_id)[i].qty)<=0)
              $$('.not-deliverable')[0].setStyle({display:'inline'});
            else
              $$('.not-deliverable')[0].setStyle({display:'none'});
          }
  
          break;
        }
      }
    }
  }
}
