// Content Slider script for Module Banner Slider
// by VietNQ [aFeLiOn], the fading script is based on Featured Content Slider script - dynamicdrive.com

function ContentSlider(sliderid,effect,delay,random){this.id=sliderid
this.timer=sliderid+"timer"
this.delay=(typeof(delay)=="number")?delay:3000
this.effect=(typeof(effect)=="string")?effect:"none"
this.sliders=[]
this.pointer=-1
this.pause=0
var slider=document.getElementById(sliderid)
var alldivs=slider.getElementsByTagName("div")
for(var i=0;i<alldivs.length;i++){if(alldivs[i].className=="bs_opacitylayer")
slider.opacitylayer=alldivs[i]
else if(alldivs[i].className=="bs_contentdiv"){this.sliders.push(alldivs[i])}}
if(this.sliders.length==0)
return;this.targetobject=slider.opacitylayer||null
var csobj=this
slider.onmouseover=function(){csobj.pause=1}
slider.onmouseout=function(){csobj.pause=0}
if((typeof(random)=="undefined")||(random==1))
this.sliders.sort(function(){return 0.5-Math.random();})
if(this.effect.charAt(0)=='s'){this.speed=1.1
this.height=parseInt(slider.style.height)
this.width=parseInt(slider.style.width)
this.pos=1
this.pointer=0
for(var i=0;i<this.sliders.length;i++){this.sliders[i].style.position="relative"}}
switch(effect){case"scroll_left":case"scroll_top":this.scrollL()
break
case"scroll_right":case"scroll_bottom":this.scrollR()
break
case"fade":default:this.slide()}}
ContentSlider.prototype.next=function(){this.pointer=(this.pointer<this.sliders.length-1)?this.pointer+1:0}
ContentSlider.prototype.hideall=function(){for(var i=0;i<this.sliders.length;i++){this.sliders[i].style.display="none"}}
ContentSlider.prototype.slide=function(){var csobj=this
if(this.pause){window[this.timer]=setTimeout(function(){csobj.slide()},1000)}
else{this.next()
this.hideall();if(this.effect!="none"){if(window[this.id+"fadetimer"])
clearTimeout(window[this.id+"fadetimer"])
this.setopacity(0.1)}
this.sliders[this.pointer].style.display="block"
if(this.effect!="none")
this.fadeup()
window[this.timer]=setTimeout(function(){csobj.slide()},this.delay)}}
ContentSlider.prototype.fadeup=function(){if(this.targetobject&&this.targetobject.currentopacity<1){this.setopacity(this.targetobject.currentopacity+0.1)
var csobj=this
window[this.id+"fadetimer"]=setTimeout(function(){csobj.fadeup()},100)}}
ContentSlider.prototype.setopacity=function(value){if(this.targetobject&&this.targetobject.filters&&this.targetobject.filters[0]){if(typeof this.targetobject.filters[0].opacity=="number")
this.targetobject.filters[0].opacity=value*100
else
this.targetobject.style.filter="alpha(opacity="+value*100+")"}
else if(this.targetobject&&typeof this.targetobject.style.MozOpacity!="undefined")
this.targetobject.style.MozOpacity=value
else if(this.targetobject&&typeof this.targetobject.style.opacity!="undefined")
this.targetobject.style.opacity=value
this.targetobject.currentopacity=value}
ContentSlider.prototype.scrollL=function(){var csobj=this
if(this.pause){window[this.timer]=setTimeout(function(){csobj.scrollL()},1000)}
else{if((this.effect=="scroll_left"&&this.pos>-this.width)||(this.effect=="scroll_top"&&this.pos>-this.height)){if(this.pos==0){this.pos=-1;window[this.timer]=setTimeout(function(){csobj.scrollL()},this.delay)
return;}
else if(this.pos<0)
this.pos=Math.floor(this.pos*this.speed)-1;else
this.pos=Math.floor(this.pos/this.speed);}
else{this.sliders[this.pointer].style.display="none"
this.pos=-this.pos;this.next()}
this.sliders[this.pointer].style.display="block"
if(this.effect=="scroll_left")
this.sliders[this.pointer].style.left=this.pos+"px"
else
this.sliders[this.pointer].style.top=this.pos+"px"
window[this.timer]=setTimeout(function(){csobj.scrollL()},100)}}
ContentSlider.prototype.scrollR=function(){var csobj=this
if(this.pause){window[this.timer]=setTimeout(function(){csobj.scrollR()},1000)}
else{if((this.effect=="scroll_right"&&this.pos<this.width)||(this.effect=="scroll_bottom"&&this.pos<this.height)){if(this.pos==0){this.pos=1;window[this.timer]=setTimeout(function(){csobj.scrollR()},this.delay)
return;}
else if(this.pos<0)
this.pos=Math.ceil(this.pos/this.speed);else
this.pos=Math.ceil(this.pos*this.speed);}
else{this.sliders[this.pointer].style.display="none"
this.pos=-this.pos;this.next()}
this.sliders[this.pointer].style.display="block"
if(this.effect=="scroll_right")
this.sliders[this.pointer].style.left=this.pos+"px"
else
this.sliders[this.pointer].style.top=this.pos+"px"
window[this.timer]=setTimeout(function(){csobj.scrollR()},100)}}
