///Scrolling/Sliding/Whatevering layer BETA1 copyright 2007 GizmoBill


var isIE = (navigator.appName.indexOf('Microsoft Internet Explorer') != -1)? true : false;

function slidingLayer(c_,co_){
	var args = slidingLayer.arguments;
	this.enableHelp = typeof args[3]!='undefined' && args[3] != null ? true : false;
	this.dir = typeof args[2]!='undefined' && args[2] != null ? args[2] : -2;

	this.updateProps = function(var_,prop){
		this[var_][prop] =  parseInt(isIE?this[var_].currentStyle[prop]:document.defaultView.getComputedStyle(this[var_], '').getPropertyValue(prop));
	}
	
	this.container = c_;
	this.content = co_;
	this.content.style.position = 'relative';
	
	this.updateProps('container','width');
	this.updateProps('content','width');
	if(this.content.width<this.container.width)
		return;
	this.updateProps('container','left'); 
	this.updateProps('content','left');	
	this.content.initLeft = this.content.left;

	
	this.slide = function(){
		this.updateProps('content','left'); 
		if(Math.abs(this.content.left+this.dir)>Math.abs(this.container.width-this.content.width)){
			this.content.style.left = parseInt(this.container.width-this.content.width)+'px';
			return;
		}
		if(this.content.left+this.dir>this.content.initLeft){
			this.content.style.left = parseInt(this.content.initLeft)+'px';
			return;
		}
		this.content.style.left = parseInt(this.content.left+this.dir)+'px';
		var thisObj = this;
		this.slideTo = setTimeout(function(){thisObj.slide()},0);
	}	
	
	this.fadeCtrls = function(dir){
		if(this.fadeCtrls.arguments.length>1 && this.fadeCtrls.arguments[1]!=false)
			this.endFadeHide = true;
		clearTimeout(this.fadeTo);
		if(isIE){
			this.filters[0].opacity += dir; 
			if(this.filters[0].opacity>=100){ this.filters[0].opacity=100; return;}
			if(this.filters[0].opacity<=0){ this.filters[0].opacity=0;
											if(this.endFadeHide==true) this.parentNode.removeChild(this);
											return;
										}
		}else{
			this.style.opacity = parseFloat(this.style.opacity)+parseFloat(dir/100);
			if(this.style.opacity>=1){ this.style.opacity=1; return;}
			if(this.style.opacity<=0){ 	this.style.opacity=0;
										if(this.endFadeHide==true) this.parentNode.removeChild(this);
										return;
									}
		}
		
		var thisObj = this;
		this.fadeTo = setTimeout(function(){thisObj.fadeCtrls(dir)},0);
	}	

	var ctrls = document.createElement('DIV');
	var ctrlLeft = document.createElement('DIV');
	var ctrlRight = document.createElement('DIV');

	ctrls.className = 'sliderCtrl';
	if(isIE)
		ctrls.style.zIndex = 99;
	ctrlLeft.setAttribute("style","float:left");
	ctrlLeft.style.styleFloat = "left";
	ctrlRight.setAttribute("style","float:right");
	ctrlRight.style.styleFloat = "right";

	var _a = document.createElement('A');
	var _b = document.createElement('A');
	_a.innerHTML = '&nbsp;&raquo;&nbsp;';
	_b.innerHTML = '&nbsp;&laquo;&nbsp;';
	_a.href = 'javascript:void(0)';
	_b.href = _a.href;
	ctrlRight.appendChild(_a);
	ctrlLeft.appendChild(_b);


	var thisObj = this;
	ctrlLeft.onclick = function(){ thisObj.dir -= 2 };
	ctrlLeft.fadeCtrls = this.fadeCtrls;
	ctrlLeft.onmouseover = function(){ 	this.fadeCtrls(15);	thisObj.dir=-2;	thisObj.slide()	};
	ctrlLeft.onmouseout = function(){ 	this.fadeCtrls(-15); clearTimeout(thisObj.slideTo)	};
	ctrlRight.onclick = function(){ thisObj.dir += 2 };
	ctrlRight.fadeCtrls = this.fadeCtrls;
	ctrlRight.onmouseover = function(){ this.fadeCtrls(15);thisObj.dir=2; thisObj.slide() };
	ctrlRight.onmouseout = function(){ this.fadeCtrls(-15); clearTimeout(thisObj.slideTo) };

	this.ctrls = ctrls;
	this.ctrlLeft = ctrlLeft;
	this.ctrlRight = ctrlRight;

	this.ctrlRight.style.opacity =!isIE?document.defaultView.getComputedStyle(this.ctrlRight, '').getPropertyValue("opacity"):null;
	this.ctrlLeft.style.opacity = !isIE?document.defaultView.getComputedStyle(this.ctrlLeft, '').getPropertyValue("opacity"):null;
	
	ctrls.appendChild(ctrlLeft);
	ctrls.appendChild(ctrlRight);
	
	
	this.container.insertBefore(this.ctrls,this.content);
	this.ctrlRight.fadeCtrls(-1);
	this.ctrlLeft.fadeCtrls(-1);

	if(this.enableHelp){
		var help_ = document.createElement('DIV');
		var helpCtrl_ = document.createElement('DIV');
		help_.id = 'sliderCtrl_help';
		helpCtrl_.id = 'sliderCtrl_helpCtrl';
		help_.setAttribute("style","float:left");
		help_.style.styleFloat = "left";
		help_.innerHTML = '? Hover mouse over the left/right-bottom sides. Click arrows to increase speed.';
		helpCtrl_.innerHTML = '?';
		help_.fadeCtrls = this.fadeCtrls;
		helpCtrl_.onmouseover = function(){ thisObj.ctrls.appendChild(thisObj.help_); thisObj.help_.fadeCtrls(15); };
		helpCtrl_.onmouseout = function(){ 	thisObj.help_.fadeCtrls(-15,true); };
		this.help_ = help_;
		this.helpCtrl_ = helpCtrl_;
		this.help_.style.opacity = !isIE?document.defaultView.getComputedStyle(this.help_, '').getPropertyValue("opacity"):null;
		ctrls.appendChild(helpCtrl_);
		ctrls.appendChild(help_);
		this.help_.fadeCtrls(-1,true);
	}
}

//USE: 	var slidingL = new slidingLayer(Node:DIV (container), Node:DIV (content), [int<0 (speed)], [mixed (enables help display)])

