// JavaScript Document

//for subnav
function showHideSub(childSub) {
		var openSub = $("div.sub:not(childSub)");
		if (openSub.is(':visible')) {
			openSub.slideUp('normal');
		}

		if (childSub.is(':visible')) {
			childSub.slideUp('normal');
		}
		else {
			childSub.slideDown('normal');
		}
}

//for sponsors rotating
function rotateSponsors() {
	var currentSponsor = $("td#sponsorsRotate div.current");
	var nextSponsor = currentSponsor.next();
	if (nextSponsor.length == 0) {
		nextSponsor = $("td#sponsorsRotate div:first");
	}
	
	currentSponsor.removeClass("current").addClass("previous");
	nextSponsor.css({ opacity : 0.0 }).addClass("current").animate({ opacity: 1.0 }, 1000, 
		function() {
			currentSponsor.removeClass("previous");
		});
}

$(document).ready(function() {
	//disable css hovers, etc.
	$("body").removeClass("noJS");	
	
	//main nav hovers
	$("#mainNav a:not(#activities #activitiesLink, #authors #authorsLink, #participate #participateLink, #schedule #scheduleLink)").hover(
		function() {
			$(this).stop().css({ "background-color" : "#c8402a" }).animate({ color: "#fff", backgroundColor: "#e62852" }, 500, "swing");
		}, function() {
			$(this).stop().css({ "background-color" : "transparent" }).animate({ color: "#000" }, 500, "swing");
		});
	
	//utilities hovers	
	$("#utilities a").hover(
		function() {
			$(this).stop().animate({ color: "#ffbd44" }, 200);
		}, function() {
			$(this).stop().css({ color: "white" }, 200);
		});
	
	//footer hovers
		$("#footer .column ul a").hover(
		function() {
			$(this).stop().animate({ color: "#dab136" }, 200);
		}, function() {
			$(this).stop().css({ color: "white" }, 200);
		})

		$("#footer .wideColumn a").hover(
		function() {
			$(this).stop().animate({ color: "#dab136" }, 200);
		}, function() {
			$(this).stop().css({ color: "#d44e18" }, 200);
		})


	//show/hide subnav
	$("#mainNav a").attr("href", "javascript:;"); // remove the not clause when activities subnav goes live
	$("#activitiesSub, #participateSub, #authorsSub, #scheduleSub, #jumpSub").css('display', 'none');
	
	$("#authorsLink").click(function() {showHideSub($('#authorsSub'))});
	$("#activitiesLink").click(function() {showHideSub($('#activitiesSub'))});
	$("#participateLink").click(function() {showHideSub($('#participateSub'))});
	$("#scheduleLink").click(function() {showHideSub($('#scheduleSub'))});
	$("#jumpLink").click(function() {showHideSub($('#jumpSub'))});
	
	//sponsorsRotate
	setInterval("rotateSponsors()", 3000);
	
	//auto clear form fields
	$("#name").focus(function() {
		if ($(this).val() == "Name") {
			$(this).val("");
		}
		});
	
	$("#email").focus(function() {
		if ($(this).val() == "Email") {
			$(this).val("");
		}
		});
	
	$("#comments").focus(function() {
		if ($(this).val() == "Comments") {
			$(this).val("");
		}
		});

	errorFocus();
});
