/* 
-------------------------------------------------------
| controls the rollover functionality for the top nav |
-------------------------------------------------------
Might be better to change the style settings to a call
to change the style from the stylesheet.*/

// global variables ==================================//

var subnavs = 6; // change this if you need more primary menu sections


//===================================================//
function RollOver(nIndex){
    /* hides all subnavs, then shows the wanted subnav */
	/*-------------------------------------------------*/
    
	var change_id = 'NavDiv' + nIndex;
	var change_prime_id = 'primeItem' + nIndex;
	
   	/* for all sublists, hide and then set the prinav element to white background */
    for(i=1; i<=subnavs; i++){
        
        var close_id='NavDiv' + i;
        var close_prime_id = 'primeItem' + i;
        
        if 	(testForObject(close_id)){
	        document.getElementById(close_id).style.visibility = 'hidden';
	        document.getElementById(close_id).style.display = 'none';
	        }
	    document.getElementById(close_prime_id).style.background = '#ffffff';
		}

	// display the correct sub menu only
    if 	(testForObject(change_id)){
	    document.getElementById(change_id).style.visibility = 'visible';
	    document.getElementById(change_id).style.display = 'inline';
	    }
		
	// turns the relevant primary nav grey
	document.getElementById(change_prime_id).style.background = '#e6e6e3';
    }
    
	
function RollOff(nIndex){
    /* hides only the specified subnav and tuns the privav element back to white too */
	/*-------------------------------------------------*/
    
	var close_id = 'NavDiv' + nIndex;
	var close_prime_id = 'primeItem' + nIndex;
	
	if 	(testForObject(close_id)){
		document.getElementById(close_id).style.visibility = 'hidden';
	    document.getElementById(close_id).style.display = 'none';
		}
   	document.getElementById(close_prime_id).style.background = '#ffffff';
    } 
    
	
function RollOffPrimary(nIndex){
    /* hides all sublists, and turn the header of the section you rolled off back to white 
	if we're highlighting the page we're on, then we'll need to turn that back on at the 
	end of this function - as if you roll out of that section, it will turn white, not
	allowing the initial page state to be preserved. */
	/*-------------------------------------------------*/
	
	var close_prime_id = 'primeItem' + nIndex;
	
	for(i=1; i<=subnavs; i++){
    	var close_id='NavDiv' + i;
        if 	(testForObject(close_id)){
        	document.getElementById(close_id).style.visibility = 'hidden';
        	document.getElementById(close_id).style.display = 'none';
        	}
		}
	document.getElementById(close_prime_id).style.background = '#ffffff';
	}
	
	
function testForObject(id){
    /*Tests to see if an object exists, prevents object not found
    errors when the sub menu isn't present. */
	/*-------------------------------------------------*/
    
    var chk = document.getElementById(id);
    if (chk){ return chk; }
    else { return null; }
    }
	
	
	
//===================================================//
// ALL DONE ! ---------------------------------------//
//===================================================//
