$(document).ready(function() {
	$('#employmentForm,#contactForm').validate({
		errorElement: "em",
		invalidHandler: function(form, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
				? 'You missed 1 required field. It has been highlighted'
				: 'You missed ' + errors + ' required fields. They have been highlighted';
				$("div.error span").html(message);
				$("div.error").show();
			} else {
				$("div.error").hide();
			}
		}
	});
	$(".checkbox").click(function(){
		if ($(this).hasClass("On")) {
			$(this).removeClass("On").css("background","url(/lifespace/images/main/checkbox.gif) 0 0 no-repeat");
			$(this).next("input").attr("value","NO");
		}
		else {
			$(this).addClass("On").css("background","url(/lifespace/images/main/checkbox.gif) -25px 0 no-repeat");
			$(this).next("input").attr("value","YES");
		}
	});
});



function getQueryVar(variable) { 
	var query = window.location.search.substring(1); 
	var vars = query.split("&"); 
	for (var i=0; i<vars.length; i++) { 
		var pair = vars[i].split("="); 
		if (pair[0] == variable) { 
			return pair[1]; 
		} 
	} 
	return "none";
}


/**********************************************************************
 image rollovers
 **********************************************************************/
 
function preloadImage(name){
    if (document.images) {
		homebuttondown = new Image();
		homebuttondown.src = siteRoot+"images/big-buttons/over/"+name+".gif";
	}	
}
function bigBtnOv(name){
    if (document.images) {
      document[ name ].src = siteRoot+"images/big-buttons/over/"+name+".gif";
    }
}
function bigBtnOut(name){
    if (document.images) {
      document[ name ].src = siteRoot+"images/big-buttons/up/"+name+".gif";
    }
}

/**********************************************************************
 shows and hides navigation layers
 **********************************************************************/

function show(id){
	menuOver();
	var subShown = false;
	for(i = 0; i<sectionArray.length; i++){
		var subNav = document.getElementById(sectionArray[i]);
		var topNavLink = document.getElementById(sectionArray[i].slice(0,sectionArray[i].length-3)+"Top");
		if(subNav != null){
			if(sectionArray[i] != id){
				 subNav.style.display = "none";
				 topNavLink.className = "n";
			}else{
				 subNav.style.display = "block";
				 topNavLink.className = "select";
				 subShown = true;
			}
		}
	}
	if (document.body){
		document.body.className = (subShown) ? "navBGsub" : "navBGtop";
	}
}
function hideAll(){
	show(subSection);
}
function menuOver(){
	if(window.clearNav){
		window.clearTimeout(clearNav);
	}
}
function revert(){
	clearNav = window.setTimeout("hideAll()", 1500);
}


/**********************************************************************
 videoCallout sidebar navigation
 **********************************************************************/
function videoCallout($prevOrNext){
	
	if($prevOrNext == "prev") {
		selectVideo -= 1;
	}else if($prevOrNext == "next"){
		selectVideo += 1;
	}else if($prevOrNext == "random"){
		selectVideo = Math.floor(Math.random()*videoArray.length);
	}else{
		selectVideo = $prevOrNext-1;
	}
	if(selectVideo == -1) selectVideo = videoArray.length-1;
	if(selectVideo == videoArray.length) selectVideo = 0;
	
	var videoCalloutBG = document.getElementById("peopleVideoBlock");
	
	videoCalloutBG.style.backgroundImage = "url("+siteRoot+videoArray[selectVideo][1]+")";
	
	for(i=0; i<videoArray.length; i++){
		var dot = document.getElementById("dot"+(i+1));
		dot.src = (selectVideo == i) ? siteRoot+"images/sidebar/navigation/dot_on.gif" : siteRoot+"images/sidebar/navigation/dot_off.gif";
	}
	
}
/* //OLD CODE
function videoCallout($prevOrNext){
	
	if($prevOrNext == "prev") {
		selectVideo -= 1;
	}else if($prevOrNext == "next"){
		selectVideo += 1;
	}else{
		selectVideo = $prevOrNext-1;
	}
	if(selectVideo == -1) selectVideo = videoArray.length-1;
	if(selectVideo == videoArray.length) selectVideo = 0;
	
	var title = document.getElementById("vidCalloutTitle");
	var subtitle = document.getElementById("vidCalloutSubtitle");
	var videoCalloutBG = document.getElementById("peopleVideoBlock");
	var description = document.getElementById("vidCalloutDescription");
	var vidLink = document.getElementById("videoCalloutLink1");
	
	title.src = siteRoot+videoArray[selectVideo][1];
	subtitle.src = siteRoot+videoArray[selectVideo][3];
	description.innerHTML = videoArray[selectVideo][4];
	videoCalloutBG.style.backgroundImage = "url("+siteRoot+videoArray[selectVideo][5]+")";
	vidLink.href = "new.php";
	
	for(i=0; i<videoArray.length; i++){
		var dot = document.getElementById("dot"+(i+1));
		dot.src = (selectVideo == i) ? siteRoot+"images/sidebar/navigation/dot_on.gif" : siteRoot+"images/sidebar/navigation/dot_off.gif";
	}
	
}*/

/**********************************************************************
 insert flash
 **********************************************************************/

function insertFlash(swfURL, swfContainer, w, h){
	var flashvars = {};
	
	var params = {};
	params.salign = "TL";
	params.scale = "scale";
	params.allowscriptaccess = "always";
	params.bgcolor = "FFFFFF";
	
	var attributes = {};
	attributes.id = "flashMovie";
	attributes.name = "flashMovie";
	
	swfobject.embedSWF(swfURL, swfContainer, w, h, "9.0.0", siteRoot+"swf/expressInstall.swf", flashvars, params, attributes);
}
function insertSlideShow(xml, link, audio){
	var flashvars = {};
	flashvars.xml = siteRoot+"swf/slides/"+xml;
	flashvars.link = link;
	flashvars.audio = siteRoot+"swf/audio/"+audio;
	flashvars.siteRoot = siteRoot;
	
	var params = {};
	params.salign = "TL";
	params.scale = "noscale";
	params.allowscriptaccess = "always";
	
	var attributes = {};
	attributes.id = "slideshow";
	attributes.name = "slideshow";
	
	swfobject.embedSWF(siteRoot+"swf/slideshow.swf", "flashcontent", "714", "540", "9.0.0", siteRoot+"swf/expressInstall.swf", flashvars, params, attributes);
}
function insertOverview(filterword, link){
	var flashvars = {};
	flashvars.filterword = filterword;
	flashvars.link = link;
	flashvars.siteRoot = siteRoot;
	
	var params = {};
	params.salign = "TL";
	params.scale = "noscale";
	params.allowscriptaccess = "always";
	params.wmode = "transparent";
	
	var attributes = {};
	attributes.id = "slideshow";
	attributes.name = "slideshow";
	
	swfobject.embedSWF(siteRoot+"swf/overview.swf", "flashcontent", "714", "540", "9.0.0", siteRoot+"swf/expressInstall.swf", flashvars, params, attributes);
}
function insertMap(){
	var flashvars = {};
	flashvars.siteRoot = siteRoot+"swf/";
	
	var params = {};
	params.salign = "TL";
	params.scale = "noscale";
	params.allowscriptaccess = "always";
	params.wmode = "transparent";
	
	var attributes = {};
	attributes.id = "map";
	attributes.name = "map";
	
	swfobject.embedSWF(siteRoot+"swf/map.swf", "flashcontent", "714", "540", "9.0.0", siteRoot+"swf/expressInstall.swf", flashvars, params, attributes);
}
/**********************************************************************
 site init on page load
 **********************************************************************/
 
function init(){
	hideAll(); // hides navigation
	setDefaultFontSize(); // load site font size off cookie
}
window.onload = init;