/* define variables for "if IE (IE 4.x), 
and if n6 (if Netscape 6/W3C-DOM compliant)" */
/* global variables */
var win_width, win_height;

/* just a bit of browser sniffing is necessary. */
var ie = (document.all) ? true: false; 
var x_offset=0, y_offset=0;

/* detecting browser support for certain key objects/methods and 
assembling a custom document object */
var doc,doc2,doc3,sty;
if (document.all) {
  doc = "document.all.";
  doc2 = "";
  doc3 = "";
  sty = ".style";
  ie = true;
}
else if (document.getElementById) {
  doc = "document.getElementById('";
  doc2 ="')";
  doc3 ="')";
  sty = "').style";
  n6 = "true";
} 

var win_width,win_height;

//show or hide an element
function showhide(elem,state) {
	docObj = eval(doc + elem + sty);
	docObj.visibility = state;
}

// get the dimensions of the browser window.
function dimensions() {
	if (ie) {
		win_width=document.body.clientWidth; 
		win_height=document.body.clientHeight;
	}
	else {
		win_width=innerWidth;
		win_height=innerHeight;
	}
}

// initalize the variable that will serve as a 'load checker'
var loaded=0;

//the object constructor's core function (note: IE5+, NS6+)
function createObject(elem,container) {
	if (ie) {
		this.element = document.all[elem];
		this.styleElem = document.all[elem].style;
		this.elemheight = this.element.offsetHeight;
		this.clipheight = this.element.offsetHeight;
	}
	else if (document.getElementById) {
		this.element = document.getElementById(elem);
		this.styleElem = document.getElementById(elem).style;
		this.elemheight = this.element.offsetHeight;
		this.clipheight = this.element.offsetHeight;
	} 
	else {return false;}
	this.scrollIt = scrollIt;
	this.scrollup = scrollup; 
	this.scrolldown = scrolldown;
	this.scroller = scroller;
	this.hidearrow = hidearrow;
	return this; 
}

var minheight, contbox, textbox;

// boxdd, textdd refer to the containing box and the text div in the scrolled area
var boxdd, textdd, contentdd;
function initialize () {
	loaded=1;
	dimensions();
	// explicitly set the width and height of the content (to prevent the minmax issues.
	if (ie)
	{
		document.all['content'].style.width=(win_width-90)+"px";
		document.all['content'].style.height=(win_height-60)+"px";
		document.all['ddbox'].style.width=(win_width - 252-x_offset)+"px";
		document.all['ddbox'].style.height=(win_height - 130-y_offset)+"px";
	}
	showhide('content', 'visible');
}

/* the menu open/close function. */

function togglemenu(num) { 
	
	/* set local variables. */
	var submenu = "sub"+num;
	
	/* Set the display style to "none" if the value is null */
	if (document.getElementById(submenu).style.display == null) {
	 document.getElementById(submenu).style.display = "none";
	}

	/* The toggle section. 
	If the value of the submenu element's display is "none", 
	then it's set to "block"; if the value is "block", it's set to "none".
	*/
	if (document.getElementById(submenu).style.display != "block") {
		changeclassstyle('div','sublevel','display','none');
		document.getElementById(submenu).style.display = "block";
	}
	else {
		document.getElementById(submenu).style.display = "none";
	}
}


/* Get all the elements with a given class name */

function getElementsByClassName(tagname, classname) {
 
 /* only execute in 5+ browsers. */
 if (!document.getElementById) return false;

 /* get all elements with the tag name tagname. */

 var TagElements = document.getElementsByTagName(tagname);

 /* define an array which will hold the elements with the class name classname. */
 var elementsByClassName = new Array();

 /* Look at all the elements in TagElements, and find the ones with the class name classname. */

 for (i=0; i<TagElements.length; i++) {
  if (TagElements[i].className == classname) {
    elementsByClassName[elementsByClassName.length] = TagElements[i];
    }
 }
  return elementsByClassName;
}


function changeclassstyle(tagname,classname,styleproperty,newstyle) {
 var tochange = getElementsByClassName(tagname,classname);
  for (k=0; k < tochange.length; k++) {
    eval("tochange[k].style." + styleproperty + " = " + "'" + newstyle + "'");
  }
}

// get the dimensions of the browser window.
function dimensions() {
	if (ie) {
		win_width=document.body.clientWidth; 
		win_height=document.body.clientHeight;
	}
	else {
		win_width=innerWidth;
		win_height=innerHeight;
	}
}
