/*******************************************************************************
____________________________ API DOCUMENTATION BEGIN ___________________________
````````````````````````````````````````````````````````````````````````````````
Provides framework for classes, methods and properties. Class_Super allows us to
define methods and properites that will be visible to all objects from classes
that are derived from it making the use of methods and properties very
efficent since they are not duplicated. If we do not want a particular method to 
be visible to all objects then all that is needed is to set the prototype to 
that class instead of Class_Super.

````````````````````````````````````````````````````````````````````````````````
_____________________________ API DOCUMENTATION END ____________________________
*******************************************************************************/

//------------------------------------------------------------------------------
// CLASS CONSTRUCTORS BEGIN
//------------------------------------------------------------------------------

//CLASS CONSTRUCTOR-- the super class
function Class_Super() {}

//Prototype derive/extend (single inheritance only)
Spawn_Object.prototype = new Class_Super;

//Prototype properties
Class_Super.prototype.zIndexCounter = 500; //global index counter for all elements in a page

//CLASS CONSTRUCTOR-- creates an generic object with foundation properties
function Spawn_Object(argDivID) {
 this.objCss = document.getElementById(argDivID).style; //create reference to [object CSSStyleDeclaration]
 this.objDivElement = document.getElementById(argDivID); //create reference to [object HTMLDivElement]
 this.objDivID = argDivID; //set element ID
 eval(this.obj + "=this"); //for methods using setTimeouts, setInterval, or eval's to call itself
}

//------------------------------------------------------------------------------
// CLASS CONSTRUCTORS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// METHODS BEGIN
//------------------------------------------------------------------------------

//METHOD-- set height property of object
function _setHeight(argHeight, argSynch) {
 this.objH = argHeight;
 if(argSynch) this.m_synchHeightProperty(); //synch to element property
}

Class_Super.prototype.m_setHeight = _setHeight;

//------------------------------------------------------------------------------

//METHOD-- set width property of object
function _setWidth(argWidth, argSynch) {
 this.objW = argWidth;
 if(argSynch) this.m_synchWidthProperty(); //synch to element property
}

Class_Super.prototype.m_setWidth = _setWidth;

//------------------------------------------------------------------------------

//METHOD-- get height of element
function _getHeight() {
 return this.objDivElement.offsetHeight;
}

Class_Super.prototype.m_getHeight = _getHeight;

//------------------------------------------------------------------------------

//METHOD-- get width of element
function _getWidth() {
 return this.objDivElement.offsetWidth;
}

Class_Super.prototype.m_getWidth = _getWidth;

//------------------------------------------------------------------------------

//METHOD-- synchs elements height property with objects height property
function _synchHeightProperty() {
 this.objCss.height = this.objH+"px";
}

Class_Super.prototype.m_synchHeightProperty = _synchHeightProperty;

//------------------------------------------------------------------------------

//METHOD-- synchs elements width property with objects width property
function _synchWidthProperty() {
 this.objCss.width = this.objW+"px";
}

Class_Super.prototype.m_synchWidthProperty = _synchWidthProperty;

//------------------------------------------------------------------------------

//METHOD-- set top property of object
function _setTop(argTop) {
 this.objY = argTop; 
 this.m_synchTopProperty();
}

Class_Super.prototype.m_setTop = _setTop;

//------------------------------------------------------------------------------

//METHOD-- set left property of object
function _setLeft(argLeft) {
 this.objX = argLeft; 
 this.m_synchLeftProperty();
}

Class_Super.prototype.m_setLeft = _setLeft;

//------------------------------------------------------------------------------

//METHOD-- get top property of object
function _getTop(argTop) {
 return this.objDivElement.offsetTop; 
}

Class_Super.prototype.m_getTop = _getTop;

//------------------------------------------------------------------------------

//METHOD-- get left property of object
function _getLeft(argLeft) {
 return this.objDivElement.offsetLeft; 
}

Class_Super.prototype.m_getLeft = _getLeft;

//------------------------------------------------------------------------------

//METHOD-- synchs elements top property with objects top property
function _synchTopProperty() {
 if(document.all) {this.objCss.pixelTop = this.objY;}
 else {this.objCss.top = this.objY+"px";} 
}

Class_Super.prototype.m_synchTopProperty = _synchTopProperty;

//------------------------------------------------------------------------------

//METHOD-- synchs elements left property with objects left property
function _synchLeftProperty() {
 if(document.all) {this.objCss.pixelLeft = this.objX;}
 else {this.objCss.left = this.objX+"px";} 
}

Class_Super.prototype.m_synchLeftProperty = _synchLeftProperty;

//------------------------------------------------------------------------------

//METHOD-- sets display property to block
function _displayBlock() {
 this.objCss.display = "block";
}

Class_Super.prototype.m_displayBlock = _displayBlock;

//------------------------------------------------------------------------------

//METHOD-- sets display property to none
function _displayNone() {
 this.objCss.display = "none";
}

Class_Super.prototype.m_displayNone = _displayNone;

//------------------------------------------------------------------------------

//METHOD-- returns display property of object
function _getDisplay() {
 return this.objCss.display;
}

Class_Super.prototype.m_getDisplay = _getDisplay;

//------------------------------------------------------------------------------

//METHOD-- set visibility property to visible
function _visibilityVisible() {
 this.objCss.visibility = "visible";
}

Class_Super.prototype.m_visibilityVisible = _visibilityVisible;

//------------------------------------------------------------------------------

//METHOD-- set visibility property to hidden
function _visibilityHidden() {
 this.objCss.visibility = "hidden";
}

Class_Super.prototype.m_visibilityHidden = _visibilityHidden;

//------------------------------------------------------------------------------

//METHOD-- changes objects visibility property to inherit
function _inheritVisibility() {
 this.objCss.visibility = "inherit";
}

Class_Super.prototype.m_inheritVisibility = _inheritVisibility;

//------------------------------------------------------------------------------

//METHOD-- returns visibility property of object
function _getVisibility() {
 return this.objCss.visibility;
}

Class_Super.prototype.m_getVisibility = _getVisibility;

//------------------------------------------------------------------------------

//METHOD-- sets background image
function _setBackgroundImage(argImagePath) {
 this.objCss.backgroundImage = "url("+argImagePath+")";
}

Class_Super.prototype.m_setBackgroundImage = _setBackgroundImage;

//------------------------------------------------------------------------------

//METHOD-- sets Alpha background image (IE only)
function _setAlphaImage(argImagePath) {
 if(document.all) this.objCss.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+argImagePath+"', sizingMethod='scale')";
 else this.m_setBackgroundImage(argImagePath);
}

Class_Super.prototype.m_setAlphaImage = _setAlphaImage;

//------------------------------------------------------------------------------

//METHOD-- sets CSS class
function _setCssClass(argClass) {
 this.objDivElement.className = argClass;
}

Class_Super.prototype.m_setCssClass = _setCssClass;

//------------------------------------------------------------------------------

//METHOD-- sets default clip properties
function _setClipProperties() {
 if(!this.objW && !this.objH) //height and width must exist before setting clip properties or you will receive an error
 {
	this.m_setHeight(this.m_getHeight(), true);
  this.m_setWidth(this.m_getWidth(), true);
 }
 this.objCss.clip = "rect(0px "+this.objW+"px "+this.objH+"px " +"0px)";
 this.m_updateClipProperties();
}

Class_Super.prototype.m_setClipProperties = _setClipProperties;

//------------------------------------------------------------------------------

//METHOD-- updates clip properties
function _updateClipProperties() {
 var clipPropArr = this.objCss.clip.match(/rect\((\d+)px[,]?[ ]+(\d+)px[,]?[ ]+(\d+)px[,]?[ ]+(\d+)px\)/i);
	
 //define clip properties
 this.objTopClip    = parseInt(clipPropArr[1]);
 this.objRightClip  = parseInt(clipPropArr[2]);
 this.objBottomClip = parseInt(clipPropArr[3]);
 this.objLeftClip   = parseInt(clipPropArr[4]);
}

Class_Super.prototype.m_updateClipProperties = _updateClipProperties;

//------------------------------------------------------------------------------

//METHOD-- returns top, right, bottom or left clip values of object
function _getClipProperties(whichClip) {
 if(whichClip=="t") return this.objTopClip;
 if(whichClip=="r") return this.objRightClip;
 if(whichClip=="b") return this.objBottomClip;
 if(whichClip=="l") return this.objLeftClip;
}

Class_Super.prototype.m_getClipProperties = _getClipProperties;

//------------------------------------------------------------------------------

//METHOD-- clips object
function _clipTo(argTop, argRight, argBottom, argLeft) {
 this.objCss.clip= "rect("+argTop+"px "+argRight+"px "+argBottom+"px "+argLeft+"px)";
 this.m_updateClipProperties();
}

Class_Super.prototype.m_clipTo = _clipTo;

//------------------------------------------------------------------------------

//METHOD-- clips object relative to its current clip values
function _clipBy(argTop, argRight, argBottom, argLeft) {
 this.objCss.clip= "rect("+(parseInt(this.m_getClipProperties('t'))+argTop)+"px "+(parseInt(this.m_getClipProperties('r'))+argRight)+"px "+(parseInt(this.m_getClipProperties('b'))+argBottom)+"px "+(parseInt(this.m_getClipProperties('l'))+argLeft)+"px)";
 this.m_updateClipProperties();
}

Class_Super.prototype.m_clipBy = _clipBy;

//------------------------------------------------------------------------------

//METHOD-- clips object using wiping effect
function _clipWiper(argTop, argRight, argBottom, argLeft, argWipeSpeed, argThreshold) {
 if(this.m_getClipProperties('b')>=argThreshold) //set threshold/stop point (set t,r,b or l depending)
 {
  this.m_clipBy(argTop, argRight, argBottom, argLeft);
	//use this.obj when you want a method of an object call itself
  setTimeout(this.obj + ".m_clipWiper(" + argTop + ", " + argRight + ", " + argBottom + ", " + argLeft + ", " + argWipeSpeed + ", " + argThreshold +")", argWipeSpeed);
 }
}

Class_Super.prototype.m_clipWiper = _clipWiper;

//------------------------------------------------------------------------------

//METHOD-- moves object to new coordinates
function _moveTo(argY, argX) {
 this.objX = parseInt(argX);
 this.objY = parseInt(argY);
 this.m_synchTopProperty();
 this.m_synchLeftProperty();
}

Class_Super.prototype.m_moveTo = _moveTo;

//------------------------------------------------------------------------------

//METHOD-- moves object to new location relative to its old position
function _moveRelative(argX, argY) {
 if(isNaN(this.objX) && isNaN(this.objY)) //if X and Y properties are not set then init them
 {
	this.m_setTop(block.m_getTop(), true);
	this.m_setLeft(block.m_getLeft(), true);
 }
 this.m_moveTo((parseInt(this.objY) + parseInt(argY)), (parseInt(this.objX) + parseInt(argX)));
}

Class_Super.prototype.m_moveRelative = _moveRelative;

//------------------------------------------------------------------------------

//METHOD-- sets height and width of mask
function _setMask() {
 this.m_setHeight(50, true);
 this.m_setWidth(50, true);
 
 //get height
 var theWindowHeight = getBrowserWindowHeight();
 var theBodyHeight = getBodyHeight();
  
 //get width
 var theWindowWidth = getBrowserWindowWidth();
 var theBodyWidth = getBodyWidth();
 
 //alert("Window: " + theWindowHeight + " " + theWindowWidth + "\n" + "Body: " + theBodyHeight + " " + theBodyWidth + "\n" + window.scrollMaxY);

 //set mask height
 if(theWindowHeight >= theBodyHeight) {this.m_setHeight(theWindowHeight, true);}
 else {this.m_setHeight(theBodyHeight, true);}

 //set mask width
 if(theWindowWidth >= theBodyWidth) {this.m_setWidth(theWindowWidth, true);}
 else {this.m_setWidth(theBodyWidth, true);}
 
 this.m_displayBlock(); //display the mask
}

Class_Super.prototype.m_setMask = _setMask;

//------------------------------------------------------------------------------

//METHOD-- centers an object vertically and horizontally within the browser window
function _positionObjCenterXY(argPageWidth) {
 var theBrowserWinWidth = getBrowserWindowWidth();
 var theBrowserWinHeight = getBrowserWindowHeight();
 
 if(argPageWidth != false) //if website is fixed width (not liquid)
 {
	if(theBrowserWinWidth > argPageWidth) theBrowserWinWidth = argPageWidth;
 }
 
 var leftPosition = getObjectPositionLeft(theBrowserWinWidth, this.objW);
 var topPosition = getObjectPositionTop(theBrowserWinHeight, this.objH);
 
 this.m_moveTo(topPosition, leftPosition);
}

Class_Super.prototype.m_positionObjCenterXY = _positionObjCenterXY;

//------------------------------------------------------------------------------

//METHOD-- validate if object
function _isObject() {
 if(typeof(this) == "object") return true;
 else return false;
}

Class_Super.prototype.m_isObject = _isObject;

//------------------------------------------------------------------------------

//METHOD-- sets background color
function _setBgcolor(argBgColor) {
 this.objCss.backgroundColor = argBgColor;
}

Class_Super.prototype.m_setBgcolor = _setBgcolor;

//------------------------------------------------------------------------------
// METHODS END
//------------------------------------------------------------------------------