jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

$.preloadImages("images/moving_butterfly.gif", "images/work.png", "images/work2.png", "images/play.png","images/play2.png");



function hideSections(){
		$("#main_pic").hide();
		$("#tagline").css('background', 'transparent url(images/content_bg.gif) repeat-x');
		$("#box_info").show();

}
function sendEmail(form_name){
var program = '0';
var contact = '0';

	if(form_name == "get_quote"){

		var name = encodeURIComponent(document.get_quote.name.value);
		var email = encodeURIComponent(document.get_quote.email.value);
		var check_email = document.get_quote.email.value;
		var phone = encodeURIComponent(document.get_quote.phone.value);
		var message = encodeURIComponent(document.get_quote.message.value);
		program = 1;

	}

	if(form_name == "send_message"){
		var name = encodeURIComponent(document.send_message.name.value);
		var email = encodeURIComponent(document.send_message.email.value);
		var check_email = document.send_message.email.value;

		var phone = encodeURIComponent(document.send_message.phone.value);
		var message = encodeURIComponent(document.send_message.message.value);
		contact = 1;

	}

	if(name == ''){
		alert("Please fill in your name");
		return false;
	}
	if(email == ''){
		alert("Please fill in your email");
		return false;
	}

	var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	if (!regex.test(check_email)){
		alert('Please enter a valid email address');
		return false;
	}


	if(message == ''){
		alert("You must include a message");
		return false;
	}


	data = 'name=' + name + '&email='+ email + '&phone='+ phone + '&message='+ message + '&program='+ program + '&contact='+ contact;
	 $.ajax({

		   type: "POST",
		   url: "form_submit.php",
		   data: data,
		   success: function(msg){
			$(".service_info").hide();
			$("#show_thank_you").html(msg);
			$("#show_thank_you").show();
		   //alert( "Data Saved: " + msg );



		   }
		 });




}


$(document).ready( function(){

	$('#main_pic').attr('src','images/moving_butterfly.gif' );

      	$(".info").children().children("a").each(function (i) {
		$(this).click(function(){
			if($("#box_info").css('display') == "none"){
				hideSections();
			}
			$(".service_info").hide();
			$(".quote").show();
			$("#show_" + this.id).show();
			return false;
		});

      });

	$("#quote").click(function(){
		if($("#box_info").css('display') == "none"){

		hideSections();
		}
		$(".service_info").hide();
		$(".quote").hide();
		$("#send_quote").show();
		return false;
	});

	$("#contact").click(function(){
		if($("#box_info").css('display') == "none"){
			hideSections();
		}
		$(".service_info").hide();
		$(".quote").hide();
		$("#send_contact").show();
		return false;
	});


	$("#get_quote").submit(function(){
		sendEmail('get_quote');
		return false;
	});

	$("#send_message").submit(function(){
		sendEmail('send_message');
		return false;
	});
 $("#work").hover(
      function () {
        $(this).attr('src', 'images/work2.png');
	$("#play_info").hide();
	$("#work_info").show();

      },
      function () {
        $(this).attr('src', 'images/work.png');
      }
    );


 $("#play").hover(
      function () {
        $(this).attr('src', 'images/play2.png');
	$("#work_info").hide();
	$("#play_info").show();

      },
      function () {
        $(this).attr('src', 'images/play.png');
      }
    );

});

