window.project=(window.project)?window.project:{};(function($)
{project.TeaserStageBehaviour=function(dom_element,options)
{var that=this;this.dom_element=dom_element;this.content_elements=this.dom_element.find(".teaser_stage_element");this.rotate_timer=null;this.ul_element=null;this.li_elements=[];this.mask_elements=[];this.li_elements_length=0;this.position=0;this.stage_size={"x":0,"y":0};options=options||{};this.options={"btn_prev_text":"vorheriger Teaser","btn_next_text":"nächster Teaser","speed":options.speed||1000,"rotate":options.rotate==="1"?true:false,"duration":options.duration||600};if(this.options.rotate)
{this.dom_element.bind({"mouseenter":function()
{that.disableRotation();},"mouseleave":function()
{that.enableRotation();}});that.enableRotation();}
this.initialize();};project.TeaserStageBehaviour.prototype.initialize=function()
{var that=this;this.ul_element=this.dom_element.find("ul").first();this.li_elements=this.ul_element.children("li");var content_elements=this.dom_element.find(".teaser_stage_element");this.mask_elements=this.dom_element.find(".teaser_stage_mask");this.li_elements_length=this.li_elements.length;if(this.li_elements_length>1)
{this.stage_size.x=$(this.li_elements[0]).outerWidth();this.stage_size.y=$(this.li_elements[0]).outerHeight();this.ul_element.css({"width":this.stage_size.x*this.li_elements_length,"height":this.stage_size.y,"overflow":"hidden"});content_elements.each(function(index,element)
{$(element).css({"position":"absolute","top":0,"left":that.stage_size.x*index});if(index!==0)
{$(that.mask_elements[index]).css("left",-1*that.stage_size.x);}});this.addEvents();this.initializeControls();}};project.TeaserStageBehaviour.prototype.enableRotation=function()
{var that=this;this.options.rotate=true;clearTimeout(this.rotate_timer);this.rotate_timer=setInterval(function(){that.next();},this.options.speed);};project.TeaserStageBehaviour.prototype.disableRotation=function()
{this.options.rotate=false;clearTimeout(this.rotate_timer);this.rotate_timer=null;};project.TeaserStageBehaviour.prototype.addEvents=function()
{var that=this;this.dom_element.bind("scroll",function()
{that.dom_element.scrollTo(0);});this.li_elements.each(function(index,li_element)
{var a_elements=$(li_element).find("a");if(a_elements.length)
{a_elements.bind("focus",function()
{that.setPosition(index);});}});};project.TeaserStageBehaviour.prototype.previous=function()
{var new_position=this.position-1;if(new_position<0)
{new_position=this.content_elements.length-1;}
this.setPosition(new_position);};project.TeaserStageBehaviour.prototype.next=function()
{var new_position=this.position+1;if(new_position>this.content_elements.length-1)
{new_position=0;}
this.setPosition(new_position);};project.TeaserStageBehaviour.prototype.initializeControls=function()
{var that=this;var div_controls=$("<div></div>").addClass("teaser_stage_controls");var prev=$("<span></span>").addClass("skip_left cursor").text(this.options.btn_prev_text).bind("click",function()
{that.previous();});prev.attr({"title":this.options.btn_prev_text,"role":"button"});var next=$("<span></span>").addClass("skip_right cursor").text(this.options.btn_next_text).bind("click",function()
{that.next();});next.attr({"title":this.options.btn_next_text,"role":"button"});this.dom_element.append(div_controls.append(prev).append(next));};project.TeaserStageBehaviour.prototype.setPosition=function(position)
{if(position===this.li_elements_length||position===-1)
{throw new Error('Mom?'+position);}
$(this.mask_elements[this.position]).css("left",-1*this.stage_size.x);this.position=position;for(var i=0;i<this.li_elements.length;i++)
{jQuery(this.content_elements[i]).animate({'left':this.stage_size.x*i-this.stage_size.x*this.position},{'duration':this.options.duration,'queue':false});}
$(this.mask_elements[this.position]).css("left",0);};JsBehaviourToolkit.registerHandler("teaser_stage",project.TeaserStageBehaviour);})(jQuery)
