$(function() {
    $('.hasDefaultValue').focus(function(){
        if ($.trim($(this).val()) == $(this).attr("title")) {
            $(this).val("");
            $(this).addClass("hasValue");
        }
    }).blur(function(){
        if ($.trim($(this).val()) == "") {
            $(this).val($(this).attr("title"));
            $(this).removeClass("hasValue");
        }
    });
	// Email form
	if (document.location.protocol === "https:") {
		$('#signupForm').attr("action", "https://app.icontact.com/icp/signup.php");
	}
	$('#signupForm').submit(function(){
		var iContactForm = $('#signupForm');
		if ($(iContactForm).find("#emailAddress").val() == "email address") {
			$(iContactForm).find("#emailAddress").focus();
			alert("The Email field is required.");
			return false;
		} else {
			$(iContactForm).find(".hasDefaultValue").each(function(){
				if ($(this).val() == $(this).attr("title")) {
					$(this).val("");
				}
			});
			return true;
		}
	});
    if($.browser.mozilla) {
        $("#searchFormContainer").css("padding-top", "1px");
    }
    $.getJSON("Place-Data/update.php", function(json){
        $('div#time').html('<strong>' + json.hour + ':' + json.minute + ' ' + json.ampm + '</strong> AST');
        adjustClock(json.hour, json.minute);
        $('div#temperature').html('<strong>' + json.temperature + '</strong> °F');
        adjustThermometer(json.temperature);
        $('div#windSpeed').html('<strong>' + json.wind_low + '</strong> to <strong>' + json.wind_high + '</strong> mph');
        $('div#placeData').fadeIn();
    });
});
function adjustClock(hours, minutes) {
    var clockHeight = 25;
    var clockSteps = 8;
    var hourStep = 0;
    if (hours == 12) {
        hourStep = 0;
    } else {
        hourStep = hours * 200;
    }
    var minuteStep = Math.floor((minutes / 60) * clockSteps) * clockHeight;
    $('div#time').css('background-position', '0px ' + -(hourStep + minuteStep) + 'px');
}
function adjustThermometer(temperature) {
    var temperatureHigh = 50;
    var temperatureLow = 30;
    var thermometerSteps = 14;
    var thermometerHeight = 25;
    var thermometerStep = 0;
    if (temperature < temperatureLow) {
        thermometerStep = 0;
    } else if (temperature >= temperatureHigh) {
        thermometerStep = thermometerSteps - 1;
    } else {
        thermometerStep = Math.floor(((temperature - temperatureLow) / (temperatureHigh - temperatureLow)) * thermometerSteps);
    }
    $('div#temperature').css('background-position', '0px ' + -(thermometerStep * 25) + 'px');
}