
if(PG==undefined)var PG={};PG.Carousel=Class.create();PG.Carousel.prototype={cardCount:0,cardWidth:160,contentContainerWidth:0,cardShow:3,currentIndex:0,spacing:5,shiftSize:1,backgroundColor:'#e8e8e8',fontColor:'#4d4d4d',height:160,cardHeight:160,slideDuration:.05,checkable:true,debug:true,nextControl:null,carousel:null,carouselContent:null,initialize:function(carouselId,options){if((typeof options.slideDuration!=undefined)&&(options.slideDuration!=undefined)){this.slideDuration=options.slideDuration;this.debug("cardHeight Parameter Set: "+options.slideDuration)}else{this.debug("cardHeight Not Defined");}
if((typeof options.cardHeight!=undefined)&&(options.cardHeight!=undefined)){this.cardHeight=options.cardHeight;this.debug("cardHeight Parameter Set: "+options.cardHeight)}else{this.debug("cardHeight Not Defined");}
if((typeof options.height!=undefined)&&(options.height!=undefined)){this.height=options.height;this.debug("height Color Parameter Set: "+options.height)}else{this.debug("height Not Defined");}
if((typeof options.backgroundColor!=undefined)&&(options.backgroundColor!=undefined)){this.backgroundColor=options.backgroundColor;this.debug("backGround Color Parameter Set: "+options.backgroundColor)}else{this.debug("backgroundColor Not Defined");}
if((typeof options.fontColor!=undefined)&&(options.fontColor!=undefined)){this.fontColor=options.fontColor;this.debug("Font Color Parameter Set: "+options.fontColor)}else{this.debug("Font Color Not Defined");}
if((typeof options.cardWidth!=undefined)&&(options.cardWidth!=undefined)){this.cardWidth=options.cardWidth;this.debug("Card Width Parameter Set: "+options.cardWidth)}else{this.debug("cardWidth Not Defined");}
if((typeof options.cardCount!=undefined)&&(options.cardCount!=undefined)){this.cardCount=options.cardCount;this.debug("Card Count Parameter Set: "+options.cardWidth)}else{this.debug("card Count Not Defined");}
if((typeof options.cardShow!=undefined)&&(options.cardShow!=undefined)){this.cardShow=options.cardShow;this.debug("cardShow Parameter Set: "+options.cardShow)}else{this.debug("cardShow Not Defined");}
if((typeof options.spacing!=undefined)&&(options.spacing!=undefined)){this.spacing=options.spacing;this.debug("spacing Parameter Set: "+options.spacing)}else{this.debug("spacing Not Defined");}
if((typeof options.shiftSize!=undefined)&&(options.shiftSize!=undefined)){this.shiftSize=options.shiftSize;this.debug("shiftSize Parameter Set: "+options.shiftSize)}else{this.debug("shiftSize Not Defined");}
this.debug(options);var wrapper=$$('#'+carouselId+' .carousel_wrapper')[0];wrapper.setStyle({backgroundColor:this.backgroundColor,fontColor:this.fontColor,height:this.height+'px'});this.cardCount=$$('#'+carouselId+' .carousel_card').size();var p=this;this.carousel=carouselId;this.nextControl=$$('#'+carouselId+' .nextControl img')[0];this.previousControl=$$('#'+carouselId+' .previousControl img')[0];this.setPositions();var inst=this;Event.observe($(this.nextControl),'click',function(e){if(inst.checkable==true){inst.checkable=false;inst.carouselNext();}});Event.observe($(this.previousControl),'click',function(e){if(inst.checkable==true){inst.checkable=false;inst.carouselPrevious();}});},debug:function(msg){try{if(this.debug==true){console.log(msg);}}catch(e){}},debugDir:function(obj){try{if(this.debug==true){console.dir(obj);}}catch(e){}},setPositions:function(){var p=this;var counter=1;var previous=-this.cardWidth;var carouselId=this.carousel;$$('#'+carouselId+' .carousel_card').each(function(card){var leftPos=((p.cardWidth+p.spacing))+previous;previous=leftPos;var cardheight=p.cardHeight+15;card.setStyle({height:cardheight+"px",left:leftPos+"px",width:p.cardWidth+"px"});counter++;});$$('#'+carouselId+' .carousel_card .carousel_type_header').each(function(card){card.setStyle({color:p.fontColor});counter++;});$$('#'+carouselId+' .carousel_card .carousel_card_body').each(function(card){var leftPos=((p.cardWidth+p.spacing))+previous;card.setStyle({height:p.cardHeight+"px"});});},carouselPrevious:function(){var p=this;for(shiftCounter=1;shiftCounter<=this.shiftSize;shiftCounter++){var cardList=$$('#'+this.carousel+' .carousel_card');var lastCard=cardList[cardList.length-shiftCounter];var cardwrap=$$('#'+p.carousel+' .carousel_wrapper')[0];var newcard=document.createElement('div');newcard.className='carousel_card';newcard.innerHTML=lastCard.innerHTML;var leftPos=-(this.cardWidth*shiftCounter);if(shiftCounter!=1){leftPos=leftPos-(this.spacing*(shiftCounter-1));}
try{newcard.style.left=leftPos+"px";newcard.style.width=p.cardWidth+"px";}catch(e){alert('Message: '+e.message);}
cardwrap.insertBefore(newcard,cardList[0]);}
var counter=0;$$('#'+this.carousel+' .carousel_card').each(function(card){if(counter>cardList.length-p.shiftSize){p.debug("name last goes here");card.setAttribute('name','last');}
var leftPos=(p.cardWidth+p.spacing)*p.shiftSize;new Effect.Move(card,{x:leftPos,y:0,move:'relative',duration:p.slideDuration,afterFinish:function(){if(card.getAttribute('name')=='last'){p.debug('trying to remove');Element.remove(card);p.checkable=true;}else{p.debug('dont remove this card');}}});counter++;});},carouselNext:function(){var p=this;var cardwrap=$$('#'+p.carousel+' .carousel_wrapper')[0];for(shiftCounter=0;shiftCounter<this.shiftSize;shiftCounter++){var firstcard=$$('#'+this.carousel+' .carousel_card')[shiftCounter];var newcard=document.createElement('div');newcard.className='carousel_card';newcard.id="card_"+shiftCounter;newcard.innerHTML=firstcard.innerHTML;cardwrap.appendChild(newcard);}
this.setPositions();var counter=0;$$('#'+this.carousel+' .carousel_card').each(function(card){var leftPos=(p.cardWidth+p.spacing)*p.shiftSize;if(counter<p.shiftSize){card.setAttribute('name','zero');}
new Effect.Move(card,{x:-leftPos,y:0,move:'relative',duration:p.slideDuration,afterFinish:function(obj){if(card.getAttribute('name')=='zero'){p.debug("trying to remove");p.debugDir(card);Element.remove(card);p.checkable=true;}else{p.debug("no remove");p.debug('counter is :'+counter);}}});counter++;});},hideNoShows:function(){var listOfCards=$$('#'+this.carousel+' li .carousel_card');var counter=0;var displayIndex=this.currentIndex;listOfCards.each(function(card){if((counter>displayIndex+2)||(counter<displayIndex)){var i=displayIndex+2;card.hide();}else{card.show();}
counter++;});},showAllPrevious:function(){var listOfCards=$$('#'+this.carousel+' li .carousel_card');var counter=0;var index=this.currentIndex;listOfCards.each(function(card){if(counter<index){card.show();}
counter++;});}};