/*******************************************************************************
FILE NAME    :dhtml.js
DEPENDENCIES :browser.js
********************************************************************************
____________________________ API DOCUMENTATION BEGIN ___________________________
````````````````````````````````````````````````````````````````````````````````
Provides foundation properties and methods. COREPROPERTIES may be used as a 
class or method depending on implementation.

````````````````````````````````````````````````````````````````````````````````
_____________________________ API DOCUMENTATION END ____________________________
*******************************************************************************/

//CLASS--- creates an object with foundation properties
//METHOD-- adds foundation properties to an existing object
function COREPROPERTIES(divID, parentID1, parentID2, clipDiv) {
 if((gBrowser.ie || gBrowser.ns || gBrowser.safari) && gBrowser.majorVersion >= 5)
 {
  this.objCss = document.getElementById(divID).style; //reference to [object CSSStyleDeclaration]
	this.objDivElement = document.getElementById(divID); //reference to [object HTMLDivElement]
	 
	//define position properties
  this.y = document.getElementById(divID).offsetTop; //top position of object 
  this.w = document.getElementById(divID).offsetWidth; //width of object
  this.h = document.getElementById(divID).offsetHeight; //height of object
  this.x = document.getElementById(divID).offsetLeft; //left position of object
  
  if(clipDiv)
  {
	 //set default clip values
	 document.getElementById(divID).style.clip = "rect(0px "+this.w+"px "+this.h+"px " +"0px)";
	 
   //define and retrieve clip properties 
 	 var clipv       = this.objCss.clip.split("rect(")[1].split(")")[0].split("px");
   this.topClip    = parseInt(clipv[0]);
   this.rightClip  = parseInt(clipv[1]);
   this.bottomClip = parseInt(clipv[2]);
   this.leftClip   = parseInt(clipv[3]);
  }
	 
	this.vis = this.objDivElement.visibility;
  this.zOrder = this.objDivElement.zIndex;
 }
 else if(gBrowser.ns4)
 {
	//set reference to layer
	if((parentID1 != null) && (parentID2 != null)) this.objCss = document.layers[parentID1].document.layers[parentID2].document.layers[divID]; //nested two layers
	else if((parentID1 != null) && (parentID2 == null)) this.objCss = document.layers[parentID1].document.layers[divID]; //nested one layer
	else this.objCss = document.layers[divID]; //not nested
  
	//define position properties
	this.y = parseInt(this.objCss.top); //top position of object 
  this.w = parseInt(this.objCss.clip.width); //width of object
  this.h = parseInt(this.objCss.clip.height); //height of object
  this.x = parseInt(this.objCss.left); //left position of object

  if(clipDiv)
  {
   //define clipping properties
   this.topClip    = parseInt(this.objCss.clip.top);
   this.rightClip  = parseInt(this.objCss.clip.right);
   this.bottomClip = parseInt(this.objCss.clip.bottom);
   this.leftClip   = parseInt(this.objCss.clip.left);
  }
		
	this.vis = this.objCss.visibility;
  this.zOrder = this.objCss.zIndex;
 }
	
 //common properties
 this.divID = divID;
 eval(this.obj + "=this"); //for methods using setTimeouts, setInterval, or eval's to call itself
}

//METHODS BEGIN --------------------------------------------------------------

//METHOD-- moves object to new coordinates
function _moveTo(x_left_hor, y_top_ver) {
 this.x = parseInt(x_left_hor);
 this.y = parseInt(y_top_ver);
 this.m_updatePosProp( );
}

//METHOD-- synchs position properties
function _updatePosProp() {
 if(gBrowser.ie) {this.objCss.pixelLeft = parseInt(this.x); this.objCss.pixelTop = parseInt(this.y);}
 else if(gBrowser.ns || gBrowser.safari) {this.objCss.left = parseInt(this.x); this.objCss.top = parseInt(this.y);} 
}

//METHOD-- updates height property
function _updateHeight() {
 if((gBrowser.ie || gBrowser.ns || gBrowser.safari) && gBrowser.majorVersion >= 5) {this.h = document.getElementById(this.divID).offsetHeight;}
}

//METHOD-- positions a object within the browser window
function _positionObj(fixedWidth, argFlushTop) {
 var theScreenW = getWindowWidth();
 if(fixedWidth != false) {if(theScreenW > fixedWidth) theScreenW = fixedWidth;}
 var theScreenH = getWindowHeight();
 var xPos = getCenterX(theScreenW, this.w);
 var yPos = getCenterY(theScreenH, this.h);
 if(checkWindowCoordsX(xPos, theScreenW, this.w)) {xPos = 0;}
 //if(checkWindowCoordsY(yPos, theScreenW, this.y)) {yPos = 0;}
 if(argFlushTop) this.m_moveTo(xPos, 0);
 else this.m_moveTo(xPos, yPos);
}

//METHOD-- sets display property
function _setDisplay(argNum) {
 switch(argNum)
 {
  case 1:
   this.objCss.display = "block";
   break;		
  case 2:
   this.objCss.display = "none";
   break;
  default:
   alert("Error: \"_setDisplay()\" method.\nCase not Found");
 }
}

//METHOD-- sets background image
function _setBackgroundImage(imagePath) {
 this.objCss.backgroundImage = "url("+imagePath+")";
}

//METHOD-- sets Alpha background image (IE only)
function _setAlphaImage(imagePath) {
 if(gBrowser.ie && gBrowser.isWin) this.objCss.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+imagePath+"', sizingMethod='scale')";
 else this.m_setBackgroundImage(imagePath);
}

//METHOD-- sets height and width of mask (uses window.js)
function _setMask() {
 //get height
 var theWindowHeight = getWindowHeight();
 var theBodyHeight = getBodyHeight();
  
 //get width
 var theWindowWidth = getWindowWidth();
 var theBodyWidth = getBodyWidth();

 //set mask height
 if(theWindowHeight >= theBodyHeight) {this.objCss.height = theWindowHeight;}
 else {this.objCss.height = theBodyHeight;}
 
 //set mask width
 if(theWindowWidth >= theBodyWidth) {this.objCss.width = theWindowWidth;}
 else {this.objCss.width = theBodyWidth;}
 
 this.m_setDisplay(1);
}

//METHODS END ----------------------------------------------------------------

//FUNCTIONS BEGIN ------------------------------------------------------------

//FUNCTION-- sets display to block
function setDisplayBlock(argEl) {
 document.getElementById(argEl).style.display = "block";
}

//----------------------------------------------------------------------------

//FUNCTION-- sets display to none
function setDisplayNone(argEl) {
 document.getElementById(argEl).style.display = "none";
}

//FUNCTIONS END ----------------------------------------------------------------

//---END