//<?

function hytScrollingDiv($uId,$D,$S,$sIn){
	var $this,$ID,$eContainer,$eContent,$aDirections,$sActiveDirection,$nWidth,$nScrollWidth,$nDsiplace,$nTimeing,$sIndex;
	$this = $ID = $eContainer = $eContent										= null;
	$aDirections																= ['u','r','d','l'];
	$sActiveDirection															= '';
	$nWidth																		= 0;
	$nScrollWidth																= 0;
	$nDsiplace																	= $D || 1;
	$nTimeing																	= $S || 10;
	$sIndex																		= $sIn || false;
/** FUNCTION
init: Inicia el objeto hytScrollingDiv.
	Input:
	$uId = Id del objeto DIV al que se le aplicará scroll, o referencia del mismo;
**/
	this.Init = function($uId){
		var $sContent,$sTextBox,$nHolWid;
		$ID																		= this.hash();
		$this																	= "$"+$ID;
		eval($this+"= this");
		
		$eContainer																= (typeof($uId)=="object") ? $uId : document.getElementById($uId);
		$eContainer.style.position												= 'relative';
		
		if($sIndex){
			$sContent															= $eContainer.innerHTML;
			$oFill																= $eContainer.getElementsByTagName($sIndex);
			$nHolWid															= parseInt($oFill[0].offsetWidth)*($oFill.length)+"px";
		}else{
			$sContent															= $eContainer.innerHTML;
			$nHolWid															= "";
		}
		
		$eContainer.innerHTML													= "";
		$sTextBox																= this.hash()+"_";		
		$eContent																= document.createElement('div');
		$eContent.style.width													= $nHolWid;
		$eContent.setAttribute('id', $sTextBox);
		
		$eContainer.appendChild($eContent);
		$eContent.style.top														= '0px';
		$eContent.style.left													= '0px';
		$eContent.style.position												= 'relative';
		
		$eContent.innerHTML														= $sContent;
		
		$nWidth																	= parseInt($eContainer.offsetWidth);
		$nScrollWidth															= parseInt($eContainer.scrollWidth);
	}
/** FUNCTION END **/
/** FUNCTION
	down: Inicia el desplazamiento de los contenidos hacia arriba.
**/
	this.down = function(){
		var $nBottomLimit														= parseInt($eContent.style.top) + parseInt($eContent.offsetHeight);
		if($nBottomLimit>parseInt($eContent.parentNode.offsetHeight)){
			var $nPos															= parseInt($eContent.style.top) - $nDsiplace;
			$eContent.style.top													= $nPos +'px';
			$sActiveDirection													= 'd';
			$aDirections['d']													= setTimeout($this+".down()", $nTimeing);
		}
	}
/** FUNCTION END **/
/** FUNCTION
	up: Inicia el desplazamiento de los contenidos hacia abajo.
**/
	this.up = function(){
		if(parseInt($eContent.style.top)<0){
			var $nPos															= parseInt($eContent.style.top) + $nDsiplace;
			$eContent.style.top													= $nPos +'px';
			$sActiveDirection													= 'u';
			$aDirections['u']													= setTimeout($this+".up()", $nTimeing);
		}
	}
/** FUNCTION END **/
/** FUNCTION
	left: Inicia el desplazamiento de los contenidos hacia la derecha.
**/
	this.left = function(){
		if(parseInt($eContent.style.left)<0){
			var $nPos															= parseInt($eContent.style.left) + $nDsiplace;
			$eContent.style.left												= $nPos +'px';
			$sActiveDirection													= 'l';
			$aDirections['l']													= setTimeout($this+".left()", $nTimeing);
		}
	}
/** FUNCTION END **/
/** FUNCTION
	right: Inicia el desplazamiento de los contenidos hacia la izquierda.
**/	
	this.right = function(){
		var $nLeftLimit															= $nScrollWidth + parseInt($eContent.style.left);
		if($nLeftLimit>$nWidth){
			var $nPos															= parseInt($eContent.style.left) - $nDsiplace;
			$eContent.style.left												= $nPos +'px';
			$sActiveDirection													= 'r';
			$aDirections['r']													= setTimeout($this+".right()", $nTimeing);
		}
	}
/** FUNCTION END **/
/** FUNCTION
	stop: Detiene el desplazamiento de los contenidos.
**/
	this.stop = function(){
		clearTimeout($aDirections[$sActiveDirection]);
	}
/** FUNCTION END **/
/** FUNCTION
	hash: Genera un HASH unico.
**/
	this.hash = function(){
		var $eNow																= new Date();
		return '_'+$eNow.getTime();
	}
/** FUNCTION END **/
// constructor
	this.Init($uId);
}
