// 2005-08-31, tom:
// simple navigation module
// hover effect via proprietary attributes osrc (original/inactive source) and hsrc (hover source) in img
// unique id for img, divs with subelements 

//test css mode
//javascript:alert(document.compatMode);

var activeId = null; //active navigation image
var openBranch = null; //currently open branch
var rollOver = false; //inactive

// DOM image rollover and mousedown
function initNavi() {
//	if (!document.getElementById) return;
//	var currEl;
//	var imgTemp = new Array();
//	var imgArr = document.getElementsByTagName('img');
//	for (var i = 0; i < imgArr.length; i++) {
//		if (imgArr[i].getAttribute('hsrc')) {
//			imgTemp[i] = new Image();
//			imgTemp[i].src = imgArr[i].getAttribute('hsrc');
//			imgArr[i].onmouseover = function() {
//				if (rollOver) this.setAttribute('src',this.getAttribute('hsrc'));
//			}
//			imgArr[i].onmouseout = function() {
//				//hover off only if not active
//				if (activeId != this.id && rollOver) this.setAttribute('src',this.getAttribute('osrc')); 
//			}
//			imgArr[i].onmousedown = function() {
//				//alert("aId: " + activeId);
//				if (activeId != null) {
//					if (activeId.indexOf(",") == -1) {
//						document.getElementById(activeId).setAttribute('src',document.getElementById(activeId).getAttribute('osrc'));
//					} else {
//						//if we have more than one active element (from loading init)
//						var lActiveIds = activeId.split(",");
//						for (var i = 0; i < lActiveIds.length; i++) {
//							//reset all active elements
//							document.getElementById(lActiveIds[i]).setAttribute('src',document.getElementById(lActiveIds[i]).getAttribute('osrc'));
//						}
//					}
//				}
//				activeId = this.id;
//				this.setAttribute('src',this.getAttribute('hsrc'));
//			}
//    	}
//	}
}

// branch toggle
function toggle(node) {
	if (node == null) {
		if (openBranch != null) document.getElementById(openBranch).style.display = 'none';
		return;
	}
	var parentEl;
	var parentDiv = node.parentNode;
	parentEl = node.parentNode;
	//avoid getting text nodes (white spaces) on FF etc. 
	if (parentDiv.nextSibling.nodeName == '#text') parentDiv = parentDiv.nextSibling;
	var nextDiv = parentDiv.nextSibling;
	
	// home area
	document.getElementById('main_accueil').setAttribute("class","mainNavi");
	document.getElementById('accueil').setAttribute("class","mainNavi");
	document.getElementById('main_accueil').setAttribute("className","mainNavi");
	document.getElementById('accueil').setAttribute("className","mainNavi");
	
	// sample request
	if(document.getElementById('main_samplerequest') && document.getElementById('samplerequest')){
	    document.getElementById('main_samplerequest').setAttribute("class","mainNavi");
	    document.getElementById('samplerequest').setAttribute("class","mainNavi");
	    document.getElementById('main_samplerequest').setAttribute("className","mainNavi");
	    document.getElementById('samplerequest').setAttribute("className","mainNavi");
    }
	
	// sitemap area
	document.getElementById('main_plansite').setAttribute("class","mainNavi");
	document.getElementById('plansite').setAttribute("class","mainNavi");
	document.getElementById('main_plansite').setAttribute("className","mainNavi");
	document.getElementById('plansite').setAttribute("className","mainNavi");
	
	//unfold the branch if it isn't visible	
	if (nextDiv.style.display == 'none') {
		// close other open branch
		if (openBranch != null) {
		    document.getElementById(openBranch).style.display = 'none';
		    if (document.getElementById(openBranch.replace("sub","main"))) {
		        document.getElementById(openBranch.replace("sub","main")).setAttribute("class","mainNavi");
		        // for IE - bug
		        document.getElementById(openBranch.replace("sub","main")).setAttribute("className","mainNavi");
		        
		        // different areas
		        document.getElementById("apropos").setAttribute("class","mainNavi");
		        document.getElementById("assistance").setAttribute("class","mainNavi");
		        document.getElementById("produits").setAttribute("class","mainNavi");
		        document.getElementById("actualites").setAttribute("class","mainNavi");
		        document.getElementById("apropos").setAttribute("className","mainNavi");
		        document.getElementById("assistance").setAttribute("className","mainNavi");
		        document.getElementById("produits").setAttribute("className","mainNavi");
		        document.getElementById("actualites").setAttribute("className","mainNavi");
		    }
		}
		nextDiv.style.display = 'block';
		openBranch = nextDiv.id; //store open branch
			
	    node.setAttribute('class','mainNaviActive');
	    parentEl.setAttribute('class','mainNaviActive');
	    // for IE - bug
	    node.setAttribute('className','mainNaviActive');
	    parentEl.setAttribute('className','mainNaviActive');
	    
	    
	} else {
		nextDiv.style.display = 'none';
		openBranch = nextDiv.id; //clear open branch
	}
}

function setActive(ids) {
	if (!ids) {
		//try to get the current productgroup/navigation from the script generated by product header (xsl)
		if (categoryGroup) ids = "produits," + categoryGroup;
	}
	
	var currEl, parentEl, baseLinkCSS, baseDivCSS;
	var activeIds = ids.split(",");
	var gActiveIds = new Array();
	var globalActiveId = "";
	for (var i = 0; i < activeIds.length; i++) {
		gActiveIds[gActiveIds.length] = activeIds[i];
		currEl = document.getElementById(activeIds[i]);
		//alert(activeIds[i] + ", " + currEl);
		parentEl = currEl.parentNode;
		
		if (currEl == undefined) continue;
		if (currEl && currEl.getAttribute("submenue") && currEl.getAttribute("submenue") == "true") {
			toggle(currEl);
		}
	        
        currEl.setAttribute("class",currEl.getAttribute("class") + "Active");
        parentEl.setAttribute("class",parentEl.getAttribute("class") + "Active");
        // for IE - bug
        currEl.setAttribute("className",currEl.getAttribute("className") + "Active");
        parentEl.setAttribute("className",parentEl.getAttribute("className") + "Active");
	}
	activeId = gActiveIds.join(",");
	//alert(activeId);
}

	function switchPortal(val) {
		var defaultLang = "1";
		var url = "";
		if (val.length == 0) { return false; } /* don't do anything if no option selected */
		switch (val) {
			case "fl":
				defaultLang = "1"; //keep the current language
				break;
			case "uk":
				defaultLang = "1";
				break;
			case "us":
				defaultLang = "1";
				break;
			case "de":
				defaultLang = "0";
				break;
			case "ch":
				defaultLang = "0";
				break;
			case "jp":
				defaultLang = "3";
				break;
		}
		if (val == "fr") url = "/"; // French portal main page
		if (val != "fr") url = "http://www.neutrik.com/content/home/home.aspx?portal=" + val + "&language=" + defaultLang;
		document.location.href = url; // redirection
	}
	
	var currImg = -1;
	var delay = 4000; //time delay for banner rotation (ms)
	var imgPath = "";
	function startBannerRotator() {
	    if (blnBanner) { //check if image array is given (not flash)
		    if (bannerImg.length > 0) {
			    bannerRotator(currImg);
		    }
		}
	}
	
	function bannerRotator() {
		if (!document.getElementById) return;
		var imgObj = document.getElementById("bannerImg");
		var urlObj = document.getElementById("bannerUrl");
		currImg++; //next pic
		if (currImg >= bannerImg.length) currImg = 0;
		//alert(bannerImg[currImg]);
		imgObj.setAttribute("src",imgPath + bannerImg[currImg]);
		//ie only
		if (document.all) {
			imgObj.filters.blendTrans.Apply();
			imgObj.filters.blendTrans.Play();
		}
		urlObj.setAttribute("href", bannerUrl[currImg]);
		// rotate if more than 1 image available
		if (bannerImg.length > 1) setTimeout("bannerRotator()",delay);
	}
	
	//2007-01-16, tom: fairrank modification
    function mehr(id) {
        document.getElementById(id).style.display = "block";
    }
    function weniger(id) {
        document.getElementById(id).style.display = "none";
    }
	
	
	
// ######################################################################## \\
// Content added by Justin

function client_window_height() {
	if (typeof(window.innerHeight) == 'number') {
	// pour la plupart des navigateurs récents (sauf IExplorer)
		hauteurAffichage = window.innerHeight;
	}
	else {
	// autres navigateurs utilisant des méthodes différentes pour retourner la taille d'affichage
		if (document.documentElement && document.documentElement.clientHeight) {
		// avec la propriété clientWidth de l'objet documentElement
			hauteurAffichage = document.documentElement.clientHeight;
		}
		else if (document.body && document.body.clientHeight) {
		// avec la propriété clientWidth de l'objet body
			hauteurAffichage = document.body.clientHeight;
		}
	}
	return hauteurAffichage; // retourne la largeur de l'affichage dans le navigateur du client
}

function client_window_width() {
	if (typeof(window.innerWidth) == 'number') {
	// pour la plupart des navigateurs récents (sauf IExplorer)
		largeurAffichage = window.innerWidth;
	}
	else {
	// autres navigateurs utilisant des méthodes différentes pour retourner la taille d'affichage
		if (document.documentElement && document.documentElement.clientWidth) {
		// avec la propriété clientWidth de l'objet documentElement
			largeurAffichage = document.documentElement.clientWidth;
		}
		else if (document.body && document.body.clientWidth) {
		// avec la propriété clientWidth de l'objet body
			largeurAffichage = document.body.clientWidth;
		}
	}
	return largeurAffichage; // retourne la largeur de l'affichage dans le navigateur du client
}

function try_to_fix_menu() {
	if (client_window_height() > 560 && client_window_width() > 900) {
		// fix menu
		// the navigation menu becomes fixed if Javascript is enabled, height is > 600px, and width is > 900px
		document.getElementById("allMenuBar").style.position = "fixed";
	}
	// otherwise the menu must stay in an absolute position
	else {
		// unfix menu
		document.getElementById("allMenuBar").style.position = "absolute";
	}
}

function alert_loading(elementId, boolStatus) {
	if (boolStatus) { document.getElementById(elementId).style.display = "block"; }
	//else { document.getElementById(elementId).style.display = "none"; }
}

// fonction de masquage / affichage de la boîte de dialogue du catalogue
function hide_help_box() {
	boxDisplay = document.getElementById("catalogHelpBox").style.display;
	if (boxDisplay == "block" || boxDisplay.length == 0) {
		document.getElementById("catalogHelpBox").style.display = "none";
		document.getElementById("catalogHelpMinimized").style.display = "block";
	}
	else {
		document.getElementById("catalogHelpBox").style.display = "block";
		document.getElementById("catalogHelpMinimized").style.display = "none";
	}
}
