// JavaScript Document

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
	thisfield.value = "";
	}
}

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
	thisfield.value = defaulttext;
	}
}

function showHide(id) {
	if (document.getElementById(id).style.display == "none"){
		document.getElementById(id).style.display = "block";
	} else {
		document.getElementById(id).style.display = "none";
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function readHeaderCookie(url) {
	var cookie = readCookie("ap_header");
	var number = 1;
	var total = 8;
	if (cookie) {
		var newNumber = cookie;
		newNumber++;
		if (newNumber == (total + 1)) {
			newNumber = 1;
		}
		number = newNumber;	
		createCookie("ap_header", newNumber, "7");			
	} else {
		createCookie("ap_header", "1", "7");	
	}
	 
	
	var obj = document.getElementById("header");
	if (obj) {
		obj.style.background = 'url('+url+'images/layout/bg_header'+number+'.jpg) no-repeat left top';		
	}
}


/* Smooth scrolling
   Changes links that link to other parts of this page to scroll
   smoothly to those links rather than jump to them directly, which
   can be a little disorienting.
   
   sil, http://www.kryogenix.org/
   
   v1.0 2003-11-11
   v1.1 2005-06-16 wrap it up in an object
*/

var ss = {
	scrollToAnchor : function() {
			$(".scroll").click(function(event){
				//prevent the default action for the click event
				event.preventDefault();
		
				//get the full url - like mysitecom/index.htm#home
				var full_url = this.href;
		
				//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
				var parts = full_url.split("#");
				var trgt = parts[1];
		
				//get the top offset of the target anchor
				var target_offset = $("#"+trgt).offset();
				var target_top = target_offset.top;
		
				//goto that anchor by setting the body scroll top to anchor top 
				$('html, body').animate({scrollTop:target_top}, 500);
			});
		}
}


ss.scrollToAnchor();

function hideInactiveMenus(){
	//Set all classes active on a in main menu to normal
	$('#bottommenu').find('.bottomsub').each(function(){
		/*
		$(this).hide();
		*/
	});
	$(".menu_selected").show();
	$("li.bottommenu").removeClass("active");
}
$(document).ready(function(){
	
	$("li.bottommenu").hover(
		function() {		// over
			window.clearTimeout(window.menuTimeout);
			/*
			$(".bottomsub").hide();
			$(this).find("ul").show();
			*/
			$("li.bottommenu").removeClass("active");
			$(this).addClass("active");
		},
		function() { 		// out
			window.clearTimeout(window.menuTimeout);
			window.menuTimeout = window.setTimeout(hideInactiveMenus,2000);
		}
	);
	
	$(".bottomsub").hover(
		function() {
			window.clearTimeout(window.menuTimeout);
		},
		function() {
			window.clearTimeout(window.menuTimeout);
			window.menuTimeout = window.setTimeout(hideInactiveMenus,2000);
		}
	);
});