// JavaScript Document

$(document).ready(function() {

// Header Animation

	// Dog slide up
	$("#dog").animate({top: "0px"}, 500, "swing");
	
	// Dog function call
	dog();
	
	// Dog animate function
	function dog () {
		var leftMargin = $("#dog").css("marginLeft"); // Get left-margin
		var margin = parseInt(leftMargin); // Parse into intiger
	
		$("#hit").hover(function(){
			$("#dog").animate({marginLeft: margin+3+"px" }, 100, "swing", function() {
				$("#dog").animate({marginLeft: margin-3+"px"}, 100, "swing", function () {
					$("#dog").animate({marginLeft: margin+"px"}, 100, "swing");
				});
			});
		});
	}
	
	// Clouds
	var cloudsInterval = clouds();
	var cloudInterval = cloud();
	
	// 2 Clouds
	function clouds() {
		$("#clouds").css("left","-20%").animate({
			left: '100%'
			}, 20000, "linear", function() {
				var cloudsInterval = clouds();
			});
	}
	
	// 1 Cloud
	function cloud() {
		$("#cloud").css("left","0px").animate({
			left: '100%'
			}, 15000, "linear", function() {
				var cloudInterval = cloud();
			});
	}


	// Video functions
	
	videoControls();
	
	function videoControls () {
		$("#video_btn").click(function() {
			$("#video").html('<iframe width="560" height="315" src="http://www.youtube.com/embed/nzM9zPdOWSU" frameborder="0" allowfullscreen></iframe>')	
			$("#curtain").fadeIn(500,function() {
				$("#video").fadeIn(250);
			});
		});
		$("#curtain").click(function() {
			$("#video").fadeOut(250).empty();
			$("#curtain").fadeOut(500);
		});
	}

	// Globally add in callout text, btns, and financing 
	function callOut() {
		$(".second_col").prepend('<h2>Call Bassett Services Heating and Cooling, <strong>800-318-5877</strong>, and schedule service or an estimate today. Or <strong><a href="http://www.bassettservices.com/indianapolis-heating-air">contact us</a></strong> online! </h2>');
	}
	
	// Mobile Fix
	var mLocation = (document.location.href);
	var mobile = mLocation.indexOf('http://m.');
	
	// If NOT mobile display callout text
	if (mobile == -1) {
		callOut();
	}

	function btns(selector) {
		$(selector).append('<a target="_blank" href="/var/m_e/e7/e7a/8718/40702-Testimonials.pdf" id="test"></a><a target="_blank" href="/var/m_2/29/29c/28540/126330-certifications.pdf" id="cert"></a><a id="financing" target="_blank" href="https://financial.wellsfargo.com/retailprivatelabel/initApp.do?profileNum=2710&dealerId=717398490"></a>');
	}
	
	if ($('.last_col').length) {
		btns(".last_col");
	} else {
		btns(".second_col");
	}

// Virtual Tour
	$("#virtual_tour_btn").click(function() {
		$("#curtain").fadeIn(500, "swing");
		$("#virtual").delay(500).fadeIn(500);
	});
	
	$("#curtain").click(function() {
		$("#virtual").fadeOut(250);
		$("#curtain").fadeOut(500);
	});
});

