function isdefined( variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}

var previous_parent_nav_id = "";
var set_menu_timeout;
var set_previous_nav_uid = "";
var bln_first_item_active = false;  
var current_nav_item = "";
var str_active_child_uid = "";
var str_last_active_subnav = "";
var str_set_back_to_white = "";
var str_first_child_item = "";
//var str_img_navigation_off_state; SET IN HEADER

  
function turnOffNavigationTimeout() {  
	clearTimeout(set_menu_timeout);
}

function turnOnNavigationTimeout() {
	set_menu_timeout = setTimeout("hideActiveNavigationItem()", 600);	
}




function fetchSubNavigationContent(position, id, first_child_item, is_ie6) {
	if (ee(id)) {
		
		//If the highlighted nav isn't the active section then set the text colour back to it's original colour
		if (str_active_sub_nav != id) {
			if (ee('nav-parent-' + str_temp_section)) {
				ee('nav-parent-' + str_temp_section).style.color='';
			}		
		}
		
		if(str_set_back_to_white) {
			str_set_back_to_white.style.color='';
		}
		
		
		
		if (ee("parent-navigation-background")) {
			ee("parent-navigation-background").height='44';
			switch(position)
			{
			case 1:
			  ee("parent-navigation-background").src = 'Images/navigation-living-here-on.jpg';
			  break;    
			case 2:
			  ee("parent-navigation-background").src = 'Images/navigation-commercial-business-on.jpg';
			  break;
			case 3:
			  ee("parent-navigation-background").src = 'Images/navigation-city-map-on.jpg';
			  break;
			case 4:
			  ee("parent-navigation-background").src = 'Images/navigation-about-springfield-on.jpg';
			  break;
			default:
			}
			clearTimeout(set_menu_timeout);	
		}

		current_nav_item = id;
		clearTimeout(set_menu_timeout);
		
		if (ee(previous_parent_nav_id)) {
			ee(previous_parent_nav_id).style.display="none";
		}
		ee(id).style.display="block";
		
		
		
		if (ee(id + "-" + first_child_item)) {
			
			
			if (ee(str_last_active_subnav)) {
				ee(str_last_active_subnav).style.display ="none";
			}
			
			ee(id + "-" + first_child_item).style.display="block";
			str_last_active_subnav = id + "-" + first_child_item;
			
			
			
			

				if (ee(id + "-" + first_child_item + "-link")) {
					ee(id + "-" + first_child_item + "-link").className='sub-nav-item-on';
					str_first_child_item = id + "-" + first_child_item + "-link";
				}

			
		}
		previous_parent_nav_id = id;	
	}
}

function hideActiveNavigationItem() {
	if (ee(set_previous_nav_uid)) {
		ee(set_previous_nav_uid).style.display="none";
		ee("parent-navigation-background").src = str_img_navigation_off_state;
		ee("parent-navigation-background").height = '36';
		
		if (ee('nav-parent-' + str_temp_section)) {
			ee('nav-parent-' + str_temp_section).style.color='white';
		}
		var temp_id = 'nav-parent-' + str_temp_section;
		if (temp_id != str_set_back_to_white.id) {
			str_set_back_to_white.style.color='';
		}
	}
}	


function closeSubNavigationContent(id, obj) {
	if (ee(id)) {

		str_set_back_to_white = obj;  
		
		turnOnNavigationTimeout();
		set_previous_nav_uid = id; 

	}
}




function showSubNavigationContent(id) {
	
	if (isdefined("set_menu_timeout") == true) {
		clearTimeout(set_menu_timeout);
	}
	
	if (isdefined("set_activeChild_timeout") == true) {
		clearTimeout(set_activeChild_timeout);
	}
	
	
	if (ee(str_last_active_subnav)) {
			ee(str_last_active_subnav).style.display ="none";
	
	}
	
	if (ee(id)) {
		
		
	
	if (ee(id + "-link")) {
		if (ee(str_first_child_item)) {
			ee(str_first_child_item).className='sub-nav-item-off';
		}
		ee(id + "-link").className = 'sub-nav-item-on';
	}
	
		
		ee(id).style.display="block";
		str_last_active_subnav = id;
		
	}
}

function turnOffActiveIcon(obj) {
	if (ee(str_last_active_subnav + "-link")) {
		ee(str_last_active_subnav + "-link").className='sub-nav-item-off';
	}
}


function resetToActiveChild() {
	if (ee(str_this_child_page)) {
		ee(str_this_child_page).className = 'sub-nav-item-on';
		id = str_this_child_page.split("-link").join("");
		showSubNavigationContent(id);
	}
}

function turnOnActiveNavImage(section) {
	ee("parent-navigation-background").src = 'Images/navigation-' + section + '-on.jpg';
}

