function ContentCarouselle(a){this._init(a)}ContentCarouselle.prototype={opts:null,DefaultOptions:{animate:false,buttonStopsAnimation:false,autoStart:false,tagContent:"LI",classContent:null,tagButton:"LI",classButton:null,btnPrev:null,btnNext:null,timerDelay:10000,animationDuration:500,animationFps:40,animationTransition:"sinoidal",currentSelected:0,buttonSelectedClass:"sel",buttonClickTransition:false,buttonOverTransition:false,autoWidth:false,direction:"auto",sync:null,circular:false},_init:function(a){var k=this;if(a.buttonTriggersAnimation!==undefined&&a.buttonTriggersAnimation!==null){a.buttonClickTransition=a.buttonOverTransition=a.buttonTriggersAnimation?ContentCarouselle.TransitionType.SLIDE:ContentCarouselle.TransitionType.STATIC}var c=k.opts=dgTools.extend(dgTools.extend({},k.DefaultOptions),a);c.inited=false;c.btnPrev=$(c.btnPrev);c.btnNext=$(c.btnNext);c.container=$(c.container);if(!c.container){return}c.containerLi=[];for(var e=0;e<c.container.childNodes.length;e++){if(c.container.childNodes[e].tagName==c.tagContent.toUpperCase()&&(c.classContent==null||c.classContent==c.container.childNodes[e].className)){c.containerLi.push(c.container.childNodes[e])}}if(c.direction!="rtl"&&c.direction!="ltr"){function f(l){if(!l){return false}var j=dgTools.Elm.getRenderedStyle(l,"direction");if(j=="rtl"){return true}if(j=="auto"||j=="inherit"){return f(l.parentNode)}return false}c.direction=f(c.container)?"rtl":"ltr"}c.buttons=$(c.buttons);if(c.buttons){c.buttonsLi=[];for(var e=0;e<c.buttons.childNodes.length;e++){if(c.buttons.childNodes[e].tagName==c.tagButton.toUpperCase()&&(c.classButton==null||c.classButton==c.buttons.childNodes[e].className)){c.buttonsLi.push(c.buttons.childNodes[e])}}while(c.buttonsLi.length>c.containerLi.length){c.buttonsLi.pop()}}c.count=c.containerLi.length;if(c.circular&&c.count>0){var h=c.containerLi[c.containerLi.length-1].cloneNode(true);var g=c.containerLi[0].cloneNode(true);c.containerLi[0].parentNode.insertBefore(h,c.containerLi[0]);c.containerLi[0].parentNode.appendChild(g);c.containerLi.insertBefore(h,0);c.containerLi.push(g)}else{c.circular=false}if(c.autoWidth){var i=0;c.containerLi.iterate(function(l,j){i+=dgTools.Elm.clientWidth(l)},k);c.container.style.width=i+"px"}var b=null;function d(l,j){dgTools.observe(l,"mouseover",function(n){var m=new dgTools.Event(n||event);if(m.relatedTarget==l||dgTools.Elm.hasChild(l,m.relatedTarget)){return}m.stop();b=l;k.goTo(j,c.buttonOverTransition)});dgTools.observe(l,"click",function(n){var m=new dgTools.Event(n||event);if(m.relatedTarget==l||dgTools.Elm.hasChild(l,m.relatedTarget)){return}m.stop();b=l;k.goTo(j,c.buttonClickTransition)});dgTools.observe(l,"mouseout",function(n){var m=new dgTools.Event(n||event);if(m.relatedTarget==l||dgTools.Elm.hasChild(l,m.relatedTarget)){return}if(c.timerEnabled&&!c.animationId){m.stop();k.stopTimer(true);k.startTimer()}b=null})}if(c.buttonsLi){c.buttonsLi.iterate(function(l,j){d(l,j)},k)}if(c.btnPrev){d(c.btnPrev,function(){if(c.currentSelected<=0){if(c.circular){return c.count-1}return 0}return c.currentSelected-1})}if(c.btnNext){d(c.btnNext,function(){if(c.currentSelected>=c.count-1){if(c.circular){return 0}return c.count-1}return c.currentSelected+1})}if(c.currentSelected<0){c.currentSelected=0}else{if(c.currentSelected>=c.count-1){c.currentSelected=c.count-1}}c.inited=true;c.container.style.left=k._getContentLeft(c.currentSelected)+"px";if(c.buttonsLi){dgTools.Elm.addClassName(c.buttonsLi[c.currentSelected],c.buttonSelectedClass)}if(c.autoStart){k.startTimer()}},_doAnimate:function(d){var a=this;var e=a.opts;if(e.animationId){e.animationId.stop();e.animationId=null}var c=a._getContentLeft(e.currentSelected);var b=function(){e.animationId=null;if(d){a.startTimer(true)}};e.animationId=dgTools.easyAnimate(e.container,null,{left:c},e.animationDuration,e.animationFps,b,e.animationTransition)},goTo:function(a,f){var d=this;var e=d.opts;if(f===undefined){f=ContentCarouselle.TransitionType.SLIDE}if(f==ContentCarouselle.TransitionType.NONE){return}var c=(typeof(a)=="function")?a():a;if((!e.buttonStopsAnimation&&e.animationId)||e.currentSelected==c){return}d.stopTimer(true);if(e.buttonsLi){dgTools.Elm.removeClassName(e.buttonsLi[e.currentSelected],e.buttonSelectedClass)}var b=e.currentSelected;e.currentSelected=c;if(e.buttonsLi){dgTools.Elm.addClassName(e.buttonsLi[e.currentSelected],e.buttonSelectedClass)}if(e.circular){if(b==0&&c==e.count-1){e.container.style.left=d._getContentLeft(e.count)+"px"}else{if(b==e.count-1&&c==0){e.container.style.left=d._getContentLeft(-1)+"px"}}}if(f==ContentCarouselle.TransitionType.SLIDE&&e.animate){d._doAnimate()}else{if(e.animationId){e.animationId.stop();e.animationId=null}e.container.style.left=d._getContentLeft(e.currentSelected)+"px"}if(e.sync&&e.sync.goTo){e.sync.goTo(e.currentSelected)}},startTimer:function(b){var a=this;var c=a.opts;if(!c.inited){return}if(!b){c.timerEnabled=true}if(c.timerTimeout){return}c.timerTimeout=setTimeout(function(){if(c.buttonsLi){dgTools.Elm.removeClassName(c.buttonsLi[c.currentSelected],c.buttonSelectedClass)}c.currentSelected=c.currentSelected+1;if(c.currentSelected>=c.count){c.currentSelected=0}if(c.circular&&c.currentSelected==0){c.container.style.left=a._getContentLeft(-1)+"px"}if(c.buttonsLi){dgTools.Elm.addClassName(c.buttonsLi[c.currentSelected],c.buttonSelectedClass)}if(c.animate){a._doAnimate(true)}else{var d=a._getContentLeft(c.currentSelected);c.container.style.left=d;c.timerTimeout=null;a.startTimer(true)}c.timerTimeout=null;if(c.sync&&c.sync.goTo){c.sync.goTo(c.currentSelected)}},c.timerDelay)},stopTimer:function(b){var a=this;var c=a.opts;if(!c.inited){return}if(!b){c.timerEnabled=false}if(c.timerTimeout){clearTimeout(c.timerTimeout);c.timerTimeout=null}},_getContentLeft:function(a){var b=this;var d=b.opts;if(!d.inited){return}var c=-dgTools.Elm.offset(d.containerLi[d.circular?a+1:a],d.container)[0];return c}};ContentCarouselle.TransitionType={NONE:false,STATIC:1,SLIDE:2};
