/*
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
*********** rotaing background images for landing page in a random order.**************
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
*/
function swapPic()
{
     if(document.getElementById)
     {
      	var thePicture=document.getElementById("Top");
      	var picPath="img/wp_00"+rnd(9)+".jpg";
        thePicture.style.background="url("+picPath+")";
        
     }
}

function swapPic2()
{
	 if(document.getElementById)
     {
      	var thePicture = document.getElementById("bg");
      	var picNum = rnd(4);
      	var picPath;
     	picPath = "img/wp_00" + picNum + ".jpg";
        thePicture.src =  picPath;
        
     }
     
    /* when pictures are more than ten.
	if(document.getElementById)
     {
      	var thePicture=document.getElementById("bg");
      	var picNum = rnd(10);
      	var picPath;
      	if(picNum >= 10)
      		picPath = "img/wp_0"+ picNum +".jpg";
      	else
      		picPath = "img/wp_00" + picNum + ".jpg";
      	 
        thePicture.src =  picPath;
     }
     */
}
     	
     	
function rnd(n)
{
     return Math.floor(Math.random() * n) + 1;
}

/*
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
**************** rotaing background images for landing page in sequence. ********************
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
*/
function setCookie(someint) 
{
	var now = new Date();
	var addDays = now.getDate() + 7
	now.setDate(addDays); // cookie expires in 7 days
	var theString = 'imgID=' + escape(someint) + ';expires=' + now.toUTCString();
	document.cookie = theString;
}

function getCookie() 
{
	var output = "0";
	if(document.cookie.length > 0) {
		var temp = unescape(document.cookie);
		temp = temp.split(';');
		for(var i = 0; i < temp.length; i++) {
			if(temp[i].indexOf('imgID') != -1) {
				temp = temp[i].split('=');
				output = temp.pop();
				break;
			}
		}
	}
	return output;
}

function loadNextImage(pic_array){
	//get image object
	var myImg = document.getElementById('myImage');

	var thePath = "img/home_pics/";
	var theImages = new Array();

	alert ("hi");
	alert (pic_array.length);
	for (i=0;i<pic_array.length;i++)
		theImages[i] = pic_array[i];
		
	var currentIndex = parseInt(getCookie());
	var imgPath = thePath + theImages[currentIndex];
	myImg.src = imgPath;
	myImg.alt = theImages[currentIndex];
	
	//set next cookie index
	currentIndex += 1;
	if(currentIndex > (theImages.length - 1)) {
		currentIndex = 0;
	}
	setCookie(currentIndex);
}

/*
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
**************** Underlining Bottom menus (alpha, omega, infinity) ********************
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
*/
function mouseOver_alpha()
{
	document.getElementById("alpha").src ="img/imagelink_ourcampaign_redline.gif"
}
function mouseOut_alpha()
{
	document.getElementById("alpha").src ="img/imagelink_ourcampaign.gif"
}
function mouseOver_omega()
{
	document.getElementById("omega").src ="img/imagelink_footsteps_redline.gif"
}
function mouseOut_omega()
{
	document.getElementById("omega").src ="img/imagelink_footsteps.gif"
}
function mouseOver_infinity()
{
	document.getElementById("infinity").src ="img/imagelink_life_redline.gif"
}
function mouseOut_infinity()
{
	document.getElementById("infinity").src ="img/imagelink_life.gif"
}
function mouseOver()
{
	document.getElementById("contentmenu_highlight").src ="img/contentleft_highlight.gif"
}


/*clear input box*/
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
} 


/*
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
**************** Menu opening_collapsing control ********************
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
*/
menu_status = new Array();


function showHide(theid)
{
    if (document.getElementById) 
    {

    	var switch_id = null;

    	num_of_submenus = num_of_things();

    	
        if(menu_status[theid] == 'show') 
        {


           switch_id = document.getElementById(theid);
           switch_id.className = 'hide';
           menu_status[theid] = 'hide';
       }
       else
       {
	       for ( i=1; i <= num_of_submenus; i++)
	       {		       
		       if (theid != "sub_menu" + i)
		       {
					switch_id = document.getElementById(theid);
           			switch_id.className = 'show';
           			menu_status[theid] = 'show';
       			}
       			
		       switch_id = document.getElementById("sub_menu" + i);		       
		       switch_id.className = 'hide';		       
		       menu_status["sub_menu" + i] = 'hide';		       
	   		}
       }
    }
    
}

function num_of_things()
{    		   			   
	var wbu_main_menu = document.getElementById("wbu_main_menu");

	items = wbu_main_menu.getElementsByTagName("div");
	
	return items.length;
}
