// JavaScript Document
$(document).ready(function(){
	makeGlobalActive();
	makeSideActive();
	setPageTitle();

	$("#dropDown").click(function() {
		$("li.drop").toggle();
	});
	
	$(document).bind('click', function(e) {
		var $clicked=$(e.target);
		if(!($clicked.is('#dropDown') || $clicked.parents().is('#dropDown'))) {
			$("li.drop").hide();
		}
	});

	$("#searchTxt").click(function() {
		if(this.value == "Enter Search Here") {
			this.value = "";
		}
	});
	$("#searchTxt").blur(function() {
		if(this.value == "") {
			this.value = "Enter Search Here";
		}
	});

});


function makeGlobalActive(){
	var path = window.location.pathname;
	path = path.replace('.html','')
	pathArray = path.split( '/' );
	pathArray = pathArray.reverse();
	if(pathArray.length > 2) {
		thisSection = pathArray[1];
		
		$("#globalNav li a").each(function () {
			navLink = this.href;
			if(navLink.indexOf(thisSection) != '-1') {
				$(this).addClass('active');
			}
		});
	}
	else {
		$("#globalNav li a.homeNav").addClass('active');
	}
}

function makeSideActive(){
	var path = window.location.pathname;
	path = path.replace('.html','')
	pathArray = path.split( '/' );
	pathArray = pathArray.reverse();
	thisPage = pathArray[0];
	
	if(thisPage != "" && thisPage != "index") {
		$("#leftCol li a").each(function () {
			navLink = this.href;
			if(navLink.indexOf(thisPage) != '-1') {
				$(this).addClass('active');
			}
		});
	}
}

function setPageTitle() {
		$("#globalNav li a").each(function () {
			if($(this).hasClass('active')) {
				var pageTitle = $(this).text();
				var pageLink = $(this).attr('href');
				$('#leftCol h1').html("<a href='" + pageLink + "'>" + pageTitle + "</a>");
			}
		});
}

function checkContactForm() {
	form = document.contactForm;
	q1 = form.entry_0.value;
	q2 = form.entry_1.value;
	q3 = form.entry_2.value;
	if (q1 == "") {
		alert('Please enter your First Name');
		return false;
	}
	else if (q2 == "") {
		alert('Please enter your Last Name');
		return false;
	}
	else if (q3 == "") {
		alert('Please enter your Email Address');
		return false;
	}
	else {
		successMessage('contactForm');
	}
}

function checkRegisterForm() {
	form = document.registerForm;
	q1 = form.entry_0.value;
	q2 = form.entry_1.value;
	if (q1 == "") {
		alert('Please enter your  Name');
		return false;
	}
	else if (q2 == "") {
		alert('Please enter your Email Address');
		return false;
	}
	else {
		successMessage('registerForm');
	}
}

function successMessage(formID) {
	document.getElementById("form-message").style.display=""; 
	document.getElementById("form-message").innerHTML="Thank you for your submission!"; 
	$("#" + formID).hide();
	formID.submit();
}

var imgCt = 0;

function imgRotator() {
	imgCt++;
	var imgSection = document.getElementById('centerCol');
	imgs = imgSection.getElementsByTagName('img');
	totalimgs = imgs.length;
	if(imgCt > totalimgs) {
		imgCt = 1;
	}
	$("img#home" + imgCt).fadeIn(1000);
	setTimeout('fadeSlide(imgCt);', 7000);
}

function fadeSlide(imgCt) {
	$("img#home" + imgCt).fadeOut(1000, imgRotator);
}


