// DHTMLapi.js custom API for cross-platform
// object positioning by Danny Goodman (http://www.dannyg.com)
// From "JavaScript Bible" 4th Edition.

// convert object name string or object reference
// into a valid object reference ready for style change
function getObject(obj) {
	var theObj
	if (document.layers) {
		if (typeof obj == "string") {
			return document.layers[obj]
		} else {
			return obj
		}
	}
	if (document.all) {
		if (typeof obj == "string") {
			return document.all(obj).style
		} else {
			return obj.style
		}
	}
	if (document.getElementById) {
		if (typeof obj == "string") {
			return document.getElementById(obj).style
		} else {
			return obj.style
		}
	}
	return null
}

// position an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
	var theObj = getObject(obj)
	if (theObj.moveTo) {
		theObj.moveTo(x,y)
	} else if (typeof theObj.left != "undefined") {
		theObj.left = x
		theObj.top = y
	}
}

// move an object by x and/or y pixels
function shiftBy(obj, deltaX, deltaY) {
	var theObj = getObject(obj)
	if (theObj.moveBy) {
		theObj.moveBy(deltaX, deltaY)
	} else if (typeof theObj.left != "undefined") {
		theObj.left = parseInt(theObj.left) + deltaX
		theObj.top = parseInt(theObj.top) + deltaY
	}
}

// set the z-order of an object
function setZIndex(obj, zOrder) {
	var theObj = getObject(obj)
	theObj.zIndex = zOrder
}

// set the background color of an object
function setBGColor(obj, color) {
	var theObj = getObject(obj)
	if (theObj.bgColor) {
		theObj.bgColor = color
	} else if (typeof theObj.backgroundColor != "undefined") {
		theObj.backgroundColor = color
	}
}

function getLayerPosx(obj) {
	var posx = getObjectLeft('navigation');
	
	//positioning for subnav layer left offset
	//posx = 210;
	switch (obj) {
			case "listeners":
				posx += 0;			
			break;
			
			case "broadcasters":
				posx += 119;					
			break;
			
			case "advertisers":
				posx += 194;					
			break;
			
			case "contentowners":
				posx += 504;
			break;
			
			case "carriers":
				posx += 616;
			break;
	}
	
	return posx;
}

// retrieve the x coordinate of a positionable object
function getObjectLeft(obj)  {
	var theObj = getObject(obj)
	return parseInt(theObj.left)
}

// retrieve the y coordinate of a positionable object
function getObjectTop(obj)  {
	var theObj = getObject(obj)
	return parseInt(theObj.top)
}

//align an object to the center
function centerObject(obj) {
		var screenWidth = alertSize();
		
		var navx = (screenWidth - 772)/2;
		var theObj = getObject(obj);

		theObj.left = parseInt(navx) + 'px';
		theObj.visibility = 'visible';		

}

function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  return myWidth;
 // window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
}