$(document).ready(function(){
	$(".swapImg", $("#navigation")).mouseover(function(){
		$(this).attr('src', $(this).attr('src').replace(/nav_/, 'nav_hover_'));
	});
	$(".swapImg", $("#navigation")).mouseout(function(){
		$(this).attr('src', $(this).attr('src').replace(/nav_hover_/, 'nav_'));
	});
	
	$("#submitAnAdd").click(function(){
		window.location = "submit-advertisement.php";
		return false;
	});
	
	
//function(){setupAjax();registerEventsList();$("#campsLoading").hide();}

});

function countryChange()
{
	$(".canada").hide();
	$(".unitedStates").hide();
	
	switch ($("#country").val()){
		case "CAN":
			$(".canada").show();
			provinceChange();
			break;
		case "USA":
			$(".unitedStates").show();
			stateChange();
			break;
	}
}

function provinceChange()
{
	//$("#city").html("Loading...");
	$("#city").load("cityajax.php", {country: $("#country").val(), province: $("#province").val()});
}

function stateChange()
{
	//$("#city").html("Loading...");
	$("#city").load("cityajax.php", {country: $("#country").val(), province: $("#state").val()});
}

function registerLocationEvents()
{
	$("#country").change(countryChange);
	$("#province").change(provinceChange);
	$("#state").change(stateChange);
	
	countryChange();
}

function startCountdown(year, month, day, hour, minute, containerID)
{
	continueCountdown(year, month, day, hour, minute, containerID);                
}
         
function continueCountdown(year, month, day, hour, minute, containerID)
{
	var Today = new Date();
            
                     
	Todays_Date = (new Date(Today.getUTCFullYear(), Today.getUTCMonth(), Today.getUTCDate(), 
						 Today.getUTCHours(), Today.getUTCMinutes(), Today.getUTCSeconds()));                                 
	Target_Date = (new Date(year, month - 1, day, hour, minute, 00));                  


	
	//Find their difference, and convert that into seconds.                  
	Time_Left = Math.round((Target_Date.getTime() - Todays_Date.getTime()) / 1000);

	if(Time_Left < 0)
	Time_Left = 0;
	 

	days = Math.floor(Time_Left / (60 * 60 * 24));
	Time_Left %= (60 * 60 * 24);
	hours = Math.floor(Time_Left / (60 * 60));
	Time_Left %= (60 * 60);
	minutes = Math.floor(Time_Left / 60);
	Time_Left %= 60;
	seconds = Time_Left;

	dps = 's'; hps = 's'; mps = 's'; sps = 's';
	//ps is short for plural suffix.
	if(days == 1) dps ='';
	if(hours == 1) hps ='';
	if(minutes == 1) mps ='';
	if(seconds == 1) sps ='';

	$("#" + containerID).html(days + ' day' + dps + ' ' + ((hours < 10) ? '0' + hours : hours) + ':' + ((minutes < 10) ? '0' + minutes : minutes) + ':' + ((seconds < 10) ? '0' + seconds : seconds));


		   
	//Recursive call, keeps the clock ticking.
	setTimeout('continueCountdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',"' + containerID + '");', 1000);
}


