(function(){var alreadyExecuted=false;Fx.Scroll=new Class({Extends:Fx,options:{offset:{x:0,y:0},wheelStops:true},initialize:function(element,options){if(!element)var element='carousel';this.element=this.subject=document.id(element);this.parent(options);var cancel=this.cancel.bind(this,false);if($type(this.element)!='element'){this.element=document.id(this.element.getDocument().body)}var stopper=this.element;if(this.options.wheelStops){this.addEvent('start',function(){stopper.addEvent('mousewheel',cancel)},true);this.addEvent('complete',function(){stopper.removeEvent('mousewheel',cancel)},true)}},set:function(){var now=Array.flatten(arguments);this.element.scrollTo(now[0],now[1])},compute:function(from,to,delta){return[0,1].map(function(i){return Fx.compute(from[i],to[i],delta)})},start:function(x,y){if(!this.check(x,y))return this;var offsetSize=this.element.getSize(),scrollSize=this.element.getScrollSize(),scroll=this.element.getScroll(),values={x:x,y:y};for(var z in values){var max=scrollSize[z]-offsetSize[z];if($chk(values[z]))values[z]=($type(values[z])=='number')?values[z].limit(0,max):max;else values[z]=scroll[z];values[z]+=this.options.offset[z]}return this.parent([scroll.x,scroll.y],[values.x,values.y])},toTop:function(){return this.start(false,0)},toLeft:function(){return this.start(0,false)},toRight:function(){return this.start('right',false)},toBottom:function(){return this.start(false,'bottom')},toElement:function(el){if(!el)return;var position=document.id(el).getPosition(this.element);return this.start(position.x,position.y)},scrollIntoView:function(el,axes,offset){axes=axes?$splat(axes):['x','y'];var to={};el=document.id(el);var pos=el.getPosition(this.element),size=el.getSize(),scroll=this.element.getScroll(),containerSize=this.element.getSize(),edge={x:pos.x+size.x,y:pos.y+size.y};['x','y'].each(function(axis){if(axes.contains(axis)){if(edge[axis]>scroll[axis]+containerSize[axis])to[axis]=edge[axis]-containerSize[axis];if(pos[axis]<scroll[axis])to[axis]=pos[axis]}if(to[axis]==null)to[axis]=scroll[axis];if(offset&&offset[axis])to[axis]=to[axis]+offset[axis]},this);if(to.x!=scroll.x||to.y!=scroll.y)this.start(to.x,to.y);return this}});Fx.Scroll.Carousel=new Class({Extends:Fx.Scroll,options:{mode:'horizontal',childSelector:false,loopOnScrollEnd:true},initialize:function(element,options){this.parent(element,options);this.cacheElements();if(!this.currentIndex)this.currentIndex=0;if(!this.count)this.count=0},cacheElements:function(){var cs=this.options.childSelector;if(cs){els=this.element.getElements(cs)}else if(this.options.mode=='horizontal'){els=this.element.getElements('div.panel')}else{els=this.element.getChildren()}this.elements=els;return this},toNext:function(){if(this.checkLink())return this;this.currentIndex=this.getNextIndex();this.toElement(this.elements[this.currentIndex]);this.fireEvent('next');$$('.filmstrip a img').removeClass('selectedNow');$$('.filmstrip a.'+this.currentIndex+' img').addClass('selectedNow');if(this.currentIndex==0){bottomSlide.myFx.toElement(bottomSlide.images[0]);bottomSlide.options.currentElement=-1;this.count=1}else{if(this.count>1){bottomSlide.slide(1)}else{this.count++}}return this},ToSpecific:function(slide){if(this.checkLink())return this;this.toElement(this.elements[slide]);this.currentIndex=slide;$$('.filmstrip a img').removeClass('selectedNow');$$('.filmstrip a.'+slide+' img').addClass('selectedNow');this.fireEvent('next');return this},toPrevious:function(){if(this.checkLink())return this;this.currentIndex=this.getPreviousIndex();this.toElement(this.elements[this.currentIndex]);this.fireEvent('previous');return this},getNextIndex:function(){this.currentIndex++;if(this.currentIndex==this.elements.length||this.checkScroll()){this.fireEvent('loop');this.fireEvent('nextLoop');return 0}else{return this.currentIndex}},getPreviousIndex:function(){this.currentIndex--;var check=this.checkScroll();if(this.currentIndex<0||check){this.fireEvent('loop');this.fireEvent('previousLoop');return(check)?this.getOffsetIndex():this.elements.length-1}else{return this.currentIndex}},getOffsetIndex:function(){var visible=(this.options.mode=='horizontal')?this.element.getStyle('width').toInt()/this.elements[0].getStyle('width').toInt():this.element.getStyle('height').toInt()/this.elements[0].getStyle('height').toInt();return this.currentIndex+1-visible},checkLink:function(){return(this.timer&&this.options.link=='ignore')},checkScroll:function(){if(!this.options.loopOnScrollEnd)return false;if(this.options.mode=='horizontal'){var scroll=this.element.getScroll().x,total=this.element.getScrollSize().x-this.element.getSize().x}else{var scroll=this.element.getScroll().y,total=this.element.getScrollSize().y-this.element.getSize().y}return(scroll==total)},getCurrent:function(){return this.elements[this.currentIndex]}});var PeriodicalExecuter=new Class({initialize:function(callback,frequency){this.callback=callback;this.frequency=frequency;this.currentlyExecuting=false;this.registerCallback()},registerCallback:function(){this.stop();this.timer=setInterval(this.onTimerEvent.bind(this),this.frequency*1000);return this},execute:function(){this.callback(this);return this},stop:function(){if(!this.timer)return this;clearInterval(this.timer);this.timer=null;return this},onTimerEvent:function(){if(!this.currentlyExecuting){try{this.currentlyExecuting=true;this.execute()}finally{this.currentlyExecuting=false}}return this}});var SlideItMoo=new Class({initialize:function(options){this.options=$extend({itemsVisible:5,showControls:1,autoSlide:0,transition:Fx.Transitions.linear,currentElement:0,thumbsContainer:'thumbs',elementScrolled:'thumb_container',overallContainer:'gallery_container'},options||{});this.images=$(this.options.thumbsContainer).getElements('a');this.image_size=this.images[0].getSize();this.setContainersSize();this.myFx=new Fx.Scroll(this.options.elementScrolled,{transition:this.options.transition});if(this.images.length>=this.options.itemsVisible){this.fwd=this.addControlers('addfwd');this.bkwd=this.addControlers('addbkwd');this.forward();this.backward();if(!this.options.autoSlide){$(this.options.thumbsContainer).addEvent('mousewheel',function(ev){new Event(ev).stop();ev.wheel<0?this.fwd.fireEvent('click'):this.bkwd.fireEvent('click')}.bind(this))}else{this.startIt=function(){this.fwd.fireEvent('click')}.bind(this);this.autoSlide=this.startIt.periodical(this.options.autoSlide,this);this.images.addEvents({'mouseover':function(){$clear(this.autoSlide)}.bind(this),'mouseout':function(){this.autoSlide=this.startIt.periodical(this.options.autoSlide,this)}.bind(this)})}}if(this.options.currentElement!==0){this.options.currentElement-=1;this.slide(1)}},setContainersSize:function(){$(this.options.overallContainer).set({styles:{'width':this.options.itemsVisible*this.image_size.x+50*this.options.showControls+(this.options.itemsVisible-1)*3}});if(Browser.Engine.trident){var widthAdjust=14}else{var widthAdjust=10}$(this.options.elementScrolled).set({styles:{'width':(this.options.itemsVisible*this.image_size.x+(this.options.itemsVisible-1)*3)-widthAdjust}})},forward:function(){this.fwd.removeEvents('click');this.fwd.addEvent('click',function(){this.slide(1)}.bind(this))},backward:function(){this.bkwd.removeEvents('click');this.bkwd.addEvent('click',function(){this.slide(-1)}.bind(this))},addControlers:function(cssClass){var element;if($$('.'+cssClass).length<1){element=new Element('div',{'class':cssClass,styles:{'display':this.options.showControls?'':'none'}}).injectInside($(this.options.overallContainer))}else{element=$$($$('.'+cssClass))[0]}return element},slide:function(step){if(this.options.autoSlide&&this.options.currentElement>=this.images.length-this.options.itemsVisible){this.options.currentElement=-1}this.myFx.cancel();this.options.currentElement+=step;this.myFx.toElement(this.images[this.options.currentElement])}});var myCarousel,bottomSlide,noMoreSlides=false,iniButtons=function(){bottomSlide=new SlideItMoo({itemsVisible:10,currentElement:0,thumbsContainer:'thumbs',elementScrolled:'thumb_container',overallContainer:'gallery_container'});$$('.filmstrip a img').each(function(image){image.removeEvents('click');image.addEvent('click',function(e){e.preventDefault();slide=e.target.get('id');if(slide!=null){myCarousel.ToSpecific(slide)}})})};var getGalleryImage=function(){var lastPanel;if(noMoreSlides==false){$$('.inner div.panel').each(function(el){lastPanel=el.getProperty('class').split(' ')});var getPanel=new Request({url:'/ajax/get_carousel',method:'get',data:{lastPanel:lastPanel[1],type:'panel'},onComplete:function(r){try{r=JSON.decode(r);if(r.panel!='false'){$$('.inner').set('html',$$('.inner').get('html')+r.panel);$$('.filmstrip').set('html',$$('.filmstrip').get('html')+r.icon);$$('.inner')[0].setStyle('width',$$('.inner')[0].getStyle('width').toInt()+r.widthCount.toInt()+'px')}else{noMoreSlides=true}}catch(err){}myCarousel.initialize();iniButtons()}}).send()}};var prepCarouselle=function(){$('gallery_container').removeClass('noshow');$('carousel').removeClass('noshow');myCarousel=new Fx.Scroll.Carousel('carousel',{mode:'horizontal',onStart:function(){myCarousel.getCurrent().tween('color','#000')},onComplete:function(){myCarousel.getCurrent().tween('color','#fff')}});var pe=new PeriodicalExecuter(function(){myCarousel.toNext()},15).stop();pe.registerCallback();iniButtons();getGalleryImage()};var resizeNews=function(){$('body_wrap').setStyle('max-width','1280px');var mainWrap=$$('#content_right')[0].getWidth(),mainColSize=Math.floor((mainWrap-996)+6),newsSize=Math.floor(mainWrap-997-106);if(mainColSize<=150){$$('#homeRight')[0].addClass('noshow');$('body_wrap').setStyle('max-width','990px')}else{$$('#homeRight')[0].removeClass('noshow');getRandomItems()}$$('#homeRight')[0].setStyle('width',mainColSize)};var checkImages=function(){$$(".middleContent  img").each(function(eachImage){var img=new Image();img.src=eachImage.src;if(!img.complete){eachImage.setStyle("display","none")}})};var checkLeftColumn=function(){$$('#homeRight')[0].setStyle('min-height',$$('#homeCenter')[0].getHeight());$$('#content_left')[0].setStyle('min-height',$$('#homeRight')[0].getHeight()+13)};var getRandomItems=function(){$$('.relatedSectionHeading')[0].setStyle('width',$$('#content_wrap')[0].getWidth()-($$('#homeCenter')[0].getWidth()+$$('#content_left')[0].getWidth())-30);if(alreadyExecuted==true){return}alreadyExecuted=true;var descSectionHeight=$$('.middleContent ')[0].getHeight(),itemBoxHeight=150,totalItems=Math.floor(descSectionHeight/itemBoxHeight)+2;new Request({url:'/ajax/getRandomItems',method:'get',data:{action:'getSimilarItems',PUB_ID:'112936',items:totalItems},onComplete:function(r){$$('#homeRight').loaded();$$('.randomProducts')[0].set('html',r);if(Browser.Engine.trident){fixIEdisplay_off.delay(1000);fixIEdisplay_on.delay(1000);checkLeftColumn.delay(2000);checkLeftColumn.delay(3000);checkLeftColumn.delay(6000)}checkLeftColumn.delay(1000);checkLeftColumn.delay(6000);alreadyExecuted=false}}).send()};var fixIEdisplay_off=function(){$$('#homeRight')[0].setStyle('display','none')};var fixIEdisplay_on=function(){$$('#homeRight')[0].setStyle('display','inline-block')};var rerun_getRandomItems=function(){$$('#homeRight').loading();getRandomItems()};window.addEvent('domready',function(){prepCarouselle();checkLeftColumn();$$('#content_left')[0].setStyle('min-height',$$('#homeCenter')[0].getHeight()+16)});window.addEvent("load",function(){checkImages();$$('#homeRight').loading();if($$('#content_right')[0]){resizeNews();window.addEvent('resize',function(){resizeNews()})}var periodicalID=rerun_getRandomItems.periodical(35000);document.addEvent('keyup',function(event){if(Event(event).key!=='n')return;rerun_getRandomItems()})})})();
