
/**
 *	class cDiv
 *
 *	Cross-Browser div functionality. Some stuff derived from dynLayer
 *
 *	@requires: basic.js
 */
function cDiv( id, nestref, frame ){
	this.id		= id;
	this.timer	= null;
	// this.frame	= frame || self;
	this.frame	= ( window.location.href != top.location.href ); // window;
	this.isvis	= false;	
	
	if( !cDiv.initialized && !frame) cDivIni();
		
	cDivNamesArray[ cDivNamesArray.length ] = id;
	
	if( ns4 ) {
		if( !frame ) {
			// if( !nestref ) var nestref = cDiv.nestRefArray[id];
			this.css = ( nestref ) ? eval("document."+nestref+".document."+id) : document.layers[id];
		} else {
			this.css = ( nestref ) ? eval("frame.document."+nestref+".document."+id) : frame.document.layers[id];
		}		
		this.elm		= this.css;
		this.doc		= this.css.document;
		this.posX		= this.css.left;
		this.posY		= this.css.top;
		this.w			= this.css.clip.width;
		this.h			= this.css.clip.height;
		this.bgColor	= this.css.bgColor;
	} else if( ie ) {
		// this.elm = this.event = this.frame.document.all[id]		
		this.elm		= document.all[id];
		this.css		= document.all[id].style;
		this.doc		= document;
		this.posX		= this.elm.offsetLeft;
		this.posY		= this.elm.offsetTop;
		this.w			= ( ie4 ) ? this.css.pixelWidth : this.elm.offsetWidth;
		this.h			= ( ie4 ) ? this.css.pixelHeight : this.elm.offsetHeight;
		this.bgColor	= this.css.backgroundColor;
	} else if( dom ) {
		this.elm		= document.getElementById(id);
		this.css		= this.elm.style;
		this.doc		= document;
		if (document.defaultView && document.defaultView.getComputedStyle) {
			// DOM Compliant browsers
			this.posX	= parseInt( document.defaultView.getComputedStyle(this.elm, null).getPropertyValue('left') );
			this.posY	= parseInt( document.defaultView.getComputedStyle(this.elm, null).getPropertyValue('top') );
			this.w			= parseInt( document.defaultView.getComputedStyle(this.elm, null).getPropertyValue('width') );
			this.h			= parseInt( document.defaultView.getComputedStyle(this.elm, null).getPropertyValue('height') );
		} else {
			// Safari < 1.3 and Konqueror < ? don't support "getComputedStyle()"
			this.posX	= 0;
			this.posY	= 0;
			this.w			= 0;
			this.h			= 0;
		}
		this.bgColor	= this.css.bgColor;
	}
	this.z			= this.css.zIndex;
	this.name		= id.substr( 0, id.length - 3 );
	this.nestref	= nestref;
	
	if( ( this.css.visibility == "show" ) || ( this.css.visibility == "visible" ) ) this.isvis = 1;
	
	this.obj 	= this.id + "cDiv";
	eval( this.obj + "=this" );
}

// constructor ( getting nestings of the divs )
function cDivIni( nestref ) {
	if( !cDiv.initialized ) cDiv.initialized = true;
	
	if( ns4 ) {
		if( nestref ) ref = eval('document.' + nestref +'.document')
		else nestref = ""; ref = document;
		
		for( var i = 0; i < ref.layers.length; i++ ) {
			var divname = ref.layers[i].name;
			cDiv.nestRefArray[divname] = nestref;
			var index = divname.indexOf("Div");
			if (index > 0) {
				eval( divname.substr( 0, index ) + ' = new cDiv("' +divname+ '","' +nestref+ '")' );
			}
			if (ref.layers[i].document.layers.length > 0) {
				// cDiv.refArray[ cDiv.refArray.length ] = (nestref=='') ? ref.layers[i].name : nestref + '.document.' + ref.layers[i].name;
			}
		}
		
		if ( cDiv.refArray.i < cDiv.refArray.length ) {
			cDivIni( cDiv.refArray[cDiv.refArray.i++] )
		}
	} else if( ie4 ) {
		for (var i = 0; i < document.all.tags("div").length; i++) {
			var divname = document.all.tags("div")[i].id
			var index = divname.indexOf("Div")
			if (index > 0) {
				//var dynName = divname.substr(0,index) // added 02/2000 by goosh
				//eval(dynName+' = new cDiv("' + divname + '")')				
				// eval(dynName+".resizeTo("+dynName+".elm.scrollWidth,"+dynName+".elm.scrollHeight)") // IE4 doesn't display layers in correct width unless resize
			}
		}
	} else if( dom ) {
		for (var i = 0; i < document.getElementsByTagName("div").length; i++) {
			var divname = document.getElementsByTagName("div")[i].id
			var index = divname.indexOf("Div")
			if (index > 0) {
				eval(divname.substr(0,index)+' = new cDiv("'+divname+'")')
			}
		}
	}
	return true
}

cDivNamesArray				= new Array();

// properties

cDiv.nestRefArray			= new Array();
cDiv.refArray				= new Array();
cDiv.refArray.i				= 0;
cDiv.initialized			= false;

// methods

cDiv.prototype.top			= cDivTop;
cDiv.prototype.left			= cDivLeft;
cDiv.prototype.x			= cDivX;
cDiv.prototype.y			= cDivY;
cDiv.prototype.x2			= cDivX2;
cDiv.prototype.y2			= cDivY2;
cDiv.prototype.width		= cDivW;
cDiv.prototype.height		= cDivH;
cDiv.prototype.vis			= cDivVis;
cDiv.prototype.visi			= cDivVisi;
cDiv.prototype.isMouseOver	= cDivIsMouseOver;

// _____________________________________________________________________________________________________________________ >> methods cDiv

function cDivTop( y ) {																							// << _____ cDivTop: get / set top
	if( y != null ) {
		this.posY = y;
		if( ns4 )		this.css.top = this.posY;
		else if( ie )	this.css.pixelTop = this.posY;
		else if( dom )	this.css.top = this.posY + "px";
	} else {
		return this.y;
	}
}

function cDivLeft( x ) {																							// << _____ cDivTop: get / set left
	if( x != null ) {
		this.posX = x;
		if( ns4 )		this.css.left = this.posX;
		else if( ie )	this.css.pixelLeft = this.posX;
		else if( dom )	this.css.left = this.posX + "px";
	} else {
		return this.x;
	}
}

function cDivX( x ) {																							// << _____ cDivTop: get / set left
	if ( x != null ) {
		this.posX = x;
		if ( ns4 )		this.css.left = this.posX;
		else if ( ie )	this.css.pixelLeft = this.posX;
		else if ( dom )	this.css.left = this.posX+ "px";
	} else {
		return this.posX;
	}
}
function cDivY( y ) {																							// << _____ cDivTop: get / set top
	if ( y != null ) {
		this.posY = y;
		if ( ns4 )		this.css.top = this.posY;
		else if ( ie )	this.css.pixelTop = this.posY;
		else if ( dom )	this.css.top = this.posY+ "px";
	} else {
		return this.posY;
	}
}
function cDivX2( x ) {																							// << _____ cDivTop: get / set left
	if ( x != null ) {
		this.w = this.posX + x;
		if ( ns4 )		this.css.left = this.posX;
		else if ( ie )	this.css.pixelLeft = this.posX;
		else if ( dom )	this.css.left = this.posX + "px";
	} else {
		return this.posX + this.w;
	}
}
function cDivY2( y ) {																							// << _____ cDivTop: get / set top
	if ( y != null ) {
		this.h = this.posY + y;
		if ( ns4 )		this.css.top = this.posY;
		else if ( ie )	this.css.pixelTop = this.posY;
		else if ( dom )	this.css.top = this.posY + "px";
	} else {
		return this.posY + this.h;
	}
}
function cDivW( w ) {																							// << _____ cDivTop: get / set left
	if ( x != null ) {
		this.w = w;
		if ( ns4 )			this.css.clip.width = w;
		else if ( ie4 )	this.css.pixelWidth = w;
		else if ( ie )		this.elm.offsetWidth = w;
		else if ( dom )	this.css.width = w + "px";
	} else {
		return this.w;
	}
}
function cDivH( h ) {																							// << _____ cDivTop: get / set top
	if ( y != null ) {
		this.h = h;
		if ( ns4 )			this.css.clip.height = h;
		else if ( ie4 )	this.css.pixelHeight = h;
		else if ( ie )		this.elm.offsetHeight = h;
		else if ( dom )	this.css.height = h + "px";
	} else {
		return this.h;
	}
}
function cDivVis( shown ) {
	if( shown ) {
		if( ns4 )		this.css.visibility = "show";
		else				this.css.visibility = "visible";
		this.isvis = true;
	} else {
		if( ns4 )		this.css.visibility = "hide";
		else				this.css.visibility = "hidden";
		this.isvis = false;
	}
}

function cDivVisi( shown ) {
	if( this.isvis ) {
		if( ns4 )		this.css.visibility = "hide";
		else				this.css.visibility = "hidden";
	} else {
		if( ns4 )		this.css.visibility = "show";
		else				this.css.visibility = "visible";
	}
	this.isvis = !this.isvis;
}

function cDivIsMouseOver() {
	if( ms.x < this.x() || ms.x > this.x2() || ms.y < this.y() || ms.y > this.y2() )
		return 0;
	else
		return 1;
}
// _____________________________________________________________________________________________________________________ << class cDiv
