Element.addMethods({store:function(B,A,C){if(Object.isUndefined(this[$(B).identify()])||!Object.isHash(this[$(B).identify()])){this[$(B).identify()]=$H();}this[$(B).identify()].set(A,C);return B;},retrieve:function(B,A){return this[$(B).identify()].get(A);}});var CarouselModuleProductSmallImage={createItem:function(A){elm=new Element("img",{"src":A.small}).observe("click",function(B){$("carousel-product-large-image").fire("select:item",{innerIndex:B.element().up("li").retrieve("index")});}.bind(this)).wrap("li").store("index",A.index).store("title",A.title);return elm;}};var CarouselModuleProductLargeImage={createItem:function(A){elm=new Element("img",{"src":A.large}).observe("click",function(B){}.bind(this)).wrap("li").store("index",A.index).store("title",A.title);return elm;}};var CarouselModuleImage={createItem:function(A){elm=new Element("img",{"src":A.image}).observe("click",function(B){this.select(B.element().up("li").retrieve("index"));}.bind(this)).wrap("li").store("index",A.index).store("title",A.title);return elm;}};var CarouselModuleSimple={createItem:function(A){elm=A.elm;l_dim=this.getDimension(elm);elm=elm.observe("click",function(B){this.notify("onClick",B);}.bind(this)).wrap("li").store("dim",l_dim);return elm;}};var CarouselModuleLinkSpace={createItem:function(A){if(A.index){elm=new Element("div",{"class":"bt_header_left"});span=new Element("span").update(A.title).wrap("a",{"href":"#"+A.index});divDelete=new Element("div",{"class":"b-tabselector-closebutton"});divDelete.observe("click",function(B){this.notify("onDelete",B);}.bind(this));elm=elm.insert(span).insert(divDelete).wrap("li").store("index",A.index);elm.observe("click",function(B){this.notify("item:onClick",B);}.bindAsEventListener(this));Droppables.add(elm,{onHover:Controller.sportal.dragWidgetInTab.bind(Controller.sportal),overlap:"vertical"});return elm;}else{elm=new Element("div",{"class":"bt_header_left"});span=new Element("span").update(A.title).wrap("a");elm=elm.insert(span).wrap("li");elm.observe("click",function(B){this.notify("onClickNewTab",B);}.bind(this));return elm;}},updateItem:function(A){var B=this.findItem(A.memo.innerIndex).element;B.store("title",A.memo.title);B.select("a").last().innerHTML=A.memo.title;B.store("dim",B.getWidth());this.calculateBlocks().checkButtons();}};var CarouselModuleLink={createItem:function(A){elm=new Element("a",{"href":A.link}).update(A.title).observe("click",function(B){}.bind(this)).wrap("li").store("index",A.index).store("title",A.title);return elm;},updateItem:function(A){var B=this.findItem(A.memo.innerIndex).element;B.store("title",A.memo.title);B.select("a").last().innerHTML=A.memo.title;B.store("dim",B.getWidth());this.calculateBlocks().checkButtons();}};var SCarousel=Class.create({initialize:function(A){this.container=$(A);this.container.insert(new Element("ul"));this.current;this.locked=false;this.block={list:$A(),current:null};this.observers=$A();this.options=Object.extend({"buttonShowStyle":"inline","slideDuration":1,"kicker":0,highLight:null,direction:"horizontal"},arguments[1]||{});this.containerSize=this.getContainerDimension();this.internalCounter=1;this.container.observe("insert:item",this.insertItemEvent.bindAsEventListener(this));this.container.observe("select:item",this.selectEvent.bindAsEventListener(this));this.container.observe("update:item",this.updateItemEvent.bindAsEventListener(this));this.container.observe("delete:item",this.deleteItemEvent.bindAsEventListener(this));this.container.observe("previous:block",this.previous.bindAsEventListener(this));this.container.observe("next:block",this.next.bindAsEventListener(this));},addObserver:function(A){this.observers.push(A);this._cacheObserverCallbacks();},removeObserver:function(A){this.observers=this.observers.reject(function(B){return B.element==A;});this._cacheObserverCallbacks();},_cacheObserverCallbacks:function(){["item:onClick","onDelete","onClickNewTab"].each(function(A){this[A+"Count"]=this.observers.select(function(B){return B[A];}).length;}.bind(this));},notify:function(A,B){if(this[A+"Count"]>0){this.observers.each(function(C){if(C[A]){C[A](A,B);}});}},calculateBlocks:function(A){this.block.list.clear().push(0);var B=0;this.container.select("li").each(function(C){if(A){l_dim=A;}else{l_dim=C.retrieve("dim");}if((B+l_dim)>this.containerSize){this.block.list.push(this.block.list[this.block.list.size()-1]+B);B=0;}if(A){B+=A;}else{B+=this.getDimension(C);}}.bind(this));return this;},getDimension:function(A){if("horizontal"==this.options.direction){return(A.getWidth()+this.options.kicker);}else{return(A.getHeight()+this.options.kicker);}},getContainerDimension:function(){return(this.getDimension(this.container)-this.options.kicker);},insertItemEvent:function(A){item=this.add(A.memo);this.calculateBlocks().checkButtons();return item;},deleteItemEvent:function(A){this.deleteItem(A.memo);},updateItemEvent:function(A){this.updateItem(A);},selectEvent:function(A){this.select(A.memo.innerIndex);},add:function(B){var A=this.createItem(B);if(!B.insert){this.container.select("ul").last().insert(A);}else{if(B.insert.position.after){Element.insert(this.container.down("li",B.insert.location),{"after":A});}else{Element.insert(this.container.down("li",B.insert.location),{"before":A});}}return A.store("dim",this.getDimension(A));},setData:function(A,B){if(this.options.loading&&$(this.options.loading)){$(this.options.loading).remove();}A.each(function(C){this.add(C);}.bind(this));this.calculateBlocks();if(!B){this.block.current=0;this.checkButtons();}else{this.select(B);}},deleteItem:function(A){var B;if(Object.isElement(A.item)){B=A.item;}else{B=this.findItem(A.item).element;}if(B){B.remove();this.calculateBlocks().checkButtons();}return this;},highLight:function(B,A){if(!this.options.highLight||!B){return this;}if(this.current){this.current.removeClassName(this.options.highLight);}B.addClassName(this.options.highLight);this.current=B;if(Object.isNumber(A)){this.block.current=A;}return this;},select:function(B){var C=this.findItem(B);var A=this.findBlock(C.position);if(Object.isNumber(this.block.current)&&(this.block.current==A)){return this.highLight(C.element,A);}else{return this.move(this.block.list[A],A,C.element);}},findItem:function(C){var A=0;var B=this.container.select("li").find(function(D){A+=D.retrieve("dim");if(C==D.retrieve("index")){return true;}return false;});return{position:A,element:B};},findBlock:function(A){var B=this.block.list.reverse(false).find(function(C){if(A>C){return true;}else{return false;}});return this.block.list.indexOf(B);},createItem:function(A){return new Element("li").update(A);},checkButtons:function(){if(!this.options.previous&&!this.options.next){return this;}if((this.block.current+1)==this.block.list.size()){$(this.options.next).hide();}else{$(this.options.next).setStyle({"display":this.options.buttonShowStyle});}if(this.block.current<1){$(this.options.previous).hide();}else{$(this.options.previous).setStyle({"display":this.options.buttonShowStyle});}return this;},move:function(A,C,B){if(this.locked){return this;}else{this.locked=true;}this.block.current=C;if("horizontal"==this.options.direction){new Effect.Move(this.container.select("ul").last(),{"x":-A,mode:"absolute","duration":this.options.slideDuration,"afterFinish":this.afterMove.bind(this,B)});}else{new Effect.Move(this.container.select("ul").last(),{"y":-A,mode:"absolute","duration":this.options.slideDuration,"afterFinish":this.afterMove.bind(this,B)});}},afterMove:function(A){this.checkButtons().highLight(A).locked=false;},next:function(){if(this.block.list.size()>this.block.current){this.move(this.block.list[this.block.current+1],this.block.current+1);}},previous:function(){if(this.block.current>0){this.move(this.block.list[this.block.current-1],this.block.current-1);}}});