// JavaScript Document
// Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();
function SafeAddOnload(f)
{
	
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
if (IEmac && IE4) // IE 4.5 blows out on testing window.onload
{
window.onload = SafeOnload;
gSafeOnload[gSafeOnload.length] = f;
}
else if (window.onload)
{
if (window.onload != SafeOnload)
{
gSafeOnload[0] = window.onload;
window.onload = SafeOnload;
} 
gSafeOnload[gSafeOnload.length] = f;
}
else
window.onload = f;
}

function SafeOnload()
{
for (var i=0;i<gSafeOnload.length;i++)
gSafeOnload[i]();
}




function switch_src(id,src){
		
		switch_Preload= new Image;
		switch_Preload.src=src;

		if (switch_Preload.complete){  //if not preloaded, don't do anything otherwise pic will screw up on transition
			var imageobj=document.getElementById(id);
			if(imageobj.filters!=null)imageobj.filters[0].apply();
			imageobj.setAttribute('src', src);
			if(imageobj.filters!=null) imageobj.filters[0].play();
		}
		/*else {
			
			switch_Preload.id=id;
			switch_Preload.onload=  function () {
				var id= this.id
				var src= this.src;
				var imageobj=document.getElementById(id);
				if(imageobj.filters!=null)imageobj.filters[0].apply();
				imageobj.setAttribute('src', src);
				if(imageobj.filters!=null) imageobj.filters[0].play();
			}
		}*/
}


/*
	Standards Compliant Rollover Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php
*/

function initRollovers() {
	
	if (!document.getElementById) return
	

	var aPreLoad = new Array();
	var oDefault_over = new Array();
	var aImages = document.getElementsByTagName('img');
	var def_counter = 0;  //counter for oDefault_over

	for (var i = 0; i < aImages.length; i++) {

		//begin  Rollover setup
		if (aImages[i].className.match("rollover")) {
			
			var src = aImages[i].getAttribute('src');
			var filetype = src.substring(src.lastIndexOf('.'), src.length);
			aImages[i].on_src = src.replace(filetype, '_over'+filetype);
			aImages[i].off_src =src;
			
			if (aImages[i].className.match("default_over")) {  //immediately turn on image with class "default_over"
				oDefault_over[def_counter] = aImages[i];  //make 
				turn_ON(oDefault_over[def_counter]);
				menu_div(oDefault_over[def_counter]); //sets up .menu_div for oDefault_over[def_counter]
				write_to_children(oDefault_over[def_counter].menu_div,oDefault_over[def_counter]);
				def_counter++;
			}
			else { //Don't apply mouseover/out fncts to "default_over"
				
				aPreLoad[i] = new Image();
				aPreLoad[i].src = aImages[i].on_src;  //preload all "over" pics
				
				aImages[i].onmouseover = function rollover_over(e) { // e is used in case of netscape to pass event
					var imageobj =this;
					imageobj.mousein="yes";  //need this to avoid when entering page with the mouse over a rollover, otherwise mouseout is called with no mouseover
					turn_ON(imageobj);				
				
					// begin turn off default_over
					var fromElement;
					if (!e) var e = window.event;  //see http://www.quirksmode.org/js/events_mouse.html#relatedtarget
					if (e.relatedTarget) fromElement = e.relatedTarget;  //for netscape
					else if (e.fromElement) fromElement = e.fromElement;  //for IE
					else fromElement = "nothing";  //for case of page load with mouse over a rollover, there is no From element, so it crashes script unless fromelement given some value
						for (var x = 0; x< oDefault_over.length; x++) { // if there is a default_over image, fade it in and out
							if (menu_div(oDefault_over[x]).id == menu_div(imageobj).id && fromElement.menu!= imageobj.menu ) { //only fade in and out default over if it is in the same menu, but also not if you are only moving in the same menu
								turn_OFF(oDefault_over[x]);
							}
						}
					//end turn off default_over

				}	
				
				aImages[i].onmouseout = function rollover_out(e) {
					var imageobj =this;
					
						
					if (imageobj.mousein=="yes") {  //need this to avoid when entering page with the mouse over a rollover, otherwise mouseout is called with no mouseover
						turn_OFF(imageobj)
						imageobj.mousein="no";   //reset this value
						
						//capture info about to/from mouseover 
						var toElement;
						if (!e) var e = window.event;  //see http://www.quirksmode.org/js/events_mouse.html#relatedtarget
						if (e.relatedTarget) toElement = e.relatedTarget;  //for netscape
						else if (e.toElement) toElement = e.toElement;  //for IE
						else toElement = "nothing";  //for case of page load with mouse over rollover, there is no "to" element, so it crashes script unless toelement given some value
						
						
						
						// begin turn on default_over
							for (var x = 0; x< oDefault_over.length; x++) { // if there is a default_over image, fade it in and out
								if (menu_div(oDefault_over[x]).id == menu_div(imageobj).id && toElement.menu!= imageobj.menu ) { //only fade in and out default over if it is in the same menu, but also not if you are only moving in the same menu
								turn_ON(oDefault_over[x]);
								}
							}
						//end turn on default_over
						

					}
				}
			}
		}
	}
	  
}
function turn_ON(imageobj) {
		if(imageobj.filters!=null)imageobj.filters[0].apply();
		imageobj.src=imageobj.on_src;
		if(imageobj.filters!=null) imageobj.filters[0].play();
}

function turn_OFF(imageobj) {
		if(imageobj.filters!=null)imageobj.filters[0].apply();
		imageobj.src=imageobj.off_src;
		if(imageobj.filters!=null) imageobj.filters[0].play();
}


function parent_id(obj){
	if (obj && obj!="nothing" && obj.tagName!="HTML" && obj.tagName!="BODY") { //"nothing" is for case of no fromELement exisiting, see above
		
		obj.parent_div = obj; 
		while (obj.parent_div.tagName!='DIV') { //iterate up to find div container for obj. if obj is a div, stops here
			obj.parent_div= obj.parent_div.parentNode;
		}
		obj.parent_id = obj.parent_div.getAttribute('id');
		return obj.parent_id;
	}
}

function menu_div(obj) {
	if (obj && obj.tagName!="HTML") { //Need HTML exception otherwise error when going from rollover out to background
		parent_id(obj); //sets up .parent_div as first containing div - should be img holder
		var id =obj.parent_div.parentNode.id; //next up should be menu container
		obj.menu_div= obj.parent_div.parentNode;
		return obj.menu_div;
	}
}

function write_to_children(element, Default) {
	var aChildren = new Array();
	aChildren = element.childNodes;
	for (var x = 0; x< aChildren.length; x++) {   // write "menu" attribute to all but the default over item
		if (aChildren[x].nodeType == 1 && aChildren[x]!=Default ) aChildren[x].menu = parent_id(Default); //menu = id of default over 
		if (aChildren[x].hasChildNodes) write_to_children(aChildren[x], Default)
	}
}



SafeAddOnload(initRollovers);


