$(document).ready(function() {

	var clicking_a_link = false;
	var submitting_a_form = false;

	// for the gallery on the homepage
	$("#gallery").PikaChoose({carousel:true});
	
	// for the request an estimate form
	var request_form_filled = false;
    $("#request_estimate").submit( function() {
        var error_text = "";
		
        if($("#name").val() == "")
        {
            var error_text = error_text + "Name Field is missing \n";
        }
        if($("#email").val() == "")
        {
            var error_text = error_text + "Phone Field is missing \n";
        }
        if($("#phone").val() == "")
        {
           var error_text = error_text + "Email Field is missing \n";
        }
        if($("#name").val() == "" || $("#email").val() == "" || $("#phone").val() == "")
        {
            alert(error_text);
            return false;
			
			request_form_filled = false;
        }
		else
		{
			request_form_filled = true;
		}
    });
	
	$('a').live('click', function() {
		clicking_a_link = true;
	});
	
	$('*').live('submit', function() {
		submitting_a_form = true;
	});
	
	
	var maxed_youtube_vid1 = false;
	$("#youtube_vid1").click(function () {
		if(!maxed_youtube_vid1)
		{
			$(this).effect("scale", { percent: 354, direction: 'both', origin: ['top','center'] }, 1000, function() {
				$(this).replaceWith('<iframe width="425" height="344" src="http://www.youtube.com/embed/o07gAsNoizM?;&rel=0" frameborder="0" allowfullscreen></iframe>');
			});
		}
		
		maxed_youtube_vid1 = true;
	});
	
	
	window.onbeforeunload = function() {

		if(!submitting_a_form && on_real_estate_agents_php && !clicking_a_link)
		{
			return 'WAIT! Complete your FREE registration and receive a FREE home inspection once you share your link (Valued at $350. Valid towards any client for 1 year). When registering enter Inspection Promo Code: FREE';
		}
		
		if(!request_form_filled && on_a_php && !clicking_a_link)
		{
			return 'WAIT! Confirm your $250 voucher. (good for one year) - REDEEM NOW.';
		}
		
	};
	
	
});
