﻿// JavaScript Document
function initialize(){
    //Grab mainNav Cookie
    //var mainNavID = readCookie('mainNav');
    var tempmainNavID = document.getElementById('mainNav');
    var mainNavID = tempmainNavID.getAttribute('value');
    
    if(mainNavID != ''){ 
        //var test = mainNavID.split('_');
        //test = test[test.length - 1]
        //Add .NET specific text to nav id   
        mainNavID = 'ctl00_ctl00_ctl00_Navigation1_' + mainNavID;

        var headerLocation = window.location.pathname.split("/");
        headerLocation = "http://" + window.location.host + "/" + headerLocation[1] + "/";
       
        var mainNav = document.getElementById(mainNavID);
        mainNav.style.backgroundImage = "url('" + headerLocation + "images/mainNav_bg_over.png')";
        
    }
}
function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
	    node = document;
    if ( tag == null )
	    tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
	    if ( pattern.test(els[i].className) ) {
		    classElements[j] = els[i];
		    j++;
	        }
    }
    return classElements;
}

function replaceDiv(oldChild)
{
    var temp = getElementsByClass(oldChild, document,'div');
    if (temp)
    {
        //var subNavID = readCookie('subNav');
        var tempsubNavID = document.getElementById('subNav');
        var subNavID = tempsubNavID.getAttribute('value');
        //alert(subNavID);        
        if(subNavID != ''){            
            var subNav = document.getElementById(subNavID);
            //alert(subNav);
            subNav.style.color = '#999999';
        }
        
	    var newChild = document.getElementsByTagName('h1').item(1);	
	    var tempHeader;
	    //alert(temp);
	    if(newChild.textContent)
	    {
	        tempHeader = temp[0].childNodes[3];	    
	        tempHeader.textContent = newChild.textContent;
    	    
	    }
	    else if(newChild.innerText)
	    {
	        tempHeader = temp[0].childNodes[1];
	        //alert(tempHeader);
	        tempHeader.innerText = newChild.innerText;
    	    
	    }
    	
	    newChild.style.display = 'none';
	}
}


function openWindow(file, width, height)
{
    var headerLocation = window.location.pathname.split("/");
        headerLocation = "http://" + window.location.host + "/";
       
    window.open(headerLocation + file,null,"'location=0,status=0,scrollbars=0,width=" + width + ",height=" + height + "'");
}

function randToutImg(id){
	var array = new Array("flash1.jpg","flash2.jpg","flash3.jpg");
	var temp = document.getElementById(id);
		var rand_no = Math.random();
		rand_no = rand_no * (array.length);
		rand_no = Math.floor(rand_no); 
		//alert("<img src='images/paintings/thumb/" + array[rand_no] + "'/>");
		temp.style.backgroundImage = "url('images/" + array[rand_no] + "')";
}