/*
 * Copyright (c) 2009 by Florian Moser @ novalab - new media engineering - http://www.novalab.ch/
 */
var MerryGoRound=Class.create({initialize:function(e,b){this.listElement=$(e);var d=this.listElement.select("li")[0];if(!d){return}this.options=Object.extend({duration:0.7,transition:Effect.Transitions.sinoidal,autorun:false,autorunDelay:5,autorunDirection:true,showHandles:true},b||{});this.nLiElements=this.listElement.select("li").size();if(this.options.autorun&&!this.options.autorunDirection){this.currentFrameID=this.nLiElements-1}else{this.currentFrameID=0}this.listElement.select("li").each(function(g){g.setStyle({"float":"left",listStyle:"none"})});this.frameDimension=d.getDimensions();this.listElement.setStyle({position:"relative",left:-1*this.currentFrameID*this.frameDimension.width+"px",top:"0",width:(this.frameDimension.width*this.nLiElements)+"px",margin:"0",padding:"0"});var a=new Element("div",{className:"mgr_container"});if(this.options.showHandles){this.linkContainer=new Element("div",{className:"mgr_linkContainer"});this.linkContainer.insert(this.createHandle("back","&lt;","mgr_linkBack"));for(var c=0;c<this.nLiElements;c++){this.linkContainer.insert(this.createHandle(c,c+1,"mgr_link"))}this.linkContainer.insert(this.createHandle("next","&gt;","mgr_linkNext"));a.update(this.linkContainer);this.linkContainer.select("a").each(this.activateHandle.bind(this))}var f=new Element("div",{className:"mgr_frame"});f.setStyle({width:this.frameDimension.width+"px",height:this.frameDimension.height+"px",overflowX:"hidden"});Element.wrap(this.listElement,f);Element.wrap(f,a);if(this.options.autorun){this.pUpdater=new PeriodicalExecuter(this.autoNextFrame.bind(this),this.options.autorunDelay)}},handleEvent:function(a){if(this.pUpdater){this.pUpdater.stop()}switch(a.element().frameID){case"next":this.currentFrameID++;break;case"back":this.currentFrameID--;break;default:this.currentFrameID=parseInt(a.element().frameID)}this.rotate()},createHandle:function(c,b,a){var d=new Element("a",{className:a});d.innerHTML=b;d.setStyle({cursor:"pointer"});d.observe("click",this.handleEvent.bind(this));d.frameID=c;return d},activateHandle:function(a){if(a.frameID==this.currentFrameID){a.addClassName("mgr_link_active")}else{a.removeClassName("mgr_link_active")}},rotate:function(){if(isNaN(this.currentFrameID)){this.currentFrameID=0}if(this.currentFrameID>=this.nLiElements){this.currentFrameID=0}if(this.currentFrameID<0){this.currentFrameID=this.nLiElements-1}new Effect.Move(this.listElement,{x:(-1*this.currentFrameID*this.frameDimension.width),y:0,mode:"absolute",duration:this.options.duration,transition:this.options.transition});if(this.options.showHandles){this.linkContainer.select("a").each(this.activateHandle.bind(this))}},autoNextFrame:function(){if(this.options.autorunDirection){this.currentFrameID++}else{this.currentFrameID--}this.rotate()}});
