function has_class(element, class_name) {
	if (!element.className) {
		return false;
	} else {
		var reg = new RegExp( "\\b" + class_name + "\\b", "gi" );
		return reg.test(element.className);
	}
}

function add_class(element, class_name) {
	if (!has_class(element, class_name)) {
		element.className += " " + class_name;//IE: No set attribute
	}
}

function remove_class(element, class_name) {
	if (element.className) {
		var reg = new RegExp( "\\b" + class_name + "\\b", "gi" );
		element.className = element.className.replace( reg, "" );//IE: no set attribute
	}
}

function activate_menu_item(item, parentId, submenu_id) {
  p = document.getElementById(parentId);
	thisChild = p.firstChild;
	while (thisChild != p.lastChild)	{
		if (thisChild.nodeType==1) {
			remove_class(thisChild, 'active');
		}
		thisChild = thisChild.nextSibling;
	}
	add_class(item, 'active');
  p = document.getElementById('submenus');
  thisChild = p.firstChild;
  if (thisChild.nodeType==1) {
    thisChild.style.display = 'none';
  }
  while (thisChild != p.lastChild)	{
    if (thisChild.nodeType==1) {
      thisChild.style.display = 'none';
    }
    thisChild = thisChild.nextSibling;
  }
  if (submenu_id) {
    document.getElementById(submenu_id).style.display = 'block';
  }
	content_focus();//put cursor focus back in content frame after click
}

/* DHTML micro API, version B
 * http://www.quirksmode.org/js/dhtmloptions.html
 */
function getObj(name) {
  if (document.getElementById) {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
  } else if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
  } else if (document.layers) {
		this.obj = getObjNN4(document,name);
		this.style = this.obj;
  }
}

function getObjNN4(obj,name) {
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++) {
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}

/*The initImage function makes the photo completely tranpsarent by using the setOpacity function to set its opacity to zero. The photo can then be made visible and faded in using the fadeIn function:*/

function initImage() {
  imageId = 'intro_wrapper';
  if (document.getElementById) {
    image = window.frames['content_frame'].document.getElementById(imageId);
    if (image) {
      setOpacity(image, 0);
      image.style.visibility = 'visible';
      fadeIn(imageId,0);
    }
  }
}

/*The setOpacity function is passed an object and an opacity value. It then sets the opacity of the supplied object using four proprietary ways. It also prevents a flicker in Firefox caused when opacity is set to 100%, by setting the value to 99.999% instead.*/

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  if (obj.style.filter) {  // IE/Win
    obj.style.filter = "alpha(opacity:"+opacity+")";
  } else if (obj.style.KHTMLOpacity) {  // Safari<1.2, Konqueror
    obj.style.KHTMLOpacity = opacity/100;
  } else if (obj.style.MozOpacity) {  // Older Mozilla and Firefox
    obj.style.MozOpacity = opacity/100;
  } else {// Safari 1.2, newer Firefox and Mozilla, CSS3
    obj.style.opacity = opacity/100;
  }
}

/*The fadeIn function uses a Timeout to call itself every 100ms with an object Id and an opacity. The opacity is specified as a percentage and increased 10% at a time. The loop stops once the opacity reaches 100%:*/

function fadeIn(imageId,opacity) {
  obj = window.frames['content_frame'].document.getElementById(imageId);
//  obj = document.getElementById(imageId);
  if (opacity <= 100) {
    setOpacity(obj, opacity);
    opacity += 10;
    window.setTimeout("fadeIn('"+imageId+"',"+opacity+")", 100);
  }
}


function content_focus() {
  window.frames['content_frame'].focus();
}

function resize_iframe() {
  var window_height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
  header_height = document.getElementById('header').scrollHeight;
  if (document.all) {
    document.getElementById('content_frame').style.height = (window_height - header_height + 60) +'px';
  } else {
    document.getElementById('content_frame').style.height = (window_height - header_height + -40) +'px';
  }
  content_focus();
}

//window.onload = function() {initImage()}
function addLoadEvent(func) { 
  var oldonload = window.onload; 
  if (typeof window.onload != 'function') { 
    window.onload = func; 
  } else { 
    window.onload = function() { 
      if (oldonload) { 
        oldonload(); 
      } 
      func(); 
    } 
	} 
}

//addLoadEvent(content_focus);
addLoadEvent(initImage);
addLoadEvent(resize_iframe);
window.onresize = resize_iframe;
