var pScroll=new Class({Implements:Options,options:{productHeight:142,productWidth:186,numberOfProducts:4,scrollFX:Fx.Transitions.Quart.easeInOut,duration:1E3,parentDiv:null,orientation:"horizontal",url:location.href,func:"getRecentlyViewed",title:"",doAnimation:false,viewAllLink:""},contentTable:null,content:null,pagination:null,paginationBullets:null,products:null,headerTable:null,leftArrowTop:null,leftArrow:null,rightArrowTop:null,rightArrow:null,viewAllLink:null,startingIndex:0,margin:0,generatedLIndex:0, generatedRIndex:0,totalLength:0,activePage:0,initialize:function(a){if(!a.parentDiv){alert("You must supply the parentDiv ID!");return false}this.setOptions(a);this.totalLength=this.options.orientation=="horizontal"?this.options.numberOfProducts*this.options.productWidth:this.options.numberOfProducts*this.options.productHeight;this.setProducts("func="+this.options.func);this.setupPScroll();this.contentTable.set("tween",{duration:this.options.duration,transition:this.options.scrollFX})},setupPScroll:function(){if(this.options.orientation== "horizontal"){var a=(new Element("table",{cellspacing:0,cellpadding:0,align:"right",width:this.totalLength+48+"px",style:"margin-bottom:10px; margin-left:10px; clear:both;",align:"left"})).inject(this.options.parentDiv);a=(new Element("tbody")).inject(a);var b=(new Element("tr")).inject(a),c=(new Element("td",{colspan:10})).inject(b);this.headerTable=(new Element("table",{"class":"productSubSectionHeader"})).inject(c);b=(new Element("tbody")).inject(this.headerTable);b=(new Element("tr")).inject(b); (new Element("td",{html:this.options.title})).inject(b);this.paginationBullets=(new Element("td",{"class":"paginationDots"})).inject(b);this.pagination=(new Element("td",{"class":"viewAllLink"})).inject(b);b=(new Element("tr")).inject(a);this.leftArrowTop=(new Element("td",{"class":"topCapPieceLeft",style:"height:4px;",html:'<img src="images/pScrollHorizTop.jpg"/>',events:{click:this.scroll.bind(this,-1),mouseover:this.hover.bind(this,[-1,1]),mouseout:this.hover.bind(this,[-1,0])}})).inject(b);c= (new Element("td",{style:"width:"+this.totalLength+"px;",rowspan:2,"class":"scrollingProductContainer"})).inject(b);d=(new Element("div",{style:"overflow:hidden;width:"+this.totalLength+"px;"})).inject(c);this.contentTable=(new Element("table",{"class":"productScrollTable"})).inject(d);c=(new Element("tbody")).inject(this.contentTable);this.content=(new Element("tr")).inject(c);this.rightArrowTop=(new Element("td",{"class":"topCapPieceRight",style:"height:4px;",html:'<img src="images/pScrollHorizTop.jpg"/>', events:{click:this.scroll.bind(this,1),mouseover:this.hover.bind(this,[1,1]),mouseout:this.hover.bind(this,[1,0])}})).inject(b);b=(new Element("tr")).inject(a);this.leftArrow=(new Element("td",{"class":"horizontalPScroll",style:"padding-right:5px;",events:{click:this.scroll.bind(this,-1),mouseover:this.hover.bind(this,[-1,1]),mouseout:this.hover.bind(this,[-1,0])}})).inject(b);(new Element("div",{"class":"leftArrow"})).inject(this.leftArrow);this.rightArrow=(new Element("td",{"class":"horizontalPScroll", style:"padding-right:5px;",events:{click:this.scroll.bind(this,1),mouseover:this.hover.bind(this,[1,1]),mouseout:this.hover.bind(this,[1,0])}})).inject(b);(new Element("div",{"class":"rightArrow"})).inject(this.rightArrow)}else{a=(new Element("table",{cellspacing:0,cellpadding:0,align:"center",height:this.totalLength+100+"px",style:"clear:both;"})).inject(this.options.parentDiv);a=(new Element("tbody")).inject(a);b=(new Element("tr")).inject(a);c=(new Element("td")).inject(b);var d=(new Element("div", {"class":"verticalHeaderLine",html:this.options.title})).inject(c);this.pagination=(new Element("div",{style:"text-align:center;",html:"&nbsp;"})).inject(c);this.viewAllLink=(new Element("div",{"class":"verticalViewAllProducts",html:'<a href="'+this.options.viewAllLink+'">View All Products</a>'})).inject(c);this.leftArrow=(new Element("tr")).inject(a);(new Element("td",{html:'<div class="arrowButton"></div>',events:{click:this.scroll.bind(this,-1),mouseover:this.hover.bind(this,[-1,1]),mouseout:this.hover.bind(this, [-1,0])}})).inject(this.leftArrow);b=(new Element("tr")).inject(a);c=(new Element("td")).inject(b);d=(new Element("div",{"class":"verticalScrollProductContainer",style:"height:"+this.totalLength+"px;"})).inject(c);this.contentTable=(new Element("table",{cellspacing:0,cellpadding:0,align:"right",style:"margin-bottom:10px; clear:both; float:none;"})).inject(d);this.content=(new Element("tbody")).inject(this.contentTable);this.rightArrow=(new Element("tr")).inject(a);(new Element("td",{"class":"arrowButton", html:'<div class="arrowButtonBottom"></div>',events:{click:this.scroll.bind(this,1),mouseover:this.hover.bind(this,[1,1]),mouseout:this.hover.bind(this,[1,0])}})).inject(this.rightArrow)}},scroll:function(a){this.activePage+=a;var b=this.startingIndex,c=this.margin;this.startingIndex+=a*this.options.numberOfProducts;this.margin=1*(this.margin+-a*this.totalLength);if(this.startingIndex>=this.products.length||this.startingIndex<0){this.startingIndex=b;this.margin=c;return false}this.startingIndex<this.generatedLIndex|| this.startingIndex>this.generatedRIndex?this.newContent():this.setPagination();if(this.options.orientation=="vertical")if(this.options.doAnimation)this.contentTable.tween("margin-top",1*this.margin);else this.contentTable.style.marginTop=1*this.margin;else if(this.options.doAnimation)this.contentTable.tween("margin-left",1*this.margin);else this.contentTable.style.marginLeft=1*this.margin},setPage:function(a){var b=this.activePage;for(b=(a-b)/Math.abs(a-b);this.activePage!=a;)this.scroll(b)},hover:function(a, b){if(this.options.orientation=="horizontal")if(a<0)if(b==1&&!this.leftArrow.getElement("div.leftArrowInactive")){this.leftArrowTop.getElement("img").src="images/pScrollHorizTopHover.jpg";this.leftArrow.className="horizontalPScrollHover"}else{this.leftArrowTop.getElement("img").src="images/pScrollHorizTop.jpg";this.leftArrow.className="horizontalPScroll"}else if(b==1&&!this.rightArrow.getElement("div.rightArrowInactive")){this.rightArrowTop.getElement("img").src="images/pScrollHorizTopHover.jpg"; this.rightArrow.className="horizontalPScrollHover"}else{this.rightArrowTop.getElement("img").src="images/pScrollHorizTop.jpg";this.rightArrow.className="horizontalPScroll"}else if(a<0)if(b==1&&!this.leftArrow.getElement("div.arrowButtonInactive")){if(this.leftArrow.getElement("div.arrowButton"))this.leftArrow.getElement("div.arrowButton").className="arrowButtonHover"}else{if(this.leftArrow.getElement("div.arrowButtonHover"))this.leftArrow.getElement("div.arrowButtonHover").className="arrowButton"}else if(b== 1&&!this.rightArrow.getElement("div.arrowButtonBottomInactive")){if(this.rightArrow.getElement("div.arrowButtonBottom"))this.rightArrow.getElement("div.arrowButtonBottom").className="arrowButtonBottomHover"}else if(this.rightArrow.getElement("div.arrowButtonBottomHover"))this.rightArrow.getElement("div.arrowButtonBottomHover").className="arrowButtonBottom"},setProducts:function(a,b){if(a)(new Request({url:this.options.url,method:"post",onComplete:function(c){this.products=JSON.decode(c);if(this.products.length== 0)$(this.options.parentDiv).style.display="none";else if(this.products.length<=this.options.numberOfProducts){this.leftArrow.style.display="none";this.rightArrow.style.display="none";this.pagination.style.display="none";if(this.options.orientation=="vertical"){this.contentTable.getParent(".verticalScrollProductContainer").style.height=this.products.length*this.options.productHeight;this.contentTable.getParent(".verticalScrollProductContainer").getParent("table").style.height=this.products.length* this.options.productHeight+100}else{this.leftArrowTop.style.display="none";this.rightArrowTop.style.display="none";this.paginationBullets.style.display="none";this.contentTable.getParent("div").style.width=this.products.length*this.options.productWidth;this.contentTable.getParent("div").getParent("td.scrollingProductContainer").style.width=this.products.length*this.options.productWidth;this.headerTable.style.width=this.products.length*this.options.productWidth;this.contentTable.getParent("table").width= this.products.length*this.options.productWidth}}this.newContent()}.bind(this)})).send(a);else this.products=b},setPagination:function(){var a=(this.startingIndex+this.options.numberOfProducts)/this.options.numberOfProducts,b=Math.ceil(this.products.length/this.options.numberOfProducts);if(this.options.orientation=="horizontal"){this.paginationBullets.set("html","");this.pagination.set("html",'<a href="'+this.options.viewAllLink+'">View All Products</a>');for(var c=0;c<b*1;c++)c+1==a?(new Element("span", {"class":"active",html:" &bull; "})).inject(this.paginationBullets):(new Element("span",{html:" &bull; ",events:{click:this.setPage.bind(this,c)}})).inject(this.paginationBullets);if(a==1){if(this.rightArrow.getElement("div.rightArrowInactive"))this.rightArrow.getElement("div.rightArrowInactive").className="rightArrow";this.leftArrow.getElement("div.leftArrow").className="leftArrowInactive"}else if(a==b){if(this.leftArrow.getElement("div.leftArrowInactive"))this.leftArrow.getElement("div.leftArrowInactive").className= "leftArrow";this.rightArrow.getElement("div.rightArrow").className="rightArrowInactive"}else{if(this.leftArrow.getElement("div.leftArrowInactive"))this.leftArrow.getElement("div.leftArrowInactive").className="leftArrow";if(this.rightArrow.getElement("div.rightArrowInactive"))this.rightArrow.getElement("div.rightArrowInactive").className="rightArrow"}}else{this.pagination.set("html","Page "+(a+" of "+b));if(a==1){if(this.rightArrow.getElement("div.arrowButtonBottomInactive"))this.rightArrow.getElement("div.arrowButtonBottomInactive").className= "arrowButtonBottom";a=this.leftArrow.getElement("div.arrowButton")?this.leftArrow.getElement("div.arrowButton"):this.leftArrow.getElement("div.arrowButtonHover");a.className="arrowButtonInactive"}else if(a==b){if(this.leftArrow.getElement("div.arrowButtonInactive"))this.leftArrow.getElement("div.arrowButtonInactive").className="arrowButton";a=this.rightArrow.getElement("div.arrowButtonBottom")?this.rightArrow.getElement("div.arrowButtonBottom"):this.rightArrow.getElement("div.arrowButtonBottomHover"); a.className="arrowButtonBottomInactive"}else{if(this.leftArrow.getElement("div.arrowButtonInactive"))this.leftArrow.getElement("div.arrowButtonInactive").className="arrowButton";if(this.rightArrow.getElement("div.arrowButtonBottomInactive"))this.rightArrow.getElement("div.arrowButtonBottomInactive").className="arrowButtonBottom"}}},newContent:function(){for(var a=this.startingIndex+this.options.numberOfProducts>this.products.length?this.products.length:this.startingIndex+this.options.numberOfProducts, b=0,c=this.startingIndex;c<a;c++){this.buildProduct(this.products[c]).inject(this.content);if(c<this.generatedLIndex)this.generatedLIndex=c;if(c>this.generatedRIndex)this.generatedRIndex=c;b++}if(this.options.orientation=="horizontal")this.contentTable.style.width=this.contentTable.style.width.substring(0,this.contentTable.style.width.length-2)*1+b*this.options.productWidth;else this.contentTable.style.height=this.contentTable.style.height.substring(0,this.contentTable.style.height.length-2)*1+b* this.options.productHeight;this.setPagination()},buildProduct:function(a){var b=new Element("td",{id:"pScrollProd_"+a.id,"class":this.options.orientation=="vertical"?"verticalPScroll productContainer2":"productContainerScroll",height:this.options.productHeight+"px"}),c=(new Element("a",{href:a.href})).inject(b);(new Element("img",{border:0,src:a.image,alt:a.alt})).inject(c);a.productName.indexOf(a.manufacturer)>-1||a.id.indexOf("b")>-1?(new Element("div",{"class":"popularTitle",html:a.manufacturer})).inject(b): (new Element("div",{"class":"popularTitle",html:a.productName})).inject(b);a.productName.indexOf(a.manufacturer)>-1&&a.id.indexOf("b")==-1&&(new Element("span",{"class":"popularSubTitle",html:a.productName.replace(a.manufacturer,"")})).inject(b);c=(new Element("div",{"class":"ratingAndCost"})).inject(b);(new Element("div",{html:a.rating})).inject(c);(new Element("text",{html:"$"+a.price})).inject(c);if(this.options.orientation=="vertical"){a=new Element("tr");b.inject(a);b=a}return b}});
