// Dynamic Layer Object - Modified 05.30.01
// Copyright (C) 1999 Dan Steinman
// Distributed under the terms of the GNU Library General Public License
// Available at http://www.dansteinman.com/dynapi/

//*********************************************
// Sapient history: 1.0 Ryan McCormak, David Kyle 1.1
//
// Description: This file has four purposes:
// 1. Create the objects representing the popUP menus (DynLayer) and the "Sapient Sites" country selector (counDynLayer).
// 2. Write the style sheet to the browser for the "Sapient" global navigation 
// 3. create the browser snif object "is"
// 4. Create and write the cascading style sheet for the global and country navs
// 
// Note: Two methods are used for creating the 4 layers (global nav, global menu, country nav, country menu)
// 1. For the global and country navs, Divs are written to the window (gNav_divCode.js) then style sheets are writen to the window. 
//	These style sheets take care of positioning, clip size, visibility,...
// 2. For the global and country menus, the arrays in gNav_menuData.js are cycled in gNav_MenuBuilder.js and menu objects are created (function Menu(...)).
//	These objects contain the divs that are writen to the window in gNav_divCcode.js. onLoad calls the init() function in gNav_navFunctions.js that
//	creates DynLayer objects for the global and country menus (gNav_dynlayerRPM.js) and counDynLayer for the country nav, this provides an easy handle for dynamic repositioning fired after the onReload event.
//	DynLayer and counDynLayer are wrappers that take the various DOM's and provide a consistant object model
//
//
//**********************************************

function DynLayer(id,nestref) {
	if (is.ns) {
		if (is.ns4) {
			if (!nestref) var nestref = DynLayer.nestRefArray[id]
			if (!DynLayerTest(id,nestref)) return
			this.css = (nestref)? eval("document."+nestref+".document."+id) : document.layers[id]
			this.elm = this.event = this.css
			this.doc = this.css.document
			this.w = this.css.clip.width
			this.h = this.css.clip.height
		} else if (is.ns6) {
			this.elm = document.getElementById(id)
			this.css = this.elm.style
			this.doc = document
			this.w = getStyle(id,"width")
			this.h = getStyle(id,"height")
		}
		this.x = this.css.left
		this.y = this.css.top
		
	}
	else if (is.ie) {	
		this.elm = this.event = document.all[id];
		this.css = document.all[id].style;
		this.doc = document;
		this.x = this.elm.offsetLeft;
		this.y = this.elm.offsetTop;
		this.w = (is.ie4)? this.css.pixelWidth : this.elm.offsetWidth;
		this.h = (is.ie4)? 113 : this.elm.offsetHeight;
		this.docHeight = 'document.body.scrollHeight';
		this.docWidth = (is.ie4)? 'document.body.clientWidth' : 'document.body.clientWidth';
	}
	this.id = id
	this.nestref = nestref
	this.obj = id + "DynLayer"
	eval(this.obj + "=this")
}
function DynLayerShow() {
	this.css.visibility = (is.ns4)? "show" : "visible"
}
function DynLayerHide() {
	this.css.visibility = (is.ns4)? "hide" : "hidden"
}
function DynLayerLeft(test) {
	if (is.ie)
		{
		var leftOffset = eval(this.docWidth) - gCouNav_navRightMargin - this.w;
		if ((eval(this.docWidth) - gCouNav_navRightMargin - gCouNav_menuWidth) < 460) leftOffset = 460 + gCouNav_menuWidth - this.w;
		else if ((eval(this.docWidth) - gCouNav_navRightMargin) > 1020) leftOffset = 1020 - this.w;
		this.css.left = leftOffset;
		}
		
	else this.css.left = document.width - gCouNav_navRightMargin - this.w;
	
	
}
function DynLayerTop(test) {
if(home == '1') {
	var addElemHeight = (test)? (this.h - 1): 0;
	if (is.ie)
		{
		var disToTop = document.all.tags("span")["oFoot"].offsetTop ;
		if (is.ie4) disToTop += 145;
		this.css.top = disToTop - gCouNav_navBottomMargin - addElemHeight + 54;
		}
	else this.css.top = document.height- gCouNav_navBottomMargin - addElemHeight + 15;
	
	}
	
}

DynLayer.prototype.show = DynLayerShow
DynLayer.prototype.setBottom = DynLayerTop
DynLayer.prototype.setRight = DynLayerLeft
DynLayer.prototype.hide = DynLayerHide
DynLayer.prototype.setbg = DynLayerSetbg
DynLayerTest = new Function('return true')
DynLayer.nestRefArray = new Array()
DynLayer.refArray = new Array()
DynLayer.refArray.i = 0
DynLayer.set = false




// BrowserCheck Object
function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.version = navigator.appVersion
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns6 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
    	this.ie6 = (this.version.indexOf('MSIE 6')>0)
	this.min = (this.ns||this.ie)
}
is = new BrowserCheck()






// CSS Function
function css(id,left,top,width,height,color,vis,z,other) {

	if (id=="START") return '<STYLE TYPE="text/css">\n'
	else if (id=="END") return '</STYLE>'
	var str = (left!=null && top!=null)? '#'+id+' {position:absolute; left:' + left + 'px;' + ' top:'+top+'px;' : '#'+id+' {position:relative;'
	if (arguments.length>=4 && width!=null) str += ' width:'+width+'px;'
	if (arguments.length>=5 && height!=null) {
		str += ' height:'+height+'px;'
		if (arguments.length<9 || other.indexOf('clip')==-1) str += ' clip:rect(0px '+width+'px '+height+'px 0px);'
	}
	if (arguments.length>=6 && color!=null) str += (is.ns)? ' layer-background-color:'+color+';' : ' background-color:'+color+';'
	if (arguments.length>=7 && vis!=null) str += ' visibility:'+vis+';'
	if (arguments.length>=8 && z!=null) str += ' z-index:'+z+';'
	if (arguments.length==9 && other!=null) str += ' '+other
	str += '}\n'
	return str
}




function writeCSS(str,showAlert) {
	str = css('START')+str+css('END')
	document.write(str)
	//alert(str)
}




// Set the background color of a DIV
function DynLayerSetbg(color) {
	if (is.ns) this.doc.bgColor = color
	else if (is.ie) this.css.backgroundColor = color
}




function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (document.defaultView)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	else if (x.currentStyle)
		var y = eval('x.currentStyle.' + styleProp);
	return parseInt(y);
}
