/* mouse over hover for primary navigation images */
function pnavMouseOver(id) {
	var oimg = document.getElementById(id);
	if (oimg) {
		if (oimg.src.search(/grey.gif/i) >= 0) {
			oimg.srcori = oimg.src;		// save original image url in (new) custom attribute
			oimg.src = oimg.src.replace(/grey.gif/i, 'red.gif');
		}
	}
}

function pnavMouseOut(id) {
	var oimg = document.getElementById(id);
	if (oimg) {
		if (oimg.srcori) {
			oimg.src = oimg.srcori;		// reset to original url if it has changed
		}
	}
}

/* Dynamically highlight current navigation elements by page context */
function initPnav() {
	
	// primary navigation is a fixed map of folder areas
	surl = window.location.href.toLowerCase();
	
	if (surl.indexOf('/02archiv') >= 0) {
		obj=document.getElementById("pnav-archiv");
		if (obj) obj.src = obj.src.replace(/grey.gif/i, 'red.gif');
	} else if (surl.indexOf('/08premium') >= 0) {
		obj=document.getElementById("pnav-abo");
		if (obj) obj.src = obj.src.replace(/grey.gif/i, 'red.gif');
	} else if (surl.indexOf('/05media') >= 0) {
		obj=document.getElementById("pnav-media");
		if (obj) obj.src = obj.src.replace(/grey.gif/i, 'red.gif');
	}  else if (surl.indexOf('sfsg.asp') >= 0 || surl.indexOf('index_fsg.asp') >= 0 || surl.indexOf('/festspiele') >= 0) {
		obj=document.getElementById("pnav-festspiele");
		if (obj) obj.src = obj.src.replace(/grey.gif/i, 'red.gif');
	}
	
	// Note: "current" and "issue" selection is done in snav intialization (s. initSnav() )
}

function initSnav() {
	// navigation is initialized based on document.location (current url)
	
	// (i) dynamic navigation: try to find current blog entry in navigation
	var prmP, prmCAT;
	qry = window.location.search; qry = qry.replace(/\?/,""); 
	qryprm = qry.split("&");
	for (i=0;i<qryprm.length;i++) {
		if (qryprm[i].split("=")[0] == 'p') {
			prmP = qryprm[i].split("=")[1];
		} else if (qryprm[i].split("=")[0] == 'cat') {
			prmCAT = qryprm[i].split("=")[1];
		}
	}
	
	// (i.1) find blog entry - "current","issue"
	var bCurrent = false, bIssue = false; bElse = false;		// Flag - is "current" or "issue" nav selected - propagate selection to pnav
	if (prmP) {
		obj=document.getElementById("current_" + prmP)
		if (obj) { 
			obj.style.color = '#BC070F';
			// obj.style.setProperty('color','#BC070F', null);	// does not work in IE - thank you, bill !
			obj=document.getElementById("current");
			if (obj) obj.style.color = '#BC070F';
			bCurrent = true;
		}
		obj=document.getElementById("issue_" + prmP)
		if (obj) { 
			obj.style.color = '#BC070F';
			obj=document.getElementById("issue");
			if (obj) obj.style.color = '#BC070F';
			bIssue = true;
		}
	}
	
	// (i.2) find catgeory entry - "cat"
	if (prmCAT) {
		obj=document.getElementById("cat_" + prmCAT)
		if (obj) { 
			obj.style.color = '#BC070F';
			obj=document.getElementById("cat");
			if (obj) obj.style.color = '#BC070F';
			if (obj.id && obj.id.substring(0, 5) == 'issue') bIssue = true;
		}
	}

	// (ii) static navigation: try to find location in href definition
	surl = window.location.href.toLowerCase();
	arym = new Array ('current', 'issue', 'cat', 'service', 'media', 'calendar', 'ort');
	for (i=0;i<arym.length;i++) {
		for (j=0;j<20;j++) {
			if (j == 0) {
				// main-entry secnav element
				obj=document.getElementById(arym[i])
			} else {
				// sub-entry secnav element
				obj=document.getElementById(arym[i] + "_m" + j)
			}
			if (obj && obj.href) {
				// on static page areas, we only work with the pathname - in blog area the whole url has to match
				if (surl.indexOf('/blog/') < 0 && surl.indexOf('/sfsg.asp') < 0) shref = obj.href.split("?")[0]; else shref = obj.href;
		
				// if (shref.charAt(shref.length - 1) != '/' && shref.lastIndexOf('/') > 0) {
					// we strip the file name of the href to only compare folder areas (therefore not every file in folder must exist in navigation as a definition)
				//	shref = shref.substring(0, shref.lastIndexOf('/'));
				//}
				if (surl.indexOf(shref.toLowerCase()) >= 0) {
					obj.style.color = '#BC070F';
					obj=document.getElementById(arym[i]);	// also highlight main navigation element
					if (obj) obj.style.color = '#BC070F';

					if (obj.id && obj.id.substring(0, 7) == 'current') { 
						bCurrent = true; 
					} else if (obj.id && obj.id.substring(0, 5) == 'issue') { 
						bIssue = true; 
					} else {
						bElse = true;
					}
				}
			} else {
				// manual link definition have to be in consecutive order
				break;
			}
		}
	}
	
	// pnav: "current" and "issue" pnav elements are set corresponding to their snav selection
	if (!bElse) {
		if (bCurrent || surl.substr(surl.length - 6 , 6) == '/blog/') {
			// pnav
			obj=document.getElementById("pnav-aktuell");
			if (obj) obj.src = obj.src.replace(/grey.gif/i, 'red.gif');
			
			// snav
			obj=document.getElementById("current");
			if (obj) obj.style.color = '#BC070F';
		} else if (bIssue) {
			// pnav
			obj=document.getElementById("pnav-magazin");
			if (obj) obj.src = obj.src.replace(/grey.gif/i, 'red.gif');
			
			// snav
			obj=document.getElementById("issue");
			if (obj) obj.style.color = '#BC070F';
		}
	}
	
}

