Carousel=Class.create(Abstract,{initialize:function(scroller,slides,controls,options){this.scrolling=false;this.scroller=$(scroller);this.slides=slides;this.controls=controls;this.options=Object.extend({duration:1,auto:false,frequency:3,visibleSlides:1,controlClassName:'carousel-control',jumperClassName:'carousel-jumper',disabledClassName:'carousel-disabled',selectedClassName:'carousel-selected',circular:false,wheel:true,effect:'scroll',transition:'sinoidal'},options||{});if(this.options.effect=='fade'){this.options.circular=true;}
this.slides.each(function(slide,index){slide._index=index;});if(this.controls){this.controls.invoke('observe','click',this.click.bind(this));}
if(this.options.wheel){this.scroller.observe('mousewheel',this.wheel.bindAsEventListener(this)).observe('DOMMouseScroll',this.wheel.bindAsEventListener(this));;}
if(this.options.auto){this.start();}
if(this.options.initial){var initialIndex=this.slides.indexOf($(this.options.initial));if(initialIndex>(this.options.visibleSlides-1)&&this.options.visibleSlides>1){if(initialIndex>this.slides.length-(this.options.visibleSlides+1)){initialIndex=this.slides.length-this.options.visibleSlides;}}}else{var initialIndex=0;}
this.moveTo(this.slides[initialIndex]);},click:function(event){this.stop();var element=event.findElement('a');if(!element.hasClassName(this.options.disabledClassName)){if(element.hasClassName(this.options.controlClassName)){eval("this."+element.rel+"()");}else if(element.hasClassName(this.options.jumperClassName)){this.moveTo(element.rel);if(this.options.selectedClassName){this.controls.invoke('removeClassName',this.options.selectedClassName);element.addClassName(this.options.selectedClassName);}}}
this.deactivateControls();event.stop();},moveTo:function(element){if(this.options.beforeMove&&(typeof this.options.beforeMove=='function')){this.options.beforeMove();}
this.previous=this.current?this.current:this.slides[0];this.current=$(element);var scrollerOffset=this.scroller.cumulativeOffset();var elementOffset=this.current.cumulativeOffset();if(this.scrolling){this.scrolling.cancel();}
switch(this.options.effect){case'fade':this.scrolling=new Effect.Opacity(this.scroller,{from:1.0,to:0,duration:this.options.duration,afterFinish:(function(){this.scroller.scrollLeft=elementOffset[0]-scrollerOffset[0];this.scroller.scrollTop=elementOffset[1]-scrollerOffset[1];new Effect.Opacity(this.scroller,{from:0,to:1.0,duration:this.options.duration,afterFinish:(function(){if(this.controls){this.activateControls();}
if(this.options.afterMove&&(typeof this.options.afterMove=='function')){this.options.afterMove();}}).bind(this)});}).bind(this)});break;case'scroll':default:var transition;switch(this.options.transition){case'spring':transition=Effect.Transitions.spring;break;case'sinoidal':default:transition=Effect.Transitions.sinoidal;break;}
this.scrolling=new Effect.SmoothScroll(this.scroller,{duration:this.options.duration,x:(elementOffset[0]-scrollerOffset[0]),y:(elementOffset[1]-scrollerOffset[1]),transition:transition,afterFinish:(function(){if(this.controls){this.activateControls();}
if(this.options.afterMove&&(typeof this.options.afterMove=='function')){this.options.afterMove(this);}
this.scrolling=false;}).bind(this)});break;}
return false;},prev:function(){if(this.current){var currentIndex=this.current._index;var prevIndex=(currentIndex==0)?(this.options.circular?this.slides.length-1:0):currentIndex-1;}else{var prevIndex=(this.options.circular?this.slides.length-1:0);}
if(prevIndex==(this.slides.length-1)&&this.options.circular&&this.options.effect!='fade'){this.scroller.scrollLeft=(this.slides.length-1)*this.slides.first().getWidth();this.scroller.scrollTop=(this.slides.length-1)*this.slides.first().getHeight();prevIndex=this.slides.length-2;}
this.moveTo(this.slides[prevIndex]);},next:function(){if(this.current){var currentIndex=this.current._index;var nextIndex=(this.slides.length-1==currentIndex)?(this.options.circular?0:currentIndex):currentIndex+1;}else{var nextIndex=1;}
if(nextIndex==0&&this.options.circular&&this.options.effect!='fade'){this.scroller.scrollLeft=0;this.scroller.scrollTop=0;nextIndex=1;}
if(nextIndex>this.slides.length-(this.options.visibleSlides+1)){nextIndex=this.slides.length-this.options.visibleSlides;}
this.moveTo(this.slides[nextIndex]);},first:function(){this.moveTo(this.slides[0]);},last:function(){this.moveTo(this.slides[this.slides.length-1]);},toggle:function(){if(this.previous){this.moveTo(this.slides[this.previous._index]);}else{return false;}},stop:function(){if(this.timer){clearTimeout(this.timer);}},start:function(){this.periodicallyUpdate();},pause:function(){this.stop();this.activateControls();},resume:function(event){if(event){var related=event.relatedTarget||event.toElement;if(!related||(!this.slides.include(related)&&!this.slides.any(function(slide){return related.descendantOf(slide);}))){this.start();}}else{this.start();}},periodicallyUpdate:function(){if(this.timer!=null){clearTimeout(this.timer);this.next();}
this.timer=setTimeout(this.periodicallyUpdate.bind(this),this.options.frequency*1000);},wheel:function(event){event.cancelBubble=true;event.stop();var delta=0;if(!event){event=window.event;}
if(event.wheelDelta){delta=event.wheelDelta/120;}else if(event.detail){delta=-event.detail/3;}
if(!this.scrolling){this.deactivateControls();if(delta>0){this.prev();}else{this.next();}}
return Math.round(delta);},deactivateControls:function(){this.controls.invoke('addClassName',this.options.disabledClassName);},activateControls:function(){this.controls.invoke('removeClassName',this.options.disabledClassName);}});Effect.SmoothScroll=Class.create();Object.extend(Object.extend(Effect.SmoothScroll.prototype,Effect.Base.prototype),{initialize:function(element){this.element=$(element);var options=Object.extend({x:0,y:0,mode:'absolute'},arguments[1]||{});this.start(options);},setup:function(){if(this.options.continuous&&!this.element._ext){this.element.cleanWhitespace();this.element._ext=true;this.element.appendChild(this.element.firstChild);}
this.originalLeft=this.element.scrollLeft;this.originalTop=this.element.scrollTop;if(this.options.mode=='absolute'){this.options.x-=this.originalLeft;this.options.y-=this.originalTop;}},update:function(position){this.element.scrollLeft=this.options.x*position+this.originalLeft;this.element.scrollTop=this.options.y*position+this.originalTop;}});;SimpleTooltip=Class.create({handle:null,tooltip:null,initialize:function(handle,tooltip){this.handle=handle;this.tooltip=tooltip;this.handle.observe('mouseenter',this.show.bindAsEventListener(this));this.getLayer().observe('mouseleave',this.hide.bindAsEventListener(this));},show:function(event){this.getLayer().clonePosition(this.handle,{setWidth:false,setHeight:false,offsetLeft:-192,offsetTop:-6}).update(this.tooltip.innerHTML).show();},hide:function(event){this.getLayer().hide();},getLayer:function(){if(!SimpleTooltip.layer){SimpleTooltip.layer=new Element('div',{'class':'tooltip'}).setStyle({position:'absolute'}).hide();document.body.appendChild(SimpleTooltip.layer);}
return SimpleTooltip.layer;}});;var Slide=Class.create({slide:null,handle:null,initialize:function(handle,slide,initial,eventstart,eventstop){this.slide=$(slide);this.handle=$(handle);if(!(this.slide&&this.handle)){return;}
this.handle.observe(eventstart,this.toggle.bindAsEventListener(this,true));this.handle.observe(eventstop,this.toggle.bindAsEventListener(this,false));this.slide[initial?'show':'hide']();},toggle:function(ev,canOpen){if(!this.slide.visible()){if(canOpen){Effect.SlideDown(this.slide,{scaleContent:false,duration:0.5});this.handle.addClassName('open');}}else{Effect.SlideUp(this.slide,{scaleContent:false,duration:0.5});this.handle.removeClassName('open');}
if(canOpen){ev.stop();}}});;var BundleOption=Class.create({initialize:function(id,priceElement,combinations){this.id=id;this.priceElement=priceElement;this.combinations=combinations;this.selects=[];$$('select.bundleoption_'+this.id).each(function(select,index){var attribute=this.getAttributeName(select)
this.selects[index]=select;select.observe('change',this.selectChanged.bindAsEventListener(this,attribute,index));select.observe('jq:change',this.selectChanged.bindAsEventListener(this,attribute,index));},this);window.setTimeout(this.selectChanged.bind(this),10);if($('bundle_option_qty_'+this.id)){$('bundle_option_qty_'+this.id).observe('click',this.quantityChanged.bindAsEventListener(this));this.qty=$('bundle_option_qty_'+this.id).checked?1:0;}else{this.qty=1;}
this.updatePrices(this.combinations);this.updatePriceHtml();$(document).fire('bundle:priceChanged',{option:this});},quantityChanged:function(event){this.qty=$('bundle_option_qty_'+this.id).checked?1:0;$(document).fire('bundle:priceChanged',{option:this});},selectChanged:function(event,attribute,index){this.minPrice=99999999;this.minRegularPrice=99999999;this.maxPrice=0;this.maxRegularPrice=0;this.updateCombinations(this.combinations);},updatePriceHtml:function(){if(!(isNaN(this.minPrice)&&isNaN(this.maxPrice))){$(this.priceElement).update(this.getPriceHtml());}},getPriceHtml:function(){var minRegularPriceHtml='';var minPriceClass='';if(this.minPrice<this.minRegularPrice){minRegularPriceHtml='<span class="old-price price">'+this.formatPrice(this.minRegularPrice)+'</span>';minPriceClass='special-price ';}
var maxRegularPriceHtml='';var maxPriceClass='';if(this.maxPrice<this.maxRegularPrice){maxRegularPriceHtml='<span class="old-price price">'+this.formatPrice(this.maxRegularPrice)+'</span>';maxPriceClass='special-price ';}
if(this.minPrice==this.maxPrice){return minRegularPriceHtml+'<span class="'+minPriceClass+'price">'+this.formatPrice(this.minPrice)+' *</span>';}else{return'<p class="price-from">\
                        <span class="price-label">Von </span>'+minRegularPriceHtml+'<span class="'+minPriceClass+'price">'+this.formatPrice(this.minPrice)+' *</span>\
                    </p>\
                    <p class="price-to">\
                        <span class="price-label">bis </span>'+maxRegularPriceHtml+'<span class="'+maxPriceClass+'price">'+this.formatPrice(this.maxPrice)+' *</span>\
                    </p>';}
return priceHtml;},updateCombinations:function(combinations,level){level=level?level:0;if(level<this.selects.size()){var currentValue=this.selects[level].getValue();this.markAvailable(this.selects[level],$H(combinations).keys());if(combinations[currentValue]){this.updateCombinations(combinations[currentValue],level+1);}else if(currentValue==0){for(i in combinations){this.updateCombinations(combinations[i],level+1);}}else{this.selects[level].selectedIndex=0;}}else{this.updatePrices(combinations);for(var i=0;i<this.selects.size();i++){if(this.selects[i].getValue()==0){this.setSelectedProduct(null);return;}
this.setSelectedProduct(combinations);}}},updatePrices:function(combinations){if(combinations.price){this.minPrice=Math.min(this.minPrice,combinations.price);this.maxPrice=Math.max(this.maxPrice,combinations.price);}
if(combinations.regularPrice){this.maxRegularPrice=Math.max(this.maxRegularPrice,combinations.regularPrice);this.minRegularPrice=Math.min(this.minRegularPrice,combinations.regularPrice);}},markAvailable:function(select,optionValues){select.select('option').each(function(option){if(optionValues.indexOf(option.value)==-1){option.disabled=true;option.addClassName('disabled');}else{option.disabled=false;option.removeClassName('disabled');}});},setSelectedProduct:function(product){if(product){$('bundle_option_'+this.id).setAttribute('value',product.selection_id);}else{$('bundle_option_'+this.id).setAttribute('value','');}
this.updatePriceHtml();$(document).fire('bundle:priceChanged',{option:this});},formatPrice:function(price){return(1*price).toFixed(2).replace('.',',')+' &euro;';},getAttributeName:function(select){return this.inputNameKeys(select.getAttribute('name')).last();},inputNameKeys:function(name){return name.split(/[\[\]]+/).findAll(Prototype.K);}});;var BundlePrice=Class.create({initialize:function(){this.priceElement=$('look-price');this.savingElement=$('look-saving');this.savingElementWrapper=$('lookSavingWrapper');if(!(this.priceElement&&this.savingElement)){return;}
this.bag={};this.bundlePrice=this.parsePrice(this.priceElement.innerHTML);$(document).observe('bundle:priceChanged',this.priceChanged.bindAsEventListener(this));},priceChanged:function(ev){if(option=ev.memo.option){this.bag[option.id]={qty:option.qty,max:option.maxPrice,min:option.minPrice};}
this.updatePriceHtml();},parsePrice:function(string){return 1.0*string.replace(/[^0-9.,]+/g,'').replace(',','.').replace(/\.$/,'.00');},formatPrice:function(price){return price.toFixed(2).replace('.',',')+' &euro; *';},updatePriceHtml:function(){min=0;max=0;complete=true;for(i in this.bag){var bagItem=this.bag[i];min+=bagItem.qty*bagItem.min;max+=bagItem.qty*bagItem.max;if(!bagItem.qty){complete=false;}}
if(complete){this.priceElement.update(this.formatPrice(this.bundlePrice));$(this.savingElementWrapper).show();this.savingElement.update(this.formatPrice(max-this.bundlePrice));Cufon.refresh('.bundle span.saving .inner span');}else{if(min==max){this.priceElement.update(this.formatPrice(min));}else{this.priceElement.update(this.formatPrice(min)+' - '+this.formatPrice(max));}
$(this.savingElementWrapper).hide();}}});;document.observe("dom:loaded",function(){var colorOption=$$('div.option_color').first();if(colorOption&&$('colorChooserContainer')){$('colorChooserContainer').insert(colorOption.remove());}
updateCarouselControls=function(carousel){carousel.controls[0][(carousel.current._index==0?'add':'remove')+'ClassName']('carousel-end');carousel.controls[1][(carousel.current._index==carousel.slides.length-1?'add':'remove')+'ClassName']('carousel-end');}
$$('.carousel').each(function(el){el=$(el);var aCarousel=new Carousel(el.select('.carousel-wrapper').first(),el.select('.slide'),el.select('a.carousel-control'),{afterMove:updateCarouselControls,initial:el.select('.slide')[0]});});$$('.looksPlus').each(function(el){new SimpleTooltip(el.select('.looksPlusIcon').first(),el.select('.looksTitle').first());});$$('ol.decorate, ul.decorate').each(function(el){decorateGeneric(el.select('li'));});new Slide($$('div.top-cart').first(),$('cart-slide'),$$('.top-cart.updated').any(),'mouseenter','mouseleave');$$('div.table-slide').each(function(el){var handle=el.previous('div.actions').select('a.actionbutton.more').first();new Slide(handle,el,false,'click','click');});new BundlePrice();});;Multiselect=Class.create({select:null,handle:null,shown:false,timeout:false,options:{handle:'li.attribute-filter-handle',select:'div.attribute-filter-wrapper'},initialize:function(box){this.select=box.select(this.options.select).first();this.handle=box.select(this.options.handle).first();this.handle.observe('mouseenter',this.show.bindAsEventListener(this));this.handle.observe('mouseleave',this.hide.bindAsEventListener(this));this.select.hide();this.select.select('li a.amshopby-attr').invoke('observe','click',this.toggleCheckbox.bindAsEventListener(this));this.shown=false;},hide:function(){Effect.SlideUp(this.select,{scaleContent:false,duration:0.3});this.shown=false;},show:function(){Effect.SlideDown(this.select,{scaleContent:false,duration:0.3});this.shown=true;},toggleCheckbox:function(ev){ev.findElement('a').toggleClassName('amshopby-attr-selected');}});
