// Secondary Navigation for PANTONE Global Build 2006
// Created by James Gibbs on 17th August 2006 @ 13:15
// This file provides the Javascript functions for the tree structure navigation to work Client-side

// Main Method
function showBranch(area,id,color){
	//area, eg 'prod' or 'page'
	//id, eg '1' or '28'
	var newBranch = area + id
	hideAllBranches(area);
	openBranch(area,id,newBranch,color);
}

//Sub Method
function hideAllBranches(area){
	var menuExists = true;
	var i = 0;
	do{
		if(document.getElementById(area + i) == null){
			menuExists = false;
		} else {
			hideBranch(area+i);
			showCollapsedBranch(area,i);
			showBranchHeader(area,i);
			i = i + 1;
		}
	} while (menuExists == true)
}

// Normal Branch Functions
function hideBranch(branchName){
	if(document.getElementById(branchName) != null){
		document.getElementById(branchName).style.display='none';	
	}
}

function openBranch(area,id,newBranch,color){
    //alert(area+id)
	closeCollapsedBranch(area,id);
	if (color != null && color != "") {
	    document.getElementById("imgMyPantone").src = "../../images/myPantone/logos/logo_" + color + ".gif";
	    sElement = setHTML(color,area,id);
	    closeBranchHeader(area,id)
	}else{
	    //document.getElementById("imgMyPantone").src = "../../images/myPantone/logos/logo_66CCCC.gif";
	    sElement = area+id
	}
	if (sElement != "") {
	    if(document.getElementById(sElement) != null){
	        document.getElementById(sElement).style.display='block';
	    }
	}
}

// Collapsed Branch Functions
function closeCollapsedBranch(area,id){
    //alert("Area: " + area + ", id = " + id);
    if(document.getElementById(area + 'show' + id) != null){
	    document.getElementById(area + 'show' + id).style.display='none';
	}
}

function showCollapsedBranch(area,id){
    if(document.getElementById(area + 'show' + id) != null){
	    document.getElementById(area + 'show' + id).style.display='block';	
	}
}

function showBranchHeader(area,id){
    var sElement = area+'Header'+id
	if (document.getElementById(sElement) != null) {
	    document.getElementById(area + 'Header' + id).style.display='block';
	}	
}

function closeBranchHeader(area,id){
    var sElement = area+'Header'+id
	if (document.getElementById(sElement) != null) {
	    document.getElementById(area + 'Header' + id).style.display='none';
	}
}

function setHTML(color,area,id){
    sElement = "selectedContent"
    document.getElementById(sElement).innerHTML = "";
    
    sHTML = "<img src='../../images/categories/sub_nav_colours/" + color + ".gif' height='11' width='190' /><ul>"
    sHTML += document.getElementById(area+id).innerHTML
    sHTML += "</ul>"
    document.getElementById(sElement).innerHTML = sHTML;
    document.getElementById(sElement).style.borderBottom='solid #' + color + ' 3px;';
    return sElement
}