// JavaScript Document

//declare the starting 'old' menu item
var oldMenu = "";

//MENU ROLLOVERS
function menuOver(menu){
	//declare the called menu item
	var curMenu = document.getElementById(menu);
	
	//set the visibility of the menu being called
	curMenu.style.display = "block";
	
	//set the old menu item
	if((oldMenu == "") || (oldMenu == menu)) {
		oldMenu = menu;
	}
	
	else { 
		var oldMenuOff = document.getElementById(oldMenu);
		oldMenuOff.style.display = "none";
		oldMenu = menu;
	}
}

//MENU ROLLOUT
//start the timeout to hide the menu item
function menuOut(menu){
	var t=setTimeout("menuHide('" + menu + "')",6000);
}

//hide the menu item
function menuHide(menu) {
	var curMenu = document.getElementById(menu);
	curMenu.style.display = "none";
}

//SUBMENU ROLLOVERS
function subOver(menu){
	var menuItem = document.getElementById(menu);
	menuItem.style.backgroundColor = "#000";
	menuItem.style.color = "#FFF";
	menuItem.style.cursor = "pointer";
}

//SUBMENU ROLLOUTS
function subOut(menu){
	var menuItem = document.getElementById(menu);
	menuItem.style.backgroundColor = "#333";
	menuItem.style.color = "#CCC";
	menuItem.style.cursor = "default";
}

//declare all the variables for the timers
var c=0;
var t;
var timer_is_on=0;

//fade in the initial page image
function fadeBackPic() {
	
	//declare the image
	var thePic = document.getElementById("backimage");
	
	//set the opacity appropriately
	thePic.style.opacity = "0." + c;
	thePic.style.filter = "alpha(opacity=\"" + (c*10) + "\")";
	
	//set the increment up by 1
	c=c+1;
	
	//run the timer
	t=setTimeout("fadeBackPic()",100);
	
	//once it hits the maximum opacity, stop the timer
	if (c > 10) { stopPicTimer(); thePic.style.opacity = "1"; thePic.style.filter = "alpha(opacity=\"100\")"; }
}

//fade in the new page image
function initNewPic(menu,section,page,pic) {
	if (!timer_is_on) {

		//declare the image container
		var thePic = document.getElementById("backimage");	
		var theText = document.getElementById("text");
		
		//set the image
		document.getElementById("backimage").src = "/images/" + pic + ".jpg";
	
		//set the image opacity to zero
		thePic.style.opacity = "0"; 
		thePic.style.filter = "alpha(opacity=\"0\")";
		
		//set the opacity of the text box to 0
		theText.style.opacity = "0"; 
		theText.style.filter = "alpha(opacity=\"0\")";
		
		//declare the image
		objImg = new Image();
		objImg.src = "/images/" + pic + ".jpg";
		objImg.onload = function() {
			//reset the timer values
			var c=0;
			var t;
			
			objImg = new Image();
			objImg.src = "/images/" + pic + ".jpg";
	 
			timer_is_on=1;
			
			//call the fade function
			fadeBackPic();
			
			//call the menu items
			subClick(menu,section,page);
		}	
	}
}

//stop the timer on the image fade
function stopPicTimer() {
	clearTimeout(t);
	timer_is_on=0;
	c=0;
}

//SUBMENU LINKS
function subClick(menu,section,page){
	//declare the submenu
	var subMenu = document.getElementById(menu);
	
	//declare the content box
	var contentBox = document.getElementById("text");
	
	//turn off the menu
	subMenu.style.display = "none";
	
	//turn on the box to display the content
	contentBox.style.display = "block";
	
	//call the function that calls the content:
	callContent(section,page);
}

//SUBMENU CALLS THE CONTENT
function callContent(section,page)
{
if ((section=="") || (page==""))
  {
  document.getElementById("text").innerHTML="Sorry, something went wrong! Please try again...";
  return;
  }  
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("text").innerHTML=xmlhttp.responseText;
	document.getElementById("text").style.opacity = "1";
	document.getElementById("text").style.filter = "alpha(opacity=\"100\")";
    }
  }
xmlhttp.open("GET","/components/content_" + section + ".php?page=" + page,true);
xmlhttp.send();
}

//FRONT PAGE: 
//change the link style from the pictures on rollover
function picToTxtOver(textLink){
	var theLink = document.getElementById(textLink);
	
	//set the style
	theLink.id = textLink + "On";
}

//change the link style from the pictures on rollover
function picToTxtOut(textLink){
	var theLink = document.getElementById(textLink + "On");
	
	//set the style
	theLink.id = textLink;
}

//reveal more of the left side image
function timedPicWidthLeft() {
	//get the width values
	var picLeftW = document.getElementById("picleft").clientWidth;
	
	//set the widths appropriately
	document.getElementById("picleft").style.width=(picLeftW + c) + "px";
	document.getElementById("leftOver").style.cursor="pointer";
	
	//set the increment up by 1
	c=c+1;
	
	//run the timer
	t=setTimeout("timedPicWidthLeft()",100);
	
	//once it hits a certain width, stop the timer
	if (picLeftW > 900) { stopTimer(); document.getElementById("picLeft").style.width = 900 + "px";doTimer('right'); }
}

//reveal more of the right side image
function timedPicWidthRight() {
	//get the width values
	var picLeftW = document.getElementById("picleft").clientWidth;
	
	//set the widths appropriately
	document.getElementById("picleft").style.width=(picLeftW - c) + "px";
	document.getElementById("rightOver").style.cursor="pointer";
	
	//set the increment up by 1
	c=c+1;
	
	//run the timer
	t=setTimeout("timedPicWidthRight()",100);
	
	//once it hits a certain width, stop the timer
	if (picLeftW < 20) { stopTimer(); document.getElementById("picLeft").style.width = 20 + "px";doTimer('left'); }
}

//start the timer to slide reveal the images
function doTimer(leftRight) {
	
	if (!timer_is_on) {
		timer_is_on=1;
		
		if(leftRight == "left") {
			timedPicWidthLeft();
		}
		
		if(leftRight == "right") {
			timedPicWidthRight();
		}
	}
}

//stop the timer on rollout
function stopTimer() {
	clearTimeout(t);
	timer_is_on=0;
}

//if the user clicks a side, send them to the page
function goToPage(url){
	document.location.href = url;
}

//OPEN THE MAILING LIST WINDOW
function listWindowOpen(url) {
	window.open(url);
}
