/********************************************/
/*   Handcode Toolkit v1.2                  */
/*   Copyright 2007 Incus Web Works         */
/********************************************/

/* Layout Functions */

//These variables define the minimum size of the browser window
MinWidth = 950;
MinHeight = 600;

//compatability code
var isDOM=document.getElementById?1:0;
var isIE=document.all?1:0;
var isNS4=navigator.appName=='Netscape'&&!isDOM?1:0;
var isIE4=isIE&&!isDOM?1:0;
var isOp=window.opera?1:0;
var isWin=navigator.platform.indexOf('Win')!=-1?1:0;
var isDyn=isDOM||isIE||isNS4;
var px=isNS4||isOp?0:"px"; 
var CSSmode=document.compatMode;
CSSmode=(CSSmode&&CSSmode.indexOf('CSS')!=-1)||isDOM&&!isIE||isOp?1:0;

function _getRef(id) {
 return document.getElementById(id);
}
function _getSty(id){
 return _getRef(id).style;
}

//object positioning, width & height functions
function _top(id, value){
 var sty=_getSty(id);
 sty.top=(value?value:0)+px;
}
function _left(id, value){
 var sty=_getSty(id);
 sty.left=(value?value:0)+px;
}
function _width(id, value){
 var sty=_getSty(id);
 sty.width=(value?value:0)+px;
}
function _height(id, value){
 var sty=_getSty(id);
 sty.height=(value?value:0)+px;
}
//page object constructor
if (!window.page) var page = { win: window, minW: MinWidth, minH: MinHeight, MS: isIE&&!isOp, db: CSSmode?'documentElement':'body' }
//function returns window width
page.winW=function() { with (this) return Math.max(minW, MS?win.document[db].clientWidth:win.innerWidth-15) }
//function returns window height
page.winH=function() { with (this) return Math.max(minH, MS?win.document[db].clientHeight:win.innerHeight) }
//onLoad and onResize functions
//window.onload = function() { _position();  _position(); }		//Call on html page
window.onresize = function() { _position(); }
//array to hold all div objects
var divs = Array();
//div object constructor
function div (id, x, y, w, h){ this.id = id; this.x = x; this.y = y; this.w = w; this.h = h; }
//function creates div object
divCount = 0;
function _locate (id, x, y, w, h){
 divs[divCount] = new div(id, x, y, w, h);
 //this line allows reference to div properties directly via id: e.g. div.{divID}.x
 eval ('div.'+id+' = new div(id, x, y, w, h)');
 ++divCount;
}
//function creates div object
function _build (id, x, y, w, h, c, s, t){
 _D(id, c, s);
 document.write(t);
 _C();
 _locate (id, x, y, w, h);
}
//function positions div objects
function _position() {
//only run these functions once
 winW = page.winW();    //no max width
 //widthMax = 900;  winW = page.winW()<widthMax ? page.winW() : widthMax;   //set max width as "widthMax" 
 winH = page.winH();    //no max height
 //heightMax = 790;  winH = page.winH()<heightMax ? page.winH() : heightMax;   //set max height as "heightMax"
 //calculates center
 xCenter = winW/2;
 yCenter = winH/2;
 //claculates left margin for a center-associated object
 xZero = winW/2-MinWidth/2;
 yZero = winH/2-MinHeight/2;
 for (var i = 0; i < divs.length; i++) {
  //'if statement' prevents error if div does not exist in page
  if (_getRef(divs[i].id)) {
   _left(divs[i].id, eval(divs[i].x)); 
   _top(divs[i].id, eval(divs[i].y)); 
   // Don't let the width and height get below 0.    
   if (divs[i].w) _width(divs[i].id, Math.max(0,eval(divs[i].w)));
   if (divs[i].h) _height(divs[i].id, Math.max(0,eval(divs[i].h)));
   _getSty(divs[i].id).visibility="visible";
  }
 }
}



