/*************************************************************** 
 * Application Name: DM FileManager									
 * Application URI: http://www.dutchmonkey.com/
 * Description: AJAX Web Based File Management System.
 * Author: Frank D. Strack
 * Author Email: frank@dutchmonkey.com
 * Author URI: http://www.dutchmokney.com
 ***************************************************************/


// Legacy variables - the browser object should be used for this, not these globals.
var b = new Browser();

var ns40 = b.ns40;
var ns50 = b.ns50;
var ie50 = b.ie50;
var Exploiter = b.Exploiter;

var screenWidth;
var screenHeight;
var pageScrolledX;
var pageScrolledY;
		
function setUpGlobalParameters()
{
	var oBrowser = new Browser();

	//function is working
	if(oBrowser.ns40)
	{
		screenWidth = window.innerWidth - 16;
		screenHeight = window.innerHeight - 16;
		pageScrolledX = 'window.pageXOffset';
		pageScrolledY = 'window.pageYOffset';
	}

	if(oBrowser.ns50)
	{
		screenWidth = window.innerWidth - 20;
		screenHeight = window.innerHeight - 20;
		
		pageScrolledX = 'document.body.scrollLeft';
		pageScrolledY = 'document.body.scrollTop';
	}
	
	if(oBrowser.Exploiter)
	{
		if(document.body.scrollWidth)	screenWidth = document.body.scrollWidth;
		else							screenWidth = document.body.offsetWidth - 18;
		
		screenHeight = document.body.offsetHeight - 18;
		
		pageScrolledX = 'document.body.scrollLeft';
		pageScrolledY = 'document.body.scrollTop';
	}
	
	return true;
}

function buildLayerObject(layerName,objectName,nested,parentLayer)
{
	return LayerObject(layerName,objectName,nested,parentLayer);
}

function LayerObject(layerName,objectName,nested,parentLayer)
{
	var oBrowser = new Browser();
	
	if(oBrowser.ns40)
	{
		if(!nested)
		{
			this.dom = eval('document.' + layerName);
			this.css = eval('document.' + layerName + '.document');
			this.images = 'document.' + layerName + '.document';
			this.forms = eval('document.' + layerName + '.document');
			this.width = eval('document.' + layerName + '.document').width;
			this.length = eval('document.' + layerName + '.document').height;
			this.dom.xpos = eval('document.' + layerName).left;
			this.dom.ypos = eval('document.' + layerName).top;
		}
		
		if(nested)
		{
			this.dom = eval('document.' + parentLayer + '.document.' + layerName);
			this.css = eval('document.' + parentLayer + '.document.' + layerName + '.document');
			this.images = 'document.' + layerName + '.document';
			this.forms = eval('document.' + parentLayer + '.document.' + layerName + '.document');
			this.width = eval('document.' + parentLayer + '.document.' + layerName + '.document').width;
			this.length = eval('document.' + parentLayer + '.document.' + layerName + '.document').height;
			this.dom.xpos = eval('document.' + parentLayer + '.document.' + layerName).left;
			this.dom.ypos = eval('document.' + parentLayer + '.document.' + layerName).top;
		}
	}

	if(oBrowser.ns50)
	{
		this.css = eval('document.getElementById(\'' + layerName + '\')');
		this.dom = eval('document.getElementById(\'' + layerName + '\').style');
		this.images = 'document';
		this.forms = document;
		this.width = this.css.offsetWidth;
		this.length = this.css.offsetHeight;
		this.dom.xpos = this.css.offsetLeft;
		this.dom.ypos = this.css.offsetTop;
	}
	
	if(oBrowser.Exploiter)
	{
		this.dom = eval(layerName).style;
		this.css = eval(layerName);
		this.images = 'document';
		this.forms = document;
		this.width = eval(layerName).offsetWidth;
		this.length = eval(layerName).offsetHeight;
		this.dom.xpos = eval(layerName).offsetLeft;
		this.dom.ypos = eval(layerName).offsetTop;
	}
	
	// properies
	this.height = this.length;
	this.getName = objectName;
	this.slidingLeft = false;
	this.slidingRight = false;
	this.slidingUp = false;
	this.slidingDown = false;
	this.slideIncrement = 1;
	this.slide = true;
	this.drag = false;
	this.mouseBufferX = 0;
	this.mouseBufferY = 0;
	this.align = "left";
	this.size = "10px";
	this.font = "verdana,tahoma,arial";
	this.color = "#000000";
	this.weight = "normal";
	
	// methods	
	this.show = _showLayer;
	this.hide = _hideLayer;
	this.moveTo = _moveLayer;
	this.slideLeftTo = _slideLayerLeft;
	this.slideRightTo = _slideLayerRight;
	this.slideUpTo = _slideLayerUp;
	this.slideDownTo = _slideLayerDown;
	this.clipTo = _clipLayerTo;
	this.img_over = _layerImg_Over;
	this.img_out = _layerImg_Out;
	this.img_swap = _layerImg_Swap;
	this.writeText = _layerWriteText;
	
	//events
	this.onSlideStop = null;  //This must be the string containg the full function name, i.e. "FunctionName()"
	
	return true;
}

function _showLayer()
{
	this.dom.visibility = "visible";
	return true;
}

function _hideLayer()
{
	this.dom.visibility = "hidden";
	return true;
}

function _moveLayer(newX,newY)
{
	this.dom.xpos = newX;
	this.dom.ypos = newY;
	this.dom.left = this.dom.xpos;
	this.dom.top = this.dom.ypos;
	
	return true;
}

function _slideLayerLeft(newX)
{
	var tempX = this.dom.xpos;
	var tempY = this.dom.ypos;
	var layerName = this.getName;
	
	if((tempX > newX) && this.slide && !this.slidingRight)
	{
		this.slidingLeft = true;
		
		tempX -= this.slideIncrement;
		
		if(tempX < newX) tempX = newX;
		
		this.moveTo(tempX,tempY);
		
		setTimeout("eval("+layerName+".slideLeftTo("+newX+"));",5);
	}
	
	else
	{	
		this.moveTo(newX,tempY);
		this.slidingLeft = false;
		
		if(this.onSlideStop != "")		eval(this.onSlideStop);
		
		return true;
	}
}

function _slideLayerRight(newX)
{
	var tempX = this.dom.xpos;
	var tempY = this.dom.ypos;
	var layerName = this.getName;

	if((tempX < newX - 5) && this.slide && !this.slidingLeft)
	{
		this.slidingRight = true;
		
		tempX += this.slideIncrement;
		
		if(tempX > newX) tempX = newX;
		
		this.moveTo(tempX,tempY);
		
		setTimeout("eval("+layerName+".slideRightTo("+newX+"));",5);
	}
	
	else
	{
		this.moveTo(newX,tempY);
		this.slidingRight = false;
		
		if(this.onSlideStop != "")		eval(this.onSlideStop);
		
		return true;
	}
}

function _slideLayerUp(newY)
{
	var tempX = this.dom.xpos;
	var tempY = this.dom.ypos;
	var layerName = this.getName;

	if((tempY > newY) && this.slide && !this.slidingDown)
	{
		this.slidingUp = true;
		
		tempY -= this.slideIncrement;
		
		if(tempY < newY) tempY = newY;
		
		this.moveTo(tempX,tempY);
		
		setTimeout("eval("+layerName+".slideUpTo("+newY+"));",5);
	}
	
	else
	{
		this.moveTo(tempX,newY);
		this.slidingUp = false;
		
		if(this.onSlideStop != "")		eval(this.onSlideStop);
		
		return true;
	}
}

function _slideLayerDown(newY)
{
	var tempX = this.dom.xpos;
	var tempY = this.dom.ypos;
	var layerName = this.getName;

	if((tempY < newY) && this.slide && !this.slidingUp)
	{
		this.slidingDown = true;
		
		tempY += this.slideIncrement;
		
		if(tempY > newY) tempY = newY;
		
		this.moveTo(tempX,tempY);
		
		setTimeout("eval("+layerName+".slideDownTo("+newY+"));",5);
	}

	else
	{
		this.moveTo(tempX,newY);
		this.slidingDown = false;
		
		if(this.onSlideStop != "")		eval(this.onSlideStop);
		
		return true;
	}
}

function _clipLayerTo(clipLeft,clipTop,clipRight,clipBottom)
{
	var oBrowser = new Browser();

	var tempX = this.dom.xpos;
	var tempY = this.dom.ypos;
			
	if(oBrowser.ns40)
	{
		this.dom.clip.top = clipTop;
		this.dom.clip.right = clipRight;
		this.dom.clip.bottom = clipBottom;
		this.dom.clip.left = clipLeft;
	}

	else if(oBrowser.Exploiter || oBrowser.ns50)
		this.dom.clip = "rect("+clipTop+"px "+clipRight+"px "+clipBottom+"px "+clipLeft+"px)";

	return true;	
}

function _layerImg_Over(imgName)
{
	eval(this.images+'.'+imgName).src = eval(imgName+'_over').src;

	return true;
}

function _layerImg_Out(imgName)
{
	eval(this.images+'.'+imgName).src = eval(imgName+'_out').src;
	
	return true;
}

function _layerImg_Swap(imgName,imgSrc)
{
	eval(this.images+'.'+imgName).src = imgSrc;
	
	return true;
}

function _layerWriteText(strText)
{	
	var oBrowser = new Browser();

	if(oBrowser.explorer || oBrowser.netscape)
	{
		this.css.innerHTML = "<div style=\"text-align:"+this.align+"; font-size:"+this.size+"px; font-family:"+this.font+"; color:"+this.color+"; font-weight:"+this.weight+"\">"+strText+"</div>";
		return;
	}
	
	if(oBrowser.ns40)
	{	
		this.css.open();		
		this.css.write("<div style=\"text-align:"+this.align+"; font-size:"+this.size+"; font-family:"+this.font+"; color:"+this.color+"; font-weight:"+this.weight+"\">"+strText+"</div>");
		this.css.close();		
	}
	
	else if(oBrowser.ns50 || oBrowser.ie50)
	{	
		this.dom.fontFamily=this.font;
		this.dom.fontSize=this.size;
		this.dom.color=this.color;
		this.dom.textAlign=this.align;
		this.dom.fontWeight = this.weight;
		
		this.css.replaceChild(document.createTextNode(strText),this.css.childNodes[0])
	}
	
	else if(oBrowser.Exploiter)
	{
		this.css.innerHTML = "<div style=\"text-align:"+this.align+"; font-size:"+this.size+"px; font-family:"+this.font+"; color:"+this.color+"; font-weight:"+this.weight+"\">"+strText+"</div>";
	}
	
	return true;
}
