jQuery(document).ready(function() {	
	
	//$('#reg001_pageText li div').removeClass('select').hide('fast');	
	
	//Apply a function to the h3	
	/*$("#reg001_pageText h4").click(function() { 
 		var titleHeight = $(this).outerHeight();			 
		var divName = $("#reg001_pageText div");	
		var divClass = $('#reg001_pageText li div').hasClass("show");					
		displayContent($(this));		
		
		return false;
	});*/
		
	var  displayContent = function(ml) {
		//alert(ml.next().find("div").outerHeight())
		
		var paraHeight = ml.next().find("div").outerHeight();		
		
		//alert(paraHeight)
		//var paraHeight = ;		
	
		var divClass = $('#reg001_pageText li div').hasClass("show");
					   
		if (ml.next().hasClass("show") == true && divClass == true ) {
			//remove the animation from the drop down.
			ml.next().animate({height: 0}, 300);
			//remove the class show from the div
			ml.next().removeClass("show");
			//remove the class arrowDown from the h3
			ml.removeClass("arrowDown");
			} else {
				//add a class of show to the div
				ml.next().addClass("show");
				//add a class of arrow down to the h3
				ml.addClass("arrowDown");
				//animates the hight of the diaplaying content	
				ml.next().find(".features").css("display", "block")
				ml.next().animate({height: paraHeight}, 700);	
			}
		} 
		$("#reg001_leftNav li a").click(function() {
			return false;
		});
		
		
				
		//when mouseover the li start apply the function
		$("#reg001_leftNav li").mouseover(function() {
			//remove the class menuOn from #reg001_leftNav li									 
			$("#reg001_leftNav li").removeClass("menuOn");
			var className = $(this).attr("class")
			
			//remove css for coporate telephone
			$("#corpNo h2:first").removeClass("corHide")
			//add class to hide corporate telephone number
			$("#corpNo h2:last").addClass("corHide")
			
			//Run the rolloverContent() function
			rolloverContent(className); 	
			//add the classMenuOn to the li on rollover
			$(this).addClass("menuOn");									
   			if ( $(this).hasClass("menuOn") ) {
				$(this).next().css("background", "none");
			}
		});

		$("#reg001_leftNav li").mouseout(function() { 	
			//$(this).removeClass("menuOn");	
			$(this).css("background", "url(images/backgrounds/leftnavLine.gif) repeat-x top left");
			
			if ($(this).className == "menuOn") {
				$(this).next().css("background", "none");
			} else if ($(this).className != "menuOn") {
				$(this).next().css("background", "url(images/backgrounds/leftnavLine.gif) repeat-x top left");
			}
			
			
   		});		


		// rollover content function
		var  rolloverContent = function(el) {	
		//remove the class show and reset css for animated drop down	
		$('#reg001_pageText li').children("div").css("height", "0");	
		$('#reg001_pageText li').children("div").css("display", "block");	
		$('#reg001_pageText li div').removeClass("show");	
		$('#reg001_pageText li h4').removeClass("arrowDown");					
		 
			var idName = $("#reg001_pageText div");				
			$(idName).removeClass('selected');
		 		//loop through the number of Divs
				for (var i = 0, j = idName.length; i < j; i++)    {			 
				if (el == $(idName[i]).attr("id")) {				
			 	// Add class="selected" to div			  
			  	$(idName[i]).addClass('selected');	
				// Enable inputs and selects so that they can be used
			 	}
				}
		
//to change the phone number on corporate rollover
			if (el == "corporate") {
				//alert("hio")
				$("#corpNo h2").removeClass("corHide")
				$("#corpNo h2:first").addClass("corHide")
				
				}
		}
		//leftNav highlighting
		//varaibles to find the unique url string
		var pageUrl = window.location.href;
		var urlLength = pageUrl.length;
		var urlHash = pageUrl.indexOf("menu")		
		var urlSplit = pageUrl.slice(urlHash, urlLength);			
		
		//variables to find the left menu and the href value
		var menuLink = $("#reg001_leftNav ul li a")
		var menuStrp = menuLink.slice(1, 1);
		
		//find the left nav containing ul
		var menuOption = $("#reg001_leftNav ul")
		
		//if there is a #menu in the url then display the relevent menu option otherwise dispaly the first menu option in the list
		if(urlHash != -1){
			rolloverContent(urlSplit);
		} else {
			menuOption.children("li:first").addClass("menuOn");
		}
		
		//compare the li class with the url and if they match add a class of menu on
		$(menuOption).children("li").each(function() {
			if ($(this).attr("class") == urlSplit) {
				$(this).addClass("menuOn");
			}

		});

		// This removes the background from the next left menu li with a class of "menuOn"
		//$("li.menuOn").next().css("background", "none");

			/*
			//loop through the left nav href and compare the href string with the url of the page
			for(i=0; i < menuLink.length; i++){		
				//alert($(menuLink[i]).attr("href"))	
				if($(menuLink[i]).attr("href").slice(1) == urlSplit ){
				//if the page url and the leftNav url match add a class on the li of menuOne
				$(menuOption.children("li")[i]).addClass("menuOn")				
				}
			}	*/	 
		
		
		var backToTopLinks = $(".backtotop").get();
		jQuery.each(backToTopLinks, function(i, backToTopLink) {
			backToTopLink.one("click", function(e){
				e.preventDefault();
				$('body').animate({scrollTop:0}, 'slow');
			});
		});

		
		});
 
// Pop up window function for ninety
/*function wopen(url, name, width, height){
	newWindow = window.open(url, name, "location=1,status=1,scrollbars=0, width=800, height=560");
	newWindow.focus();
}*/
function wopen(url, name, width, height){
	if (!width) width = 800;
	if (!height) height = 560;
	newWindow = window.open(url, name, "location=1,status=1,scrollbars=0, width=" +width+ ", height=" +height+ "");
	newWindow.focus();
}