//** menu_timer is the global variable that is used to hold the value
//** of the window managed time interval

var menu_timer;

var video_timer;

//** menu delay is the number of milliseconds to wait after mouseout
//** before removing the menu from visibility

var menu_delay = 200;

var cssmenudebug = false;

//** This is a debugging function
//** NOTE : This function seems to sooth IE
function updateStatus() {

	var twin = document.getElementById("test_window");
	if (cssmenudebug) twin.style.visibility = "visible";
	
	var thesemenus = getCSSMenus();
	if (thesemenus) {
		var dispText = "Updating Menus...( " + updateStatus.caller + " )...<br>";
		for (var i in thesemenus) {
			var thisElem = document.getElementById(thesemenus[i]);
			if (thisElem) dispText += thesemenus[i] + " - " + thisElem.style.visibility + " - " + thisElem.style.visibility + "<br>";	
		}//** end for
	}//** end if divs

	twin.innerHTML = dispText;

}//** end js function


//** function show_menu shows the menu defined in menu_tag
//** Procedure:
//** Cancel any existing timeout object to prevent menu from being hidden inadvertantly
//** Set the menu visibility property to a value of 'hidden'
//** Hide any other menus

function show_menu(menu_tag) {
	
	hide_others(menu_tag);
	window.clearTimeout(menu_timer);
	
	if (menu_tag.indexOf("_") == -1) {
		window.clearTimeout(video_timer);
		showEmbObjs();
	}

	var thisMenu = document.getElementById(menu_tag + "_menu");
	
	if (thisMenu && thisMenu.style.visibility != "visible") {

		if (thisMenu.style.display != "block") thisMenu.style.display = "block";
		thisMenu.style.visibility = "visible";
		
		video_timer = window.setTimeout("hideEmbObjs();",100);

	}//** end if

	updateStatus();

}//** end js function

//** function hide_menu hides the menu defined in menu_tag
//** Procedure:
//** Set timeout to hide the object in future
//** This gives the user a chance to mouseover 
//** sub menus without losing the parent

function hide_menu(menu_tag) {

	var to_string = "hide_menu_now(\"" + menu_tag + "\");hide_children(\"" + menu_tag + "\");hide_parents(\"" + menu_tag + "\");showEmbObjs();";
	menu_timer = window.setTimeout(to_string,menu_delay);

	

}//** end js function

//** function hide_menu_now immediately hides the menu defined in menu_tag
//** Procedure:
//** If the element with the id [menu_tag]_tag exists,
//** set the visibility to 'hidden'

function hide_menu_now(menu_tag) {
	
	window.clearTimeout(video_timer);

	if ( document.getElementById(menu_tag  + "_menu") ) {
		var thisMenu = document.getElementById(menu_tag  + "_menu");
		if (thisMenu.style.display != "none") thisMenu.style.display = "none";
		if (thisMenu.style.visibility != "hidden") thisMenu.style.visibility = "hidden";
	}

	if (cssmenudebug) updateStatus();

}//** end js function

/*function hideVideo() {

	var obem = getEmbeds();

	for (var i in obem) {

		if (obem[i].style) obem[i].style.visibility = "hidden";
		
	}

}*/

/*function restoreVideo() {

	var obem = getEmbeds();

	for (var i in obem) {
		if (obem[i].style) obem[i].style.visibility = "visible";
	}

}*/

//** function hide_others() hides all menus
//** beside the tagged menu and its ancestry

function hide_others(menu_tag) {

	var myancestors = new Array();
	var lineage = menu_tag.split("_");
	var parent_tag = lineage[0];
	
	for (var i = 0 ; i < lineage.length ; i++ ) {
		
		myancestors[i] = (i == 0) ? lineage[i] : myancestors[i - 1] + "_" + lineage[i] ;
		
	}//** end for

	var thesemenus = getCSSMenus();

	if (thesemenus) {

		for (var key in thesemenus ) {

			if (thesemenus[key].substr){
				var tagLength = thesemenus[key].length - 5;			
				var loopTag = thesemenus[key].substr(0,tagLength);
				var hideLoop = true;

				for (var j = 0 ; j < myancestors.length ; j++ ) {
					
					if ( loopTag == myancestors[j] ) hideLoop = false;

				}//** end loop through ancestors
							
				if (hideLoop) {

					hide_menu_now(loopTag);

				}//** end if

			}//** end if

		}//** end for menus

	}//** end if menus

}//** end js function

function hide_children(menu_tag) {

	var thesemenus = getCSSMenus();
	if (thesemenus) {
		
		for (var i = 0 ; i < thesemenus.length ; i++ ) {

			var loopMenu = thesemenus[i];

			if (loopMenu.indexOf(menu_tag) == 0) {
	
				var tagLength = loopMenu.length - 5;				
				var tempTag = loopMenu.substr(0,tagLength);
				if (tempTag != menu_tag) hide_menu_now(tempTag);
			
			}

		}//** end for divs

	}//** end if divs

}//** end js function

function hide_parents(menu_tag) {
	
	var lineage = menu_tag.split("_");
	var parent_tag = lineage[0];
	
	if (parent_tag != menu_tag) hide_menu_now(parent_tag);
	hide_children(parent_tag);

}//** end js function

function getCSSMenus() {

	var divs = document.getElementsByTagName("div");

	if (divs) {
		
		var ret = new Array();

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

			var loopId = divs[i].id;
			var tagLength = loopId.length - 5;	
			
			if (loopId.indexOf("_menu") != tagLength) continue;
			else {
				ret.push(loopId);
			}//** end if/else
			
		}//** end for divs

	} else var ret = false;

	return ret;

}//** end function

/*function getEmbeds() {

	var embs = new Array();
	var os = document.getElementsByTagName("OBJECT");
	var es = document.getElementsByTagName("EMBED");
	var sp = document.getElementsByTagName("SPAN");

	if (sp.length > 0) for (var si in sp) {

		if (sp[si].className == "scs_hidelayer") {

			if (sp[si].childNodes){

				for (var nd in sp[si].childNodes) { 

					if (
						(es.length == 0 && sp[si].childNodes[nd].nodeType == 1 && sp[si].childNodes[nd].tagName == "OBJECT")
					) {
						
						var newObjectIndex = os.length;
						sp[si].childNodes[nd].hideme = true;
						os[newObjectIndex] = sp[si].childNodes[nd];

					} else if (
						es.length > 0 && sp[si].childNodes[nd].nodeType == 1 && sp[si].childNodes[nd].tagName == "OBJECT"
					) {
					
						
						var theseEmbeds = sp[si].childNodes[nd].getElementsByTagName("EMBED");
						if (theseEmbeds.length > 0) {
							var newEmbedIndex = es.length;
							theseEmbeds[0].hideme = true;
							es[newEmbedIndex] = theseEmbeds[0];
							break;
						}
							
					}//** end if child node is an OBJECT element	
				
				}//** end for each child

			}//** end if there are children

		}//** end if class name = hidelayer

	}//** end if sp.length > 0
	if (os.length > 0) for (var oi in os) embs.push(os[oi]);
	if (es.length > 0) for (var ei in es) {if (es[ei].tagName == "EMBED") embs.push(es[ei]);}
	

	var ret = new Array();

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

		var skip = false;

		if (embs[i].hideme != true) {

			if (embs[i].tagName == "OBJECT") {
				if (embs[i].childNodes) var params = embs[i].childNodes;
				else {
					var params = null;
					continue;
				}

				for (var p = 0; p < params.length; p++) {
				
					if (
						( params[p].tagName == "PARAM") && 
						( params[p].name.toLowerCase() == "movie" || params[p].name.toLowerCase() == "filename" ) && 
						( params[p].value.indexOf("oascentral") != -1 || params[p].value.indexOf("https://www.santacruztoday.com/openads/") != -1)
						
					) {
						skip = true;
						break;
					}

				}

			} else {

				if (embs[i].src && embs[i].src.indexOf("https://www.santacruztoday.com/openads/") != -1) {
						skip = true;
						break;				
				}

			}
	
		}

		if (!skip && embs[i].className != "scs_static_flash") {
			ret.push(embs[i]);
		}

	}

	return ret;

}//** end js function
*/

//** REVISION BY PMC 2/14/2007

var scs_embobjs = new Array();

function setEmbObjs() {

	if (document.getElementsByTagName) {

		var objElems = document.getElementsByTagName("OBJECT");
		var embElems = document.getElementsByTagName("EMBED");

		var tempObjs = (embElems.length > 0) ? embElems : objElems ;

		if (tempObjs.length > 0) {

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

				if (tempObjs[i] && tempObjs[i].style) {

					var thisParent = (tempObjs[i].tagName == "EMBED") ? tempObjs[i].parentNode : tempObjs[i] ;
					if (thisParent && thisParent.className == "scs_static_flash") continue;
					var params = tempObjs[i].getElementsByTagName("PARAM");
					for (var j = 0; j < params.length; j++) { if (params[j].name.toLowerCase() == "movie") {var movieParam = params[j]; break;}}
					var thisSrc = (params && params.length > 0) ? movieParam.value : tempObjs[i].src ; 
					//if (thisSrc.indexOf("https://www.santacruztoday.com/openads/") != -1) continue;
					scs_embobjs.push(tempObjs[i]);

				}//** end if object/embed has a style

			}//**end loop through scs_embobjs

		}//** end if there are object/embed elements in the document
		
	} else return false;

}//** end js function 2/14/2007

function hideEmbObjs() {

	for (var i = 0; i < scs_embobjs.length ; i++ ) {
		//if (scs_embobjs[i].style.zIndex) alert(scs_embobjs[i].style.zIndex);
		scs_embobjs[i].style.zIndex = 0;
		scs_embobjs[i].style.visbility = "hidden";
	}

}//** end js function 2/14/2007

function showEmbObjs() {
	if (scs_embobjs.length == 0) setEmbObjs();
	for (var i = 0; i < scs_embobjs.length ; i++ ) {
		scs_embobjs[i].style.visbility = "visible";
	}
}//** end js function 2/14/2007

window.onload = setEmbObjs;

//** END REVISION 2/14/2007

function in_array(needle,haystack) {

	for (var i in haystack) {

		if (haystack[i] == needle) return true;

	}

	return false;

}//** end js function