	
	var currentFeature = 0;
	var animationTime = 800;
	var featureTimer;
	var featureTime = 8000;
	
	$(document).ready(function() {
	
		$(".vidbox").fancybox({ 
			titleShow: false,
			overlayColor: '#000',
			overlayOpacity: .6,
			width: 750,
			height: 422
		});
		
		$(".inline").fancybox({ height: 550, width: 675, autoDimensions: false, autoScale: false });
		
		$(".home_images img").not(".selected").css({display: "block", opacity: 0, zIndex: 99});
		$(".home_images img.selected").css({display: "block", zIndex: 100});
		featureTimer = setTimeout(swapImages, featureTime);
		
		$("input[name=form_type]").change(swapContactForm);
		
		if(window.location.hash)
		{
			var hash = window.location.hash.substr(1);
			
			if(hash.substr(0, 5) == "form_")
			{
				$("input." + hash).click();
				$("form#" + hash).show();
				window.location.hash = "form_area";
			}
			else
			{
				$(".vidbox." + hash).click();
			}
		}
		
		$(".callouts .why").click(function() {
			if($(".vidbox.why").length > 0)
			{
				$(".vidbox.why").click();
			}
		});
		
		$("#same_as").change(function() {
			var form = $(this).parents("form");
			if($(this).is(":checked"))
			{
				form.find("input[name=billing_company]").val(form.find("input[name=install_company]").val());
				form.find("input[name=billing_address_1]").val(form.find("input[name=install_address_1]").val());
				form.find("input[name=billing_address_2]").val(form.find("input[name=install_address_2]").val());
				form.find("input[name=billing_city]").val(form.find("input[name=install_city]").val());
				form.find("select[name=billing_state]").val(form.find("select[name=install_state]").val());
				form.find("input[name=billing_zip]").val(form.find("input[name=install_zip]").val());
				form.find("input[name=billing_contact_name]").val(form.find("input[name=install_contact_name]").val());
				form.find("input[name=billing_contact_title]").val(form.find("input[name=install_contact_title]").val());
				form.find("input[name=billing_contact_phone]").val(form.find("input[name=install_contact_phone]").val());
				form.find("input[name=billing_contact_email]").val(form.find("input[name=install_contact_email]").val());
			}
			else
			{
				form.find("input[name=billing_company]").val("");
				form.find("input[name=billing_address_1]").val("");
				form.find("input[name=billing_address_2]").val("");
				form.find("input[name=billing_city]").val("");
				form.find("select[name=billing_state]").val("");
				form.find("input[name=billing_zip]").val("");
				form.find("input[name=billing_contact_name]").val("");
				form.find("input[name=billing_contact_title]").val("");
				form.find("input[name=billing_contact_phone]").val("");
				form.find("input[name=billing_contact_email]").val("");
			}
		});
		
		$("#body.landing .tabs a").click(swapTabs);
	});
	
	
	function swapImages()
	{
		currentFeature ++
		if(currentFeature >= $(".home_images img").length)
		{
			currentFeature = 0;
		}
		
		$(".home_images img").eq(currentFeature).css({zIndex: 101}).animate({opacity: 1}, animationTime, function() {
			$(".home_images img.selected").css({zIndex: 99, opacity: 0}).removeClass("selected");
			$(this).addClass("selected").css({zIndex: 100});
		});
		
		clearTimeout(featureTimer);
		featureTimer = null;
		featureTimer = setTimeout(swapImages, featureTime);
	}
	
	
	function swapContactForm()
	{
		$("form").not($(this).parents("form")).hide();
		$("form#" + $(this).val()).show();
		window.location.hash = "form_area";
	}
	
	function swapTabs(e)
	{
		e.preventDefault();
		var newClass = $(this).attr("href").substr(1);
		
		$("#body.landing .tabs a.selected").removeClass("selected");
		$(this).addClass("selected");
		
		$("#body.landing .pane.selected").removeClass("selected");
		$("#body.landing .pane.pane_" + newClass).addClass("selected");
		$("#body.landing .content_bottom.landing .selected").removeClass("selected");
		$("#body.landing .content_bottom.landing ." + newClass).addClass("selected");
	}
	
