/**
 * @author 
 */


var _arrScrollContainers = new Array();
var _arrClipStructures = new Array();
var _iCurrentLayer = null;
var clipWidth = 350;

function ClipStructure(){
	this.clipTop = 0;
	this.clipWidth = clipWidth;
	this.defalut_clipBottom = clipWidth;
	this.clipBottom = 320;
	this.topper = 10;
	this.lyrheight = 0;
	this.time,this.amount,this.theTime,this.theHeight,this.DHTML;
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

function InitScrollable(){
	InitScrollable2();
}

function InitScrollable2(){
	
	var _ClipStructure = null;
	
	try{
		var _ContentElememt = document.getElementById('l_content');
		var _arrDivElements = _ContentElememt.getElementsByTagName('div');
		if (_arrDivElements.length > 1){
			for (i=0; i<_arrDivElements.length; i++){
				if(_arrDivElements[i].id == 'divContent_scrollable'){
					_arrScrollContainers.push(_arrDivElements[i]);
					_arrClipStructures.push(new ClipStructure());
				}
			}
		}
	}catch(e){}
	
	try{
		var _ContentElememt = document.getElementById('m_content');
		var _arrDivElements = _ContentElememt.getElementsByTagName('div');
		if (_arrDivElements.length > 1){
			for (i=0; i<_arrDivElements.length; i++){
				if(_arrDivElements[i].id == 'divContent_scrollable'){
					_arrScrollContainers.push(_arrDivElements[i]);
					_arrClipStructures.push(new ClipStructure());
				}
			}
		}
	}catch(e){}
	
	try{
		_ContentElememt = document.getElementById('r_content');
		_arrDivElements = _ContentElememt.getElementsByTagName('div');
		if (_arrDivElements.length > 1){
			for (i=0; i<_arrDivElements.length; i++){
				if(_arrDivElements[i].id == 'divContent_scrollable'){
					_arrScrollContainers.push(_arrDivElements[i]);
					_arrClipStructures.push(new ClipStructure());
				}
			}
		}
	}catch(e){}
	
	try{
		for (scCounter=0; scCounter<_arrScrollContainers.length; scCounter++){
			var _oScrollableContainer =	_arrScrollContainers[scCounter];
			_oScrollableContainer.id = 'divContent_scrollable_'+(scCounter+1);
			var _arrElements = _oScrollableContainer.getElementsByTagName('div');
			
			for (j=0; j<_arrElements.length; j++){
				if (_arrElements[j].id == 'divUpControl'){
					var _oUpControlContainer = _arrElements[j];
					_oUpControlContainer.innerHTML = '<img src="fileadmin/templates/main/images/layout/l_arrow_top.png" onmousedown="scrollayer(\'divContent_scrollable_body_'+(scCounter+1)+'\',-10,100)" onmouseup="stopScroll()" onmouseout="stopScroll()" alt="" />';
				}
				if (_arrElements[j].id == 'divDownControl'){
					var _oDownControlContainer = _arrElements[j];
					_oDownControlContainer.innerHTML = '<img src="fileadmin/templates/main/images/layout/l_arrow_bottom.png" onmousedown="scrollayer(\'divContent_scrollable_body_'+(scCounter+1)+'\',10,100)" onmouseup="stopScroll()" onmouseout="stopScroll()" alt="" />';
				}
				if (_arrElements[j].id == 'divTopImage'){
					if (_arrElements[j].getElementsByTagName('img').length > 0){
						_ClipStructure = _arrClipStructures[scCounter];
						_ClipStructure.clipBottom = _ClipStructure.defalut_clipBottom - new Number(_arrElements[j].getElementsByTagName('img')[0].height);
						_arrClipStructures[scCounter] = _ClipStructure;
					}
				}
				if (_arrElements[j].id == 'divContent_scrollable_container'){						
					var _oScrollableBody = _arrElements[j].getElementsByTagName('div')[0];
					_oScrollableBody.id = 'divContent_scrollable_body_'+(scCounter+1);
					init(_oScrollableBody.id, scCounter);
				}
			}
		}	
	}catch(e){
		alert(e);
	}
}

function init(pScrollBody, pIndex)
{	
	DHTML = (document.getElementById || document.all || document.layers)
	if (!DHTML) return;
	var x = new getObj(pScrollBody);
	if (document.layers)
	{
		lyrheight = x.style.clip.bottom;
		lyrheight += 20;
		
		x.style.clip.top = _arrClipStructures[pIndex].clipTop;
		x.style.clip.left = 0;
		x.style.clip.right = _arrClipStructures[pIndex].clipWidth;
		x.style.clip.bottom = _arrClipStructures[pIndex].clipBottom;

	} else if (document.getElementById || document.all) {
		lyrheight = x.obj.offsetHeight;
		//alert(_arrClipStructures[pIndex].clipBottom);
		if (lyrheight > _arrClipStructures[pIndex].clipBottom){
			var _arrElements = _arrScrollContainers[pIndex].getElementsByTagName('div');
			for (j=0; j<_arrElements.length; j++){
				if (_arrElements[j].id == 'divUpControl'){
					var _oUpImage = _arrElements[j].style.visibility = 'visible';							
				}
				if (_arrElements[j].id == 'divDownControl'){
					var _oDownImage = _arrElements[j].style.visibility = 'visible';							
				}
			}
		}
		x.style.clip = 'rect('+_arrClipStructures[pIndex].clipTop+'px,'+_arrClipStructures[pIndex].clipWidth+'px,'+_arrClipStructures[pIndex].clipBottom+'px,0)';
	}
}

function scrollayer(layername,amt,tim)
{
	if (!DHTML) return;
	thelayer = new getObj(layername);
	if (!thelayer) return;
	
	try{
		_iCurrentLayer = new Number(layername.split("_")[3]);
		_iCurrentLayer--;

	}catch(e){
		_iCurrentLayer = 0;
	}
	
	//set the current clip structure values
	_arrClipStructures[_iCurrentLayer].amount = amt;
	_arrClipStructures[_iCurrentLayer].theTime = tim;
	realscroll();
}

function realscroll()
{
	if (!DHTML) return;
	_arrClipStructures[_iCurrentLayer].clipTop += _arrClipStructures[_iCurrentLayer].amount;
	_arrClipStructures[_iCurrentLayer].clipBottom += _arrClipStructures[_iCurrentLayer].amount;
	_arrClipStructures[_iCurrentLayer].topper -= _arrClipStructures[_iCurrentLayer].amount;
	if (_arrClipStructures[_iCurrentLayer].clipTop < 0 || _arrClipStructures[_iCurrentLayer].clipBottom > lyrheight)
	{
		_arrClipStructures[_iCurrentLayer].clipTop -= _arrClipStructures[_iCurrentLayer].amount;
		_arrClipStructures[_iCurrentLayer].clipBottom -= _arrClipStructures[_iCurrentLayer].amount;
		_arrClipStructures[_iCurrentLayer].topper += _arrClipStructures[_iCurrentLayer].amount;
		return;
	}
	if (document.getElementById || document.all)
	{
		clipstring = 'rect('+_arrClipStructures[_iCurrentLayer].clipTop+'px,'+_arrClipStructures[_iCurrentLayer].clipWidth+'px,'+_arrClipStructures[_iCurrentLayer].clipBottom+'px,0)';
		thelayer.style.clip = clipstring;
		thelayer.style.top = _arrClipStructures[_iCurrentLayer].topper + 'px';
	}
	else if (document.layers)
	{
		thelayer.style.clip.top = _arrClipStructures[_iCurrentLayer].clipTop;
		thelayer.style.clip.bottom = _arrClipStructures[_iCurrentLayer].clipBottom;
		thelayer.style.top = _arrClipStructures[_iCurrentLayer].topper;
	}
	_arrClipStructures[_iCurrentLayer].time = setTimeout('realscroll()',_arrClipStructures[_iCurrentLayer].theTime);
}

function stopScroll()
{
	if (_iCurrentLayer != null)
		if (_arrClipStructures[_iCurrentLayer].time) clearTimeout(_arrClipStructures[_iCurrentLayer].time);
}