//The variable used to keep track of the timeout for the hover 
//(allows you to have the delay on the hover of the menu, so that the menu sticks around after you moved off the li's)
var currentTimeout;

//an array to hold the li's that you want held in hover mode
var LIs_To_Hover = new Array();

var browser=navigator.appName;
var b_version=navigator.appVersion;


function hideFormInIE()
{
	if(browser=="Microsoft Internet Explorer" && b_version.indexOf('MSIE 6.0')!=-1)
	{     
		var form_wrapper = document.getElementById('form_wrapper_inner');
		if(form_wrapper)
		{
			form_wrapper.className = form_wrapper.className.replace("visible","hidden");
		}
	}
	
}

function showFormInIE()
{
	if(browser=="Microsoft Internet Explorer" && b_version.indexOf('MSIE 6.0')!=-1)
	{     
		var form_wrapper = document.getElementById('form_wrapper_inner');
		if(form_wrapper)
		{
			form_wrapper.className = form_wrapper.className.replace("hidden","visible");
		}
	}

}



//sets up the functions for the mouseover and mouse out for the li's with class of 'top_li' and a parent container with the id 'nav'
function enableMenuImageRollovers()
{
	//get the surrounding container with the id of 'nav'
	var container = document.getElementById('nav');

	//return if the id is not found
	if (!container)
	{
	    return;
    }
	
	//get a list of all the li's in that surrounding div
	var lis = container.getElementsByTagName('li');


	for(x=0; x< lis.length; x++)
	{
		var li=lis[x];

		//indexOf is the same as str_pos in php (this is looking to see if the string "top_li" is in the class name of the li)
		//this is to make sure the li that are under the top level li's are not given these functions
		if(li.className.indexOf("top_li")!=-1)
		{
			//push the li's id onto the array of li's able to be hovered
			LIs_To_Hover.push(li.id);
			li.onmouseover=function() 
			{
				RollOver(this);
			}
			li.onmouseout=function() 
			{
				RollOff(this);
			}
		}
	}
}

//what do do when the li is rolled over
function RollOver(li)
{
	//go through the list of lis that can be hovered and turn off hover
	TurnOffAll();
	clearTimeout(currentTimeout);

	li.className=li.className.replace("hover_off","hover_on");

	var img_list = li.getElementsByTagName('img');

	img_list[0].src = img_list[0].src.replace("normal", "rollover");
	hideFormInIE();

}

//what do do when the li is rolled off
function RollOff(li)
{
	currentTimeout = setTimeout("RemoveSynHover('" + li.id + "')",500);
}

//remove the hover attributes of an li
function RemoveSynHover(LI_Id)
{
	var li = document.getElementById(LI_Id);

	li.className=li.className.replace("hover_on","hover_off");

	var img_list = li.getElementsByTagName('img');

	img_list[0].src = img_list[0].src.replace("rollover", "normal");
	showFormInIE();
}

//go through each li in the list of "hoverable" li's and remove their hover attributes 
function TurnOffAll()
{
	for(var i = 0; i < LIs_To_Hover.length; i++)
	{
		RemoveSynHover(LIs_To_Hover[i]);
	}
}







//#############################################
//STUFF NEEDED FOR FAQ
//#############################################



function getElementsByTagAndClassName(tagName, className)
{
	var items = new Array();
	var elems = document.getElementsByTagName(tagName);
	for(var i = 0; i < elems.length; i++)
	{
		var elem = elems[i];
		var classNames = elem.className.split(" ");
		for (var j = 0; j < classNames.length; j++)
		{
			if(classNames[j] == className)
			{
				items.push(elem);
			}
		}
	}
	return items;
}




function enableFAQExpanders()
{
  var blocks = getElementsByTagAndClassName('span','detailfaq');
  for(var i=0; i < blocks.length ; i++)
  {
    var block = blocks[i];
    var question = block.getElementsByTagName('span')[0];
    var answer = block.getElementsByTagName('div')[0];
	if(question && answer)
	{
		question.innerHTML = "<a href=\"#\">" + question.innerHTML + "</a>";
		var href = question.getElementsByTagName('a')[0];
		href.answer = answer;
		href.onclick=function()
		{
				if(this.className=="")
				{
					this.className="question clicked";
				}
				else
				{
					this.className="question unclicked";
				}

				if (this.answer.style.display=='none')
				{
					Effect.BlindDown(this.answer);
				}
				else
				{
					Effect.BlindUp(this.answer);
				}
				return false;      
		};
		answer.style.display='none';
	}
  }
}



document.getElementsByTagAndClassName=function(tagName, className, parentElement)
{
	var items = new Array();
	var elems = (document.getElementById(parentElement) || document.body).getElementsByTagName(tagName);
	for(var i = 0; i < elems.length; i++)
	{
		var elem = elems[i];
		var classNames = elem.className.split(" ");
		for (var j = 0; j < classNames.length; j++)
		{
			if(classNames[j] == className)
			{
				items.push(elem);
			}
		}
	}
	return items;
};






function bindBehaviors()
{

 

  // quit if this function has already been called
  if (arguments.callee.done) return;

  // flag this function so we don't do the same thing twice
  arguments.callee.done = true;

  enableMenuImageRollovers();
  enableFAQExpanders();
}


if (window.addEventListener)
{
  window.addEventListener('load', bindBehaviors, false);

}
else if (window.attachEvent)
{
  window.attachEvent('onload',bindBehaviors);

}
