stLight.options( {
	publisher:'f0cde54a-b223-4eec-9165-d7af35353d29',
	publisherGA:"UA-24683769-1",
	theme: 5,
	onhover: false
});

function updateTicker()
{
	var daysTens = eval($("#days1").html());
	var daysOnes = eval($("#days2").html());
	var hoursTens = eval($("#hours1").html());
	var hoursOnes = eval($("#hours2").html());
	var minutesTens = eval($("#minutes1").html());
	var minutesOnes = eval($("#minutes2").html());
	
	if(minutesOnes == 0)
	{
		if(minutesTens == 0)
		{
			if(hoursOnes == 0)
			{
				if(hoursTens == 0)
				{
					if(daysOnes == 0)
					{
						if(daysTens == 0)
						{
						}
						else
						{
							daysTens--;
							daysOnes = 9;
							hoursTens = 2;
							hoursOnes = 3;
							minutesTens = 5;
							minutesOnes = 9;
						}
					}
					else
					{
						daysOnes--;
						hoursTens = 2;
						hoursOnes = 3;
						minutesTens = 5;
						minutesOnes = 9;
					}
				}
				else
				{
					hoursTens--;
					hoursOnes = 9;
					minutesTens = 5;
					minutesOnes = 9;
				}
			}
			else
			{
				hoursOnes--;
				minutesTens = 5;
				minutesOnes = 9;
			}
		}
		else
		{
			minutesTens--;
			minutesOnes = 9;
		}		
	}
	else
	{
		minutesOnes--;
	}
	
	$("#days1").html(daysTens);
	$("#days2").html(daysOnes);
	$("#hours1").html(hoursTens);
	$("#hours2").html(hoursOnes);
	$("#minutes1").html(minutesTens);
	$("#minutes2").html(minutesOnes);
	
}

function setCatg(catg_id) {
	document.getElementById('nmnatn_catg').value = catg_id;
	if (catg_id == 1) {
		document.getElementById("nmnatn_catg1").src = "/img/bttn_selectplay_active.jpg";
		document.getElementById("nmnatn_catg2").src = "/img/bttn_selectcreate.jpg";
		document.getElementById("nmnatn_catg3").src = "/img/bttn_selectexplore.jpg";
	} else if (catg_id == 2) {
		document.getElementById("nmnatn_catg1").src = "/img/bttn_selectplay.jpg";
		document.getElementById("nmnatn_catg2").src = "/img/bttn_selectcreate_active.jpg";
		document.getElementById("nmnatn_catg3").src = "/img/bttn_selectexplore.jpg";
	} else if (catg_id == 3) {
		document.getElementById("nmnatn_catg1").src = "/img/bttn_selectplay.jpg";
		document.getElementById("nmnatn_catg2").src = "/img/bttn_selectcreate.jpg";
		document.getElementById("nmnatn_catg3").src = "/img/bttn_selectexplore_active.jpg";
	}
	return false;
}

function closeRegister(redir_path)
{
	$("#overlayRegister").hide();
	$("#curtain").hide();
	if (redir_path == '/nominate/') {
		document.location.href = '/home/';
	}
}

function openSample()
{
		$("#curtain").show();
		$("#overlaySample").show();
}

function closeSample()
{
	$("#overlaySample").hide();
	$("#curtain").hide();
}

function closeSMS()
{
	$("#overlaySMS").hide();
	$("#curtain").hide();
}

function openSMS()
{
		$("#curtain").show();
		$("#overlaySMS").show();
}

function openConfirm()
{
		$("#curtain").show();
		$("#overlayAdminConfirm").show();
}

function openVote(nominationId) {

	$("#curtain").show();
	$("#overlayVote").show();

	var axel = Math.random() + "";
	var a = axel * 10000000000000;
	$("#overlayVote").append('<iframe src="https://fls.doubleclick.net/activityi;src=3329539;type=confi839;cat=cloro356;ord=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>');

	$.ajax({
	    url: '/json/getGalleryItem',
	    data_type: 'json',
	    type: 'POST',
	    data: "nominationId=" + nominationId,
	    success: function (data) {
	        if (data.length == 0) {
	        }
	        else {
	            //$.each(data, function () {
	            $("#nmnImgReplacementID").remove();
	            $("#nomineeFrame").append("<div id=\"nmnImgReplacementID\" name=\"nmnImgReplacementID\" class=\"nmnImgReplacement\"><img src=\"" + data.img_path_nm + "/" + data.img_file_nm + data.img_ext_nm + "\" height=\"70\" alt=\"Nominee\"></div>");

	            var categoryText = "";
	            var categoryAltText = "";
	            if (data.nmnatn_catg_id == "3") {
	                categoryText = "/img/explore_white.gif";
	                categoryAltText = "Explore";
	            }
	            else if (data.nmnatn_catg_id == "2") {
	                categoryText = "/img/create_white.gif";
	                categoryAltText = "Create";
	            }
	            else if (data.nmnatn_catg_id == "1") {
	                categoryText = "/img/play_white.gif";
	                categoryAltText = "Play";
	            }

	            var categoryItemText = "<img src=\"" + categoryText + "\" alt=\"" + categoryAltText + "\">";
	            var voteTitleText = data.nmnatn_title_txt;
	            var voteLocationText = data.school_nm + ", " + data.city_nm + ", " + data.state_cd;
	            var voteCountText = "" + data.votes;
	            var voteTextID = "" + data.clrx_nmnee_vote_id;

	            var votingText = "<div id=\"votingText\" name=\"votingText\">" + categoryItemText + " with " + voteCountText + " votes " + "<img src=\"/img/icon_txt.gif\" alt=\"Text\" /> " + "clorox" + voteTextID + "</div>";

	            $("#nmnVoteTitle").remove();
	            $("#voteTitle").append("<div id=\"nmnVoteTitle\" name=\"nmnVoteTitle\" class=\"nmnVoteTitleClass\">" + data.nmnatn_title_txt + "</div>");

	            $("#nmnVoteLocation").remove();
	            $("#voteLocation").append("<div id=\"nmnVoteLocation\" name=\"nmnVoteLocation\" class=\"nmnVoteLocationClass\">" + data.school_nm + ", " + data.city_nm + ", " + data.state_cd + "</div>");

	            $("#votingText").remove();
	            $("#votePaneText").append(votingText);

	            $("#nmnVoteConfirmID").remove();
	            $("#nmnVoteCloseID").remove();
	            $("#votingConfirmButtonID").append("<a id=\"nmnVoteCloseID\" name=\"nmnVoteCloseID\" href=\"javascript:;\" onclick=\"closeVote();\"><img id=\"voteCancel\" src=\"/img/bttn_vote_cancel.gif\" alt=\"Cancel\" /></a> <a id=\"nmnVoteConfirmID\" name=\"nmnVoteConfirmID\" href=\"javascript:;\" onclick=\"openVoteConfirmed(" + nominationId + ");\"><img src=\"/img/bttn_confirmvote.gif\" alt=\"Confirm Vote\" /></a>");
	        }
	    },
	    error: function (xhr, ajaxOptions, thrownError) {
	    }


	});
}

function openAlready()
{
	$("#curtain").show();
	$("#overlayAlreadyVoted").show();
}

function openApprove()
{
		$("#curtain").show();
		$("#overlayAdminConfirm").hide();
		$("#overlayAdminApprove").show();
}

function closeAdmin()
{
		$("#overlayAdminConfirm").hide();
		$("#overlayAdminApprove").hide();
		$("#curtain").hide();
}

function openVoteConfirmed(nominationId)
{
		$("#overlayVote").hide();
		$("#overlayVoteConfirm").show();

		$.ajax({
		    url: '/json/voteEntry',
		    data_type: 'json',
		    type: 'POST',
		    data: "nominationId=" + nominationId,
		    success: function (data) {
		        if (data.length == 0) {
		        }
		        else {
		        }
		    },
		    error: function (xhr, ajaxOptions, thrownError) {
		    }


		});


}

function closeVote()
{
		$("#overlayVote").hide();
		$("#overlayVoteConfirm").hide();
		$("#curtain").hide();
}

function closeAlready()
{
		$("#overlayAlreadyVoted").hide();
		$("#curtain").hide();
}

function clickClear(selectedObject, defaultText, status)
{
	if(status == "focus")
	{
		if(selectedObject.value == defaultText)
		{
			selectedObject.value = "";
		}
	}
	else
	{
		if(selectedObject.value == "")
		{
			selectedObject.value = defaultText;
		}
	}	
}

function toggleLogin(activeTab)
{
	$("#registerTab").removeClass("active");
	$("#loginTab").removeClass("active");
	$(".registerForm").hide();
	$(".loginForm").hide();

	$("#" + activeTab + "Tab").addClass("active");
	$("." + activeTab + "Form").show();
	
	$("#curtain").show();
	$("#overlayRegister").show();
	
	if(activeTab == "register")
	{
		trackingCall(['_trackEvent', 'pabf_register','click','register']);
		trackingCall(['_trackPageview', '/register']);
/*<!--
Start of AKQA Doubleclick Floodlight Tag: Please do not remove
Activity name of this tag: Clorox Power a Bright Future Homepage - Register
URL of the webpage where the tag is expected to be placed: http://www.powerabrightfuture.com/home/
This tag must be placed between the <body> and </body> tags, as close as possible to the opening tag.
Creation Date: 08/29/2011
-->*/
		var axel = Math.random() + "";
		var a = axel * 10000000000000;
		$("#overlayRegisterPane").append('<iframe src="https://fls.doubleclick.net/activityi;src=3329539;type=homep760;cat=cloro506;ord=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>');
/*<!-- End of AKQA Doubleclick Floodlight Tag: Please do not remove -->*/


}
	else
	{
		trackingCall(['_trackEvent', 'pabf_login','click','login']);
		trackingCall(['_trackPageview', '/login']);
	}
}

// 8/12/11 John Ernest: Added countdown date to 10/24/11 (please note that Month in JS is Month - 1), you can access via the function or the voting_countdown variable.
function getCountdownDate() 
{
    var curDate = new Date();
    var currentTimestamp = Math.round(new Date(Date.UTC(curDate.getUTCFullYear(), curDate.getUTCMonth(), curDate.getUTCDate(), curDate.getUTCHours(), curDate.getUTCMinutes(), curDate.getUTCSeconds(), 0)).getTime() / 1000);
    var targetTimestamp = Math.round(new Date(Date.UTC(2011, 9, 19, 0, 0, 0, 0)).getTime() / 1000);
    return targetTimestamp - currentTimestamp;
}

var voting_countdown = getCountdownDate();

$(document).ready(function() {

	$("#nmnatn_catg1").bind("mouseenter", function() {
		$("#createTip").hide();
		$("#exploreTip").hide();
		$("#playTip").show();
		$("#schoolCategoryPane .toolTip").show();
	}).bind("mouseleave", function() {
		$("#schoolCategoryPane .toolTip").hide();
	});
	
	$("#nmnatn_catg2").bind("mouseenter", function() {
		$("#playTip").hide();
		$("#exploreTip").hide();
		$("#createTip").show();
		$("#schoolCategoryPane .toolTip").show();
	}).bind("mouseleave", function() {
		$("#schoolCategoryPane .toolTip").hide();
	});
	
	$("#nmnatn_catg3").bind("mouseenter", function() {
		$("#playTip").hide();
		$("#createTip").hide();
		$("#exploreTip").show();
		$("#schoolCategoryPane .toolTip").show();
	}).bind("mouseleave", function() {
		$("#schoolCategoryPane .toolTip").hide();
	});

	$("#schoolPhotoPane").bind("mouseenter", function() {
		$(".toolTip", this).show();
	}).bind("mouseleave", function() {
		$(".toolTip", this).hide();
	});

	$("#schoolGrantPane").bind("mouseenter", function() {
		$(".toolTip", this).show();
	}).bind("mouseleave", function() {
		$(".toolTip", this).hide();
	});

	$("#schoolProgramPane").bind("mouseenter", function() {
		$(".toolTip", this).show();
	}).bind("mouseleave", function() {
		$(".toolTip", this).hide();
	});

	$("#schoolDifferencePane").bind("mouseenter", function() {
		$(".toolTip", this).show();
	}).bind("mouseleave", function() {
		$(".toolTip", this).hide();
	});

	// Nav Active States
	var currentPage = window.location.href.substring((window.location.href.indexOf(".com")+5), (window.location.href.indexOf("/", window.location.href.indexOf(".com")+5)));
	switch(currentPage)
	{
		case "nominate":
			$("#nominateNav").addClass("active");
			break;
		case "gallery":
			$("#galleryNav").addClass("active");
			break;
		case "how-works":
			$("#howworksNav").addClass("active");
			break;
		case "about":
			$("#aboutNav").addClass("active");
			break;
		case "games":
			$("#gamesNav").addClass("active");
			break;
	}

	$("#register").bind("click", function(){
		toggleLogin("register");
	});
	$("#login").bind("click", function(){
		toggleLogin("login");
	});
	$("#registerTab").bind("click", function(){
		toggleLogin("register");
	});
	$("#loginTab").bind("click", function(){
		toggleLogin("login");
	});
	
	$("#sampleCTA").bind("click", function() {
		openSample();
	});

	$("#adminCallout").bind("click", function() {
		document.location.href='/admin';
	});

	$("#lastYear").bind("mouseenter", function() {
		var curSrc = $(this).attr("src");
		curSrc = curSrc.replace("winners.jpg", "winners_active.jpg");
		$(this).attr("src", curSrc);
	}).bind("mouseleave", function() {
		var curSrc = $(this).attr("src");
		curSrc = curSrc.replace("winners_active.jpg", "winners.jpg");
		$(this).attr("src", curSrc);
	});
	
	$("#adminTable tr:even").css("background-color", "#EBF8FD");
	
	$("#winnersLinks a").bind("click", function() {
		var target = $(this).attr('rel');
		$("#" + target + "WinnerOverlay").show(0);
		$("#winnersContent").slideDown(300);
		$("#homePane").animate({height:'750px'},300);
	});
	$("#winnersTeasers a").bind("click", function() {
		var target = $(this).attr('rel');
		$("#" + target + "WinnerOverlay").show(0);
		$("#winnersContent").slideDown(300);
		$("#homePane").animate({height:'750px'},300);
	});
	$("#winnersContent a.close").bind("click", function() {
		$("#winnersContent").slideUp(300).delay(300).children(".overlay").fadeOut(300);
		$("#homePane").animate({height:'350px'},300);
	});
});
