// 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);
			
			//CJ 11.29.07 - lets hide items if its not selected from the menu them
			if ((area == "page") && (isMYP() == 1))
			{
			    document.getElementById(i).style.display = 'none';
			}
			
			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){
	closeCollapsedBranch(area,id);
	
	//CJ 11/29/2007 - fix for tips + techinques
	if (id==-1)
	{
	    color = "FFFFFF";
	}
	
	if (color != null && color != "") {
	    if (document.getElementById("imgMyPantone") != null)
	    {
	        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 isMYP()
{
    var iRtn = 0;
    var sURL = location.href;
    if ((sURL.indexOf("MYP_") > -1) || (sURL.indexOf("myp_") > -1))
    {
        iRtn = 1;
    }    

    return iRtn;
}

function setHTML(color,area,id){
   
    sElement = "selectedContent"
    document.getElementById(sElement).innerHTML = "";
    
    // ************************************************************************     
    // *** CJ 10/12/2007 - updated for new myPANTONE.  If within new myPANTONE
    // *** site,we remove  color from top and bottom of the header bars
    // ************************************************************************
    var sURL = location.href;
    var sHTML = "";
    var iMyPantone  = 0;
    var sHTMLBottom = "";

    //CJ 11/29/2007 - fix for tips + techinques
    if (id == -1)
    {
        id = 0;
    }
        
    var oHeader = document.getElementById("header"+id);
    
    if (isMYP() == 1)
    {
        iMyPantone = 1;
    }   
    
    if (iMyPantone == 0)
    {
        sHTML = "<img src='../../images/categories/sub_nav_colours/" + color + ".gif' height='11' width='190' />"
        document.getElementById(sElement).style.borderBottom='solid #' + color + ' 3px;';
    }
    else
    {
        sHTMLBottom = "<br><br>";
        oHeader.style.fontWeight="bolder";
        
    }
        
    sHTML += "<ul>"    
    sHTML += document.getElementById(area+id).innerHTML
    sHTML += "</ul>"
    sHTML += sHTMLBottom;
    
    document.getElementById(sElement).innerHTML = sHTML;
    
    return sElement
}