
if('undefined'===typeof Alo_Objects){var Alo_Objects=[];}
function Alo_Scroller(container,config)
{this.id=Alo_Objects.length;var self=Alo_Objects[this.id]=this;this.ref="Alo_Objects["+this.id+"]";if("string"===typeof container){this.e=document.getElementById(container);}else{this.e=container;}
var defaults={"orientation":"vertical","textAlign":"","verticalAlign":"","showButtons":true,"interval":5000,"debug":false};if(!config)config={};for(var i in defaults){if(!config[i]){config[i]=defaults[i];}}
config.horizontal=("horizontal"===config.orientation.toLowerCase());if(config.verticalAlign===""&&this.e.style.verticalAlign){config.verticalAlign=this.e.style.verticalAlign;}
this.config=config;this.tb=null;this.children=[];this.cx=this.cy=this.index=this.scrollTimerId=this.timerId=0;this.e.style.display="block";var child=this.e.firstChild;while(child){var nextSibling=child.nextSibling;if(1===child.nodeType){this.children[this.children.length]=child;child._cy=child.scrollHeight;child._cx=child.scrollWidth;if((0===this.cx)||(child._cx>this.cx)){this.cx=child._cx;}
if((0===this.cy)||(child._cy>this.cy)){this.cy=child._cy;}}
child.parentNode.removeChild(child);child=nextSibling;}
if(this.config.showButtons){this.tb=this.initButtons();this.tb.style.textAlign="right";this.e.appendChild(this.tb);}
this.status=document.createElement("div");this.e.appendChild(this.status);this.viewport=this.e.appendChild(document.createElement("div"));this.count=this.children.length;this.viewport.style.width=this.cx+"px";this.viewport.style.height=this.cy+"px";this.viewport.style.overflow="hidden";if(this.config.debug)this.viewport.style.border="1px solid";var table=this.viewport.appendChild(document.createElement("table"));table.cellSpacing=table.cellPadding=0;var tbody=table.appendChild(document.createElement("tbody"));if(this.config.horizontal){var tr=tbody.appendChild(document.createElement("tr"));}
for(var i=0;i<this.children.length;i++){var child=this.children[i];if(!this.config.horizontal){var tr=tbody.appendChild(document.createElement("tr"));}
var td=tr.appendChild(document.createElement("td"));td.style.verticalAlign="top";var div=td.appendChild(document.createElement("div"))
div.style.overflow="hidden";div.style.width=this.cx+"px";div.style.height=this.cy+"px";if(this.config.debug)div.style.backgroundColor=i&1?"#ffd":"#dff";var div2=div.appendChild(document.createElement("div"));div2.appendChild(child);if(this.config.debug&&(i<5)){this.showStatus(i
+" "+child.offsetLeft+","+child.offsetTop
+" "+div2.offsetLeft+","+div2.offsetTop+" "+div2.offsetWidth+"x"+div2.offsetHeight
+" "+child._cx+"x"+child._cy);}
var y=0;switch(this.config.verticalAlign.toLowerCase()){case"top":y=0;break;case"bottom":y=this.cy-child._cy;break;default:y=parseInt((this.cy-child._cy)/2);break;}
div2.style.marginTop=-div2.offsetTop+y+"px";div2.style.marginLeft=-div2.offsetLeft+"px";}
this.setState(true);addLoadEvent(function(){if(self.config.horizontal){self.index=parseInt((self.viewport.scrollLeft+self.cx-1)/self.cx);}else{self.index=parseInt((self.viewport.scrollTop+self.cy+-1)/self.cy);}
self.restartTimer();});}
Alo_Scroller.prototype.showStatus=function(html)
{this.status.innerHTML="<div>"+html+"</div>"+this.status.innerHTML;}
Alo_Scroller.prototype.setState=function(state)
{if(this.tb){this.tb.buttons.play.style.display=state?"none":"";this.tb.buttons.pause.style.display=state?"":"none";}}
Alo_Scroller.prototype.play=function(){this.setState(true);this.timer();}
Alo_Scroller.prototype.pause=function(){if(this.timerId){window.clearTimeout(this.timerId);this.timerId=0;}
this.setState(false);}
Alo_Scroller.prototype.timer=function(){this.timerId=0;this.next();this.restartTimer();}
Alo_Scroller.prototype.stopTimer=function()
{if(this.timerId){window.clearTimeout(this.timerId);this.timerId=0;}}
Alo_Scroller.prototype.restartTimer=function(stop)
{this.stopTimer();this.timerId=window.setTimeout(this.ref+".timer()",this.config.interval);}
Alo_Scroller.prototype.show=function(index)
{if(index<0)index=this.count-1;if(index>=this.count)index=0;if((index<0)||(index>=this.count))return false;this.index=index;if(this.config.horizontal){this.scrollTarget=index*this.cx;}else{this.scrollTarget=index*this.cy;}
if(0===this.scrollTimerId){this.scrollTimerId=window.setTimeout(this.ref+".scrollTimer()",100);}
if(this.timerId){this.restartTimer();}
return true;}
Alo_Scroller.prototype.scrollTimer=function()
{this.scrollTimerId=0;var value=this.config.horizontal?this.viewport.scrollLeft:this.viewport.scrollTop;var delta=this.scrollTarget-value;if(Math.abs(delta)>1){value+=parseInt(delta/2);}else{value=this.scrollTarget;}
if(this.config.horizontal){this.viewport.scrollLeft=value;}else{this.viewport.scrollTop=value;}
if(value!==this.scrollTarget){this.scrollTimerId=window.setTimeout(this.ref+".scrollTimer()",100);}}
Alo_Scroller.prototype.next=function(){return this.show(this.index+1);}
Alo_Scroller.prototype.prev=function(){return this.show(this.index-1);}
Alo_Scroller.prototype.initButtons=function()
{var self=this;var buttonInfo={"down":{"x":0,"cx":23,"title":"siguiente"},"up":{"x":-23,"cx":23,"title":"anterior"},"prev":{"x":-46,"cx":23,"title":"anterior"},"next":{"x":-69,"cx":23,"title":"siguiente"},"play":{"x":-92,"cx":27,"title":"cambiar automáticamente"},"pause":{"x":-119,"cx":27,"title":"pausar"},"stop":{"x":-146,"cx":27,"title":"detener"}};var buttons=this.config.horizontal?["prev","play","pause","next"]:["up","play","pause","down"];var tb=document.createElement("div");tb.className='ScrollerButtons';tb.buttons={};var tmp=document.createElement("div");for(var i in buttons){var action=buttons[i];var b=buttonInfo[action];tmp.innerHTML='<img src="/common/spacer.gif" alt="'+b.title+'" title="'+b.title+'" style="background:url(\'/common/ScrollerButtons.gif\')" height="18" width="'+b.cx+'">';var img=tb.appendChild(tmp.firstChild);tb.buttons[action]=img;img._x=b.x+"px";img._y=img._hover=img._enabled=img._pressed=null;img._enabled=true;img._action=action;img.onclick=function(){if(!this._enabled)return false;switch(this._action){case"play":self.play();break;case"pause":self.pause();break;case"up":case"prev":self.pause();self.prev();break;case"down":case"next":self.pause();self.next();break;}}
img.paint=function(){var y="0px";if(!this._enabled){y="-56px";}else if(this._pressed){y="-36px";}else if(this._hover){y="-18px";}
if(this._y!==y){this.style.backgroundPosition=this._x+" "+(this._y=y);this.style.cursor=this._enabled?"pointer":"";}}
img.setEnabled=function(enabled){this.paint(this._enabled=Boolean(enabled));}
img.onmousedown=function(){this.paint(this._pressed=true);}
img.onmouseup=function(){this.paint(this._pressed=false);}
img.onmouseover=function(){this.paint(this._hover=true);}
img.onmouseout=function(){this.paint(this._hover=false);}
img.paint();}
return tb;}
