(function(){if(typeof yaCarousel==="undefined"||!yaCarousel){yaCarousel=function(f,e){this.init(f,e)};var a=10,b=window,d=function(e){return document.getElementById(e)},c=function(){if(b.addEventListener){return function(e,j,i,h,f){var g=function(k){return h.call(e,k,f||[])};j.addEventListener(i,g,false)}}else{if(b.attachEvent){return function(e,j,i,h,f){var g=function(k){return h.call(e,k,f||[])};j.attachEvent("on"+i,g)}}else{return function(){}}}}();yaCarousel.prototype={init:function(g,e){var f=this;f.id=g;f.list=d(g);f.scrollInc=e.scrollInc||1;f.numVisible=e.numVisible||1;f.isCircular=e.isCircular||false;f.startIndex=0;f.lastIndex=f.numVisible-1;f.size=e.size||10000;f.timer=null;f.anmTimer=null;f.autoPlayAt=e.autoPlayAt||0;f.autoPlayLength=e.autoPlayLength||-1;f.anmSec=(typeof e.animationSpeed==="number")?e.animationSpeed:0.15;if(e.nextElement){if(typeof e.nextElement==="string"){f.nextElement=d(e.nextElement)}else{if(e.nextElement.nodeName){f.nextElement=e.nextElement}}if(f.nextElement){c(f,f.nextElement,"mouseup",f._onNextClick)}}if(e.prevElement){if(typeof e.prevElement==="string"){f.prevElement=d(e.prevElement)}else{if(e.prevElement.nodeName){f.prevElement=e.prevElement}}if(f.prevElement){c(f,f.prevElement,"mouseup",f._onPrevClick)}}f.loadNextHandler=(typeof e.loadNextHandler==="function")?e.loadNextHandler:function(){};f.loadPrevHandler=(typeof e.loadPrevHandler==="function")?e.loadPrevHandler:function(){};f.loadItemHandler=(typeof e.loadItemHandler==="function")?e.loadItemHandler:function(){};if(typeof e.loadInitHandler==="function"){e.loadInitHandler.apply(f,[f.startIndex,f.lastIndex])}f._calculateSize();if(e.autoPlay&&typeof e.autoPlay==="number"){f.autoPlayInterval=e.autoPlay;f.startAutoPlay()}},scrollTo:function(l){var m=this,e=m.list.style,h=m.startIndex,n=m.scrollAmountPerInc,f,g,k,j,i;m._setIndex(l);f=m.startIndex;k=-1*n*f;m.loadItemHandler(m.startIndex,m.lastIndex,m._itemsLoaded(0,m.lastIndex));if(m.anmSec<=0){e.left=k+"px"}else{clearInterval(m.anmTimer);e.left="-"+n*h+"px";g=f-h;j=(n*g)/(m.anmSec/a*1000);m.anmTimer=setInterval(function(){i=parseInt(e.left)-j;if(g>0&&i<=k||g<=0&&i>=k){e.left=k+"px";clearInterval(m.anmTimer)}else{e.left=i+"px"}},a)}},addItem:function(f,i,j){if(f<0||f>=this.size){return}if(!i){return}var g=this,e=g.getItem(f),h;if(e==null||typeof e!=="object"){e=g._createItem(f,i);g.list.appendChild(e)}else{if(e.placeholder){h=g._createItem(f,i);g.list.replaceChild(h,e);e=h}}if(j){e.className=j}},getItem:function(e){return d(this.id+"-item-"+e)},startAutoPlay:function(){var e=this;e.timer=setTimeout(function(){e.scrollNext();e.timer=setInterval(function(){e.scrollNext()},e.autoPlayInterval);if(e.autoPlayLength!=-1){setTimeout(function(){e.stopAutoPlay()},e.autoPlayLength)}},e.autoPlayAt)},stopAutoPlay:function(){this.timer=clearTimeout(this.timer)},scrollNext:function(){var e=this;e.scrollTo(e.startIndex+e.scrollInc);e.loadNextHandler(e.startIndex,e.lastIndex,e._itemsLoaded(0,e.lastIndex))},scrollPrev:function(){var e=this;e.scrollTo(e.startIndex-e.scrollInc);e.loadPrevHandler(e.startIndex,e.lastIndex,e._itemsLoaded(0,e.lastIndex))},_calculateSize:function(){var e=null,g=this,j=g.list,h,f;for(h=0,f=j.childNodes.length;h<f;h++){e=j.childNodes[h];if(e.nodeType==1&&e.tagName.toLowerCase()=="li"){break}}g.scrollAmountPerInc=e.offsetWidth;j.style.left="-"+g.scrollAmountPerInc*g.startIndex+"px"},_onNextClick:function(f){this.stopAutoPlay();this.scrollNext()},_onPrevClick:function(f){this.stopAutoPlay();this.scrollPrev()},_setIndex:function(e){this.startIndex=e;this._fixIndex()},_fixIndex:function(){var e=this;if(e.startIndex>=e.size){if(e.isCircular){e.startIndex=0}else{e.startIndex=e.size-1}}if(e.startIndex<0){if(e.isCircular){e.startIndex=e.size-1}else{e.startIndex=0}}e.lastIndex=e.startIndex+e.numVisible-1},_createItem:function(f,g){var e=document.createElement("li");e.id=this.id+"-item-"+f;if(typeof g==="string"){e.innerHTML=g}else{e.appendChild(g)}return e},_itemsLoaded:function(j,h){var f=true,g,e;for(g=j;g<=h;g++){e=this.getItem(g);if(e==null||typeof e!=="object"){this._prebuildLiElem(g);f=false}else{if(e.placeholder){f=false}}}return f},_prebuildLiElem:function(f){if(f<0){return}var e=document.createElement("li");e.id=this.id+"-item-"+f;e.placeholder=true;this.list.appendChild(e)}}}})();
