var ProductsSlider=function(){var currentIdx=0
var cellCnt=$('popular-cats-container').down('popular-cats').childElements().size()
var cellWidth=$('popular-cats-container').childElements()[0].getDimensions().width
var moveLock=false
var clearMoveLock=function(){moveLock=false}
var processPrevNextState=function(){if(currentIdx==0){$('arrow-left1').addClassName('inactive')}else{$('arrow-left1').removeClassName('inactive')}
if(currentIdx+3>=cellCnt){$('arrow-right1').addClassName('inactive')}else{$('arrow-right1').removeClassName('inactive')}}
processPrevNextState()
$('arrow-right1').observe('click',function(e){if(moveLock)return
if(currentIdx+3<cellCnt-1){moveLock=true
currentIdx+=3
new Effect.Move($($container).down(div),{x:-1*cellWidth,duration:.5,afterFinish:clearMoveLock})}
processPrevNextState()})
$('arrow-left1').observe('click',function(e){if(moveLock)return
if(currentIdx-3>=0){moveLock=true
currentIdx-=3
new Effect.Move($($container).down(div),{x:cellWidth,duration:.5,afterFinish:clearMoveLock})}
processPrevNextState()})};var Advancednewsletter=Class.create();Advancednewsletter.prototype={url:'',initialize:function(ctrl,url){this.url=url;ctrl.observe('click',function(event){this.display();Event.stop(event);}.bind(this));$('an-content').observe('click',(function(event){if(event.element().id=='advancednewsletter-cancel')this.deactivate();}).bind(this));},display:function(){if($('advancednewsletter-subscribe-ajax')==undefined)
{this.sendResponse()}
else
{$('advancednewsletter-overlay').show();$('an-content').show();}},deactivate:function(){$('advancednewsletter-overlay').hide();$('an-content').hide();},sendResponse:function(){this.displayWait();new Ajax.Request(this.url,{onSuccess:function(resp){$('subscribe-please-wait').hide();$('an-content').update(resp.responseText.stripScripts());this.alignBlockAn($('an-content'),400,200);advancednewsletterForm=new VarienForm('advancednewsletter-form');}.bind(this)});},displayWait:function(){$('advancednewsletter-overlay').show();this.alignBlockAn($('subscribe-please-wait'),120,20);},alignBlockAn:function(block,width,height){block.style.display='block';block.style.width=width+'px';block.style.height=height+'px';block.style.left=(document.viewport.getWidth()/2-width/2)+'px';block.style.top=(document.viewport.getHeight()/2-height/2)+'px';}};function nerdyDomLoaded(func)
{if((/msie [1-6]\./i).test(navigator.userAgent)){Event.observe(window,'load',func)}else{document.observe("dom:loaded",func)}}
var NerdyProductClick=Class.create({initialize:function(clickUrl){this.clickUrl=clickUrl},processClick:function(pId,pnHash){new Ajax.Request(this.clickUrl,{method:'post',parameters:{product_id:pId,prev_next_hash:pnHash}})}});var NerdyModal=Class.create({initialize:function(){this.curModal=this.skipNextClick=this.stickyModal=false
Event.observe(document.body,'click',this.onSomeWhereClick.bindAsEventListener(this))
Event.observe(window,'keyup',this.processEsc.bindAsEventListener(this))
this.hideCurrentModalBind=this.hideCurrentModal.bind(this)},processEsc:function(e){if(e.keyCode==Event.KEY_ESC){this.hideCurrentModal()}},onSomeWhereClick:function(e){if(!this.stickyModal&&!this.skipNextClick&&this.curModal&&this.curModal.down()&&!this.within(this.curModal.down(),Event.pointerX(e),Event.pointerY(e))){this.curModal.hide()
this.curModal=false}else{this.skipNextClick=false}},within:function(el,x,y){var co=el.cumulativeOffset()
var dim=el.getDimensions()
if(x<co[0]||y<co[1])return false
if(x>co[0]+dim.width||y>co[1]+dim.height)return false
return true},switchCurrentModal:function(newModal,skipNextClick){if(this.curModal)this.curModal.hide()
this.curModal=newModal
this.skipNextClick=skipNextClick},showModal:function(newModal,skipNextClick){if(this.curModal)this.curModal.hide()
this.curModal=newModal
this.skipNextClick=skipNextClick
var modalDim={width:(document.body.scrollWidth-1)+'px',height:(document.body.scrollHeight-1)+'px'}
var modalStyle=Object.extend({top:'0px',left:'0px',position:'absolute',opacity:0},modalDim)
document.body.appendChild(this.curModal)
this.curModal.setStyle(modalStyle)
this.curModal.show()
this.curModal.down().absolutize()
if((/msie 7\./i).test(navigator.userAgent)){this.curModal.select('.modal-main')[0].setStyle({height:this.curModal.select('.modal-main .content')[0].getHeight()+'px'})}
var modalHeight=Math.max(this.curModal.select('.modal')[0].getHeight(),this.curModal.select('.modal-main')[0].getHeight(),this.curModal.select('.modal-main .content')[0].getHeight()).round()
this.curModal.down().setStyle({zIndex:10000,left:(document.viewport.getScrollOffsets().left+(document.viewport.getWidth()-this.curModal.select('.modal-main')[0].getWidth())/2).round()+'px',top:(document.viewport.getScrollOffsets().top+(document.viewport.getHeight()-modalHeight)/2).round()+'px'})
this.curModal.appear({duration:1.0})},hideCurrentModal:function(){if(this.curModal)this.curModal.fade({duration:1.0})
this.stickyModal=false}})
var NerdyModalSingleton
function nerdyGetModal(){if(!NerdyModalSingleton){NerdyModalSingleton=new NerdyModal()}
return NerdyModalSingleton}
function nerdyShowThisSizeChartModal(scmId){if($(scmId)){nerdyGetModal().showModal($(scmId),true)}}
function nerdyShowSizeChartModal(){if($('size-chart-modal')){nerdyGetModal().showModal($('size-chart-modal'),true)}};var NerdyCountdown=Class.create({initialize:function(options){this.dayValue=24*60*60*1000
this.hourValue=60*60*1000
this.minuteValue=60*1000
this.secondValue=1000
if(!options.containers)return;this.dayLabel=options.dayLabel||'Days'
this.hourLabel=options.hourLabel||'Hrs'
this.minuteLabel=options.minuteLabel||'Min'
this.secondLabel=options.secondLabel||'sec'
var container,targetTime,tDate;this.containers=[];for(i=0;i<options.containers.length;i++){if((container=$(options.containers[i].id))&&(targetTime=Date.parse(options.containers[i].targetDate))){tDate=new Date()
targetTime=targetTime-tDate.getTimezoneOffset()*60*1000
tDate.setTime(targetTime)
this.containers.push({containerId:options.containers[i].id,expiredId:options.containers[i].expiredId,targetDate:tDate})}}
for(i=0;i<this.containers.length;i++){this.containers[i].loopExec=new PeriodicalExecuter(this.updateCountdown.bind(this,this.containers[i]),1)}},getTimeLeft:function(cId){for(i=0;i<this.containers.length;i++){if(this.containers[i].containerId==cId){return this.containers[i].targetDate.getTime()-(new Date()).getTime()}}
return 0},updateCountdown:function(container){var timeLeft=container.targetDate.getTime()-(new Date()).getTime()
var hourLeft,minuteLeft,secondLeft
if(timeLeft<=0){dayLeft=hourLeft=minuteLeft=secondLeft=new String(0)}else{dayLeft=Math.floor(timeLeft/this.dayValue)
if(dayLeft>=4)timeLeft-=dayLeft*this.dayValue
else dayLeft=0
hourLeft=Math.floor(timeLeft/this.hourValue)
timeLeft-=hourLeft*this.hourValue
minuteLeft=Math.floor(timeLeft/this.minuteValue)
timeLeft-=minuteLeft*this.minuteValue
secondLeft=Math.floor(timeLeft/this.secondValue)}
var dayContainer,dayLabelContainer
var hourContainer=$$('#'+container.containerId+' .hour')
var minuteContainer=$$('#'+container.containerId+' .minute')
var secondContainer=$$('#'+container.containerId+' .second')
var hourLabelContainer=$$('#'+container.containerId+' .hour-label')
var minuteLabelContainer=$$('#'+container.containerId+' .minute-label')
var secondLabelContainer=$$('#'+container.containerId+' .second-label')
if(dayLeft>0){dayContainer=hourContainer
hourContainer=minuteContainer
minuteContainer=secondContainer
secondContainer=null
dayLabelContainer=hourLabelContainer
hourLabelContainer=minuteLabelContainer
minuteLabelContainer=secondLabelContainer
secondLabelContainer=null}
if(dayContainer&&dayContainer[0]){dayContainer[0].update(dayLeft)}
if(hourContainer&&hourContainer[0]){hourContainer[0].update(hourLeft)}
if(minuteContainer&&minuteContainer[0]){minuteContainer[0].update(minuteLeft)}
if(secondContainer&&secondContainer[0]){secondContainer[0].update(secondLeft)}
if(dayLabelContainer&&dayLabelContainer[0]){dayLabelContainer[0].update(this.dayLabel)}
if(hourLabelContainer&&hourLabelContainer[0]){hourLabelContainer[0].update(this.hourLabel)}
if(minuteLabelContainer&&minuteLabelContainer[0]){minuteLabelContainer[0].update(this.minuteLabel)}
if(secondLabelContainer&&secondLabelContainer[0]){secondLabelContainer[0].update(this.secondLabel)}
if(timeLeft<=0&&container.expiredId&&$(container.expiredId)){$(container.containerId).hide()
$(container.expiredId).show()}else{$(container.containerId).show()
if(container.expiredId&&$(container.expiredId))$(container.expiredId).hide()}}});var NerdyBannerGallery=Class.create({initialize:function(images,options){this.options={imageSwitchDuration:.5,containerId:'banner-slider',width:950,height:316,html_tpl:'<a href="#{target_url}"><img src="#{img_url} title="#{title}" width="#{width}" height="#{height}"/></a>',startPosition:1,cycle:'none',cycleDuration:10}
Object.extend(this.options,options)
this.images=images
this.selImgIdx=0
this.switching=false
this.initImages()
try{if(this.images.length>0&&$(this.options.containerId).select('.slider-nav-container')[0]){$(this.options.containerId).select('.slider-nav-container')[0].insert('<ul class="slider-nav"></ul>')}
for(var i=0;i<this.images.length;i++){var imgCfg={}
Object.extend(imgCfg,this.options)
Object.extend(imgCfg,this.images[i])
this.images[i]=imgCfg
this.images[i].html_tpl=new Template(this.images[i].html_tpl)
if(this.images[i].img_url){(new Image()).src=this.images[i].img_url}
$(this.options.containerId).select('.slider-nav')[0].insert('<li>&bull;</li>')
try{$(this.options.containerId).select('.slider-nav')[0].childElements()[i].observe('click',this.onSwitchSelImg.bindAsEventListener(this,i))}catch(e){}}}catch(e){}
try{$(this.options.containerId).select('.arrow-left')[0].observe('click',this.onPrevImage.bindAsEventListener(this))}catch(e){}
try{$(this.options.containerId).select('.arrow-right')[0].observe('click',this.onNextImage.bindAsEventListener(this))}catch(e){}
if(this.images.length>0){if(this.options.startPosition>1&&this.options.startPosition<=this.images.length)this.switchSelImg(this.options.startPosition-1)
else this.switchSelImg(0)}},startCycle:function(){this.stopCycle()
if(-1!=['left','right'].indexOf(this.options.cycle)&&this.options.cycleDuration>0){if(this.options.cycle=='left'){this.cycleLoop=new PeriodicalExecuter(this.prevImage.bind(this),this.options.cycleDuration)}else if(this.options.cycle=='right'){this.cycleLoop=new PeriodicalExecuter(this.nextImage.bind(this),this.options.cycleDuration)}}},stopCycle:function(){try{this.cycleLoop.stop()}catch(e){}},initImages:function(){this.frontImg=$(this.options.containerId).select('.content')[0]
this.backImg=$(this.options.containerId).select('.content')[1]
this.backImg.absolutize().clonePosition(this.frontImg).setOpacity(0)
this.frontImg.setStyle({width:this.options.width+'px',height:this.options.height+'px'})
this.backImg.setStyle({width:this.options.width+'px',height:this.options.height+'px'})},onPrevImage:function(e){this.stopCycle()
this.prevImage()},prevImage:function(){if(this.selImgIdx==0)this.switchSelImgIdx(this.images.length-1)
else this.switchSelImgIdx(this.selImgIdx-1)
this.switchImage()},onNextImage:function(e){this.stopCycle()
this.nextImage()},nextImage:function(e){if(this.selImgIdx==this.images.length-1)this.switchSelImgIdx(0)
else this.switchSelImgIdx(this.selImgIdx+1)
this.switchImage()},onSwitchSelImg:function(e,newIdx){this.switchSelImg(newIdx)},switchSelImg:function(newIdx){this.switchSelImgIdx(newIdx)
this.switchImage()},switchSelImgIdx:function(newIdx){try{$(this.options.containerId).select('.slider-nav')[0].childElements()[this.selImgIdx].removeClassName('active')}catch(e){}
this.selImgIdx=newIdx
try{$(this.options.containerId).select('.slider-nav')[0].childElements()[this.selImgIdx].addClassName('active')}catch(e){}
try{if(this.selImgIdx==0)$(this.options.containerId).select('.arrow-left')[0].addClassName('inactive')
else $(this.options.containerId).select('.arrow-left')[0].removeClassName('inactive')}catch(e){}
try{if(this.selImgIdx==this.images.length-1)$(this.options.containerId).select('.arrow-right')[0].addClassName('inactive')
else $(this.options.containerId).select('.arrow-right')[0].removeClassName('inactive')}catch(e){}},switchImage:function(){this.stopEffects()
this.setSwitching(false)
var selImg=this.images[this.selImgIdx]
this.backImg.update(selImg.html_tpl.evaluate(selImg))
this.switchEffect=new Effect.Parallel([new Effect.Opacity(this.frontImg,{sync:true,from:1,to:0}),new Effect.Opacity(this.backImg,{sync:true,from:0,to:1})],{duration:this.options.imageSwitchDuration,afterFinish:this.afterSwitch.bind(this)})
this.backImg.show()},afterSwitch:function(){this.finishSwitch()
this.setSwitching(false)},finishSwitch:function(){var oldFrontImg=this.frontImg
this.frontImg=this.backImg
this.backImg=oldFrontImg
this.backImg.hide()
this.startCycle()},setSwitching:function(flag){this.switching=flag},stopEffects:function(){try{this.switchEffect.cancel()}catch(e){}
if(this.switching){this.finishSwitch()
this.frontImg.setOpacity(1)
this.backImg.hide()}}});var NerdySlider=Class.create({initialize:function(options){this.options={moveDuration:.5,moveStep:1,prevClass:'arrow-left',nextClass:'arrow-right',startPosition:0,cycle:'none',cycleDuration:10,isListItemContainer:false}
Object.extend(this.options,options)
if(!$(this.options.containerId))return;if(this.options.container&&$(this.options.container)){this.container=$(this.options.container)}else{this.container=$(this.options.containerId)}
if(this.options.itemContainer&&$(this.options.itemContainer)){this.itemContainer=$(this.options.itemContainer)}else if(this.options.itemContainerId&&$(this.options.itemContainerId)){this.itemContainer=$(this.options.itemContainerId)}else if(this.options.itemContainerClass&&(this.itemContainer=this.container.select('.'+this.options.itemContainerClass))&&this.itemContainer.size()>0){this.itemContainer=this.itemContainer[0]}else{this.itemContainer=this.container}
if(this.options.itemClass){this.items=this.itemContainer.childElements().findAll((function(el){return el.hasClassName(this.options.itemClass)}).bind(this))}else{this.items=this.itemContainer.childElements()}
this.itemCnt=this.items.size()
if(this.itemCnt==0)return
if(this.options.navigationContainer&&$(this.options.navigationContainer)){this.navigationContainer=$(this.options.navigationContainer)}
if(this.options.navigationItems&&this.options.navigationItems.length>0){this.navigationItems=this.options.navigationItems}else if(this.navigationContainer){if(this.navigationContainer.childElements().size()>0){this.navigationItems=this.navigationContainer.childElements()}else{this.navigationItems=[]
if(this.options.isListItemContainer&&this.itemCnt>0){this.navigationContainer.insert('<ul class="bulls"></ul>')
this.navigationContainer=this.navigationContainer.childElements().last()}
for(i=0;i<this.itemCnt;i++){if(this.options.isListItemContainer){navItemHtml='<li><a href="javascript:void(0);">&bull;</a></li>'}else{navItemHtml='<a href="javascript:void(0);">&bull;</a>'}
this.navigationContainer.insert({bottom:navItemHtml})
this.navigationItems.push(this.navigationContainer.childElements().last())}}}
if(this.navigationItems&&this.navigationItems.length>0){for(i=0;i<this.navigationItems.length;i++){this.navigationItems[i].observe('click',this.onMoveByIdx.bindAsEventListener(this,i))}}
this.moveWidth=this.options.moveWidth||this.items[0].getDimensions().width
this.currentIdx=0
try{this.prevBtn=$(this.options.prevBtnId)||this.container.select('.'+this.options.prevClass)[0]
this.prevBtn.observe('click',this.onMovePrev.bindAsEventListener(this))}catch(e){}
try{this.nextBtn=$(this.options.nextBtnId)||this.container.select('.'+this.options.nextClass)[0]
this.nextBtn.observe('click',this.onMoveNext.bindAsEventListener(this))}catch(e){}
this.moveLock=false
if(this.options.startPosition>1&&this.options.startPosition<=this.itemCnt)this.moveByIdx(this.options.startPosition-1,true)
this.startCycle()
this.processPrevNextState()},startCycle:function(){this.stopCycle()
if(-1!=['left','right'].indexOf(this.options.cycle)&&this.options.cycleDuration>0){if(this.options.cycle=='left'){this.cycleLoop=new PeriodicalExecuter(this.movePrev.bind(this,false),this.options.cycleDuration)}else if(this.options.cycle=='right'){this.cycleLoop=new PeriodicalExecuter(this.moveNext.bind(this,false),this.options.cycleDuration)}}},stopCycle:function(){try{this.cycleLoop.stop()}catch(e){}},processPrevNextState:function(){try{if(this.currentIdx==0)this.prevBtn.addClassName('inactive')
else this.prevBtn.removeClassName('inactive')}catch(e){}
try{if(this.currentIdx+this.options.moveStep>=this.itemCnt)this.nextBtn.addClassName('inactive')
else this.nextBtn.removeClassName('inactive')}catch(e){}
try{this.navigationItems.invoke('removeClassName','active')
this.navigationItems[this.currentIdx].addClassName('active')}catch(e){}},onMovePrev:function(e){this.stopCycle()
this.movePrev(false)},movePrev:function(instant){if(this.moveLock)return
if(this.currentIdx-this.options.moveStep>=0){this.moveLock=true
this.currentIdx-=this.options.moveStep
if(instant){new Effect.Move(this.itemContainer,{x:this.moveWidth*this.options.moveStep,duration:0,afterFinish:this.clearMoveLock.bind(this)})}else{new Effect.Move(this.itemContainer,{x:this.moveWidth*this.options.moveStep,duration:this.options.moveDuration,afterFinish:this.clearMoveLock.bind(this)})}
this.processPrevNextState()}else if(this.options.cycle=='left'){this.moveByIdx(this.itemCnt-1)}},onMoveNext:function(e){this.stopCycle()
this.moveNext(false)},moveNext:function(instant){if(this.moveLock)return
if(this.currentIdx+this.options.moveStep<this.itemCnt){this.moveLock=true
this.currentIdx+=this.options.moveStep
if(instant){new Effect.Move(this.itemContainer,{x:-1*this.moveWidth*this.options.moveStep,duration:0,afterFinish:this.clearMoveLock.bind(this)})}else{new Effect.Move(this.itemContainer,{x:-1*this.moveWidth*this.options.moveStep,duration:this.options.moveDuration,afterFinish:this.clearMoveLock.bind(this)})}
this.processPrevNextState()}else if(this.options.cycle=='right'){this.moveByIdx(0)}},onMoveByIdx:function(e,idx){this.stopCycle()
this.moveByIdx(idx,false)},moveByIdx:function(idx,instant){if(this.moveLock||idx<0||idx>=this.itemCnt||this.currentIdx==idx)return
this.moveLock=true
if(instant){new Effect.Move(this.itemContainer,{x:-1*this.moveWidth*(idx-this.currentIdx),duration:0,afterFinish:this.clearMoveLock.bind(this)})}else{new Effect.Move(this.itemContainer,{x:-1*this.moveWidth*(idx-this.currentIdx),duration:this.options.moveDuration,afterFinish:this.clearMoveLock.bind(this)})}
this.currentIdx=idx
this.processPrevNextState()},clearMoveLock:function(){this.moveLock=false
this.startCycle()}})
