// JavaScript Document

var sectionArray = new Array();


sectionArray.push(["home", 0]);
sectionArray.push(["gardens", -1590]);
sectionArray.push(["mausoleum", -2560]);
sectionArray.push(["services", -3530]);
sectionArray.push(["aftercare", -4500]);
sectionArray.push(["preplanning", -5470]);
sectionArray.push(["committment", -6440]);
sectionArray.push(["petHaven", -7410]);
sectionArray.push(["contact", -8380]);

var currentSection = 0;



$(document).ready(function(){
	
	
	// CHECK FOR HASH TAGS IN URL
	if(window.location.hash) {
	  // Fragment exists
	  
	  if(window.location.hash == "#contact-us") {  
		  currentSection = 8;
		  $(".header_logo").fadeIn();
		  moveSlider(currentSection);
	  }
	  
	} else {
	  // Fragment doesn't exist
	}
	
	$(".contactLink").click(function(){
		currentSection = 8;
		moveSlider(currentSection);
	});
	
	// SLIDER CONTROLS
	
	$("#nextButton").click(function(){
		
		if (currentSection == sectionArray.length-1) {
			currentSection = 0;
		} else {
			currentSection++;
		}
		
		moveSlider(currentSection);
	});
	
	$("#prevButton").click(function(){
		
		if (currentSection == 0) {
			currentSection = sectionArray.length-1;
		} else {
			currentSection--;
		}
		
		moveSlider(currentSection);
		
	});
	
	function moveSlider(section) {
		
		if (currentSection == 0) {
			$("#prevButton").fadeOut();
			$(".header_logo").fadeOut();
		} else if (currentSection == sectionArray.length-1) {
			$("#nextButton").fadeIn();
			$("#nextButton").fadeOut();
		} else {
			
			$(".header_logo").fadeIn();
			$("#nextButton").fadeIn();
			$("#prevButton").fadeIn();
		}
		
		
		$("#slider").animate({
			left: sectionArray[currentSection][1],
			easing: 'easeInOutCirc'
		}, 1000, function() {
		// Animation complete.
		});
		updateNav();
	}
	
	function updateNav() {
		var navButton = ".nav_" + sectionArray[currentSection][0];
		
		$(".nav_home a, .nav_gardens a, .nav_mausoleum a, .nav_services a, .nav_aftercare a, .nav_preplanning a, .nav_committment a, .nav_petHaven a, .nav_contact a").removeClass("active");
		
		$(navButton + " > a").addClass("active");
	}
	
	// NAVIGATION 
	
	$(".nav_home").click(function(){
		currentSection = 0;
		moveSlider(currentSection);
	});
	
	$(".nav_gardens, #gardens_btn, .explore").click(function(){
		currentSection = 1;
		moveSlider(currentSection);
	});
	
	$(".nav_mausoleum, #mausoleum_btn").click(function(){
		currentSection = 2;
		moveSlider(currentSection);
	});
	
	$(".nav_services").click(function(){
		currentSection = 3;
		moveSlider(currentSection);
	});
	
	$(".nav_aftercare").click(function(){
		currentSection = 4;
		moveSlider(currentSection);
	});
	
	$(".nav_preplanning").click(function(){
		currentSection = 5;
		moveSlider(currentSection);
	});
	
	$(".nav_committment").click(function(){
		currentSection = 6;
		moveSlider(currentSection);
	});
	
	$(".nav_petHaven, #petHaven_btn").click(function(){
		currentSection = 7;
		moveSlider(currentSection);
		//window.location = "pethaven/index.html";
	});
	
	$(".nav_contact").click(function(){
		currentSection = 8;
		moveSlider(currentSection);
	});
	
	
	
	
	// INTERACTIVE GARDENS MAP
	
	var currentLocation = "christtheKing";
	
	$(".icon_christtheKing").click(function(){
		$("." + currentLocation).fadeOut(function(){
			$(".christtheKing").fadeIn();
			currentLocation = "christtheKing";
		});
	});
	
	$(".icon_fallenHeroes").click(function(){
		$("." + currentLocation).fadeOut(function(){
			$(".fallenHeroes").fadeIn();
			currentLocation = "fallenHeroes";
		});
	});
	
	$(".icon_gardenofMemories").click(function(){
		$("." + currentLocation).fadeOut(function(){
			$(".gardenofMemories").fadeIn();
			currentLocation = "gardenofMemories";
		});
	});
	
	$(".icon_honor1").click(function(){
		$("." + currentLocation).fadeOut(function(){
			$(".honor1").fadeIn();
			currentLocation = "honor1";
		});
	});
	
	$(".icon_gardenofPrayer").click(function(){
		$("." + currentLocation).fadeOut(function(){
			$(".gardenofPrayer").fadeIn();
			currentLocation = "gardenofPrayer";
		});
	});
	
	$(".icon_hillside").click(function(){
		$("." + currentLocation).fadeOut(function(){
			$(".hillside").fadeIn();
			currentLocation = "hillside";
		});
	});
	
	$(".icon_honor1").click(function(){
		$("." + currentLocation).fadeOut(function(){
			$(".honor1").fadeIn();
			currentLocation = "honor1";
		});
	});
	
	$(".icon_honor2").click(function(){
		$("." + currentLocation).fadeOut(function(){
			$(".honor2").fadeIn();
			currentLocation = "honor2";
		});
	});
	
	$(".icon_mausoleum").click(function(){
		$("." + currentLocation).fadeOut(function(){
			$(".mausoleum").fadeIn();
			currentLocation = "mausoleum";
		});
	});
	
	$(".icon_privateEstate").click(function(){
		$("." + currentLocation).fadeOut(function(){
			$(".privateEstate").fadeIn();
			currentLocation = "privateEstate";
		});
	});
	
	$(".icon_petHaven").click(function(){
		$("." + currentLocation).fadeOut(function(){
			$(".petHaven").fadeIn();
			currentLocation = "petHaven";
		});
	});
	
	$(".icon_stJohn").click(function(){
		$("." + currentLocation).fadeOut(function(){
			$(".stJohn").fadeIn();
			currentLocation = "stJohn";
		});
	});
	
	$(".icon_stMark").click(function(){
		$("." + currentLocation).fadeOut(function(){
			$(".stMark").fadeIn();
			currentLocation = "stMark";
		});
	});
	
	$(".icon_stPaul").click(function(){
		$("." + currentLocation).fadeOut(function(){
			$(".stPaul").fadeIn();
			currentLocation = "stPaul";
		});
	});
	
	$(".icon_chapelMausoleum").click(function(){
		$("." + currentLocation).fadeOut(function(){
			$(".chapelMausoleum").fadeIn();
			currentLocation = "chapelMausoleum";
		});
	});
	
	
	
	
	$(".map_icon").hover(function(){
	      $(this).animate({
			width: '70px', /* Set new width */
			height: '80px', /* Set new height */
			left: '-=25px'
		}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */
	},function(){
	      $(this).animate({
			width: '20px', /* Set new width */
			height: '24px', /* Set new height */
			left: '+=25px'
		}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */
	});
		
		
	
	// PHOTO GALLERIES
	$("a[rel^='mausoleum_drawing']").prettyPhoto({
			theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square / facebook / pp_default */
			overlay_gallery: true, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
	});
	

	$("a[rel^='prettyPhoto']").prettyPhoto({
			theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square / facebook / pp_default */
			overlay_gallery: true, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
	});
	
	
	$("a[rel^='ChristKing_360']").prettyPhoto({
			custom_markup: '<div id="360_canvas"><img id="pano" src="images/360s/ChristtheKing.jpg" width="700" height="400"/></div>',
			changepicturecallback: function(){ initialize360(3246); }
	});
	
	
	$("a[rel^='FallenHeroes_360']").prettyPhoto({
			custom_markup: '<div id="360_canvas"><img id="pano" src="images/360s/FallenHeroes.jpg" width="700" height="400"/></div>',
			changepicturecallback: function(){ initialize360(2726); }
	});
	
	
	$("a[rel^='GardenofMemories_360']").prettyPhoto({
			custom_markup: '<div id="360_canvas"><img id="pano" src="images/360s/GardenofMemories.jpg" width="700" height="400"/></div>',
			changepicturecallback: function(){ initialize360(3290); }
	});
	
	
	$("a[rel^='GardenofPrayer_360']").prettyPhoto({
			custom_markup: '<div id="360_canvas"><img id="pano" src="images/360s/GardenofPrayer.jpg" width="700" height="400"/></div>',
			changepicturecallback: function(){ initialize360(3460); }
	});
	
	
	$("a[rel^='HillsideMausoleum_360']").prettyPhoto({
			custom_markup: '<div id="360_canvas"><img id="pano" src="images/360s/HillsideMausoleum.jpg" width="700" height="400"/></div>',
			changepicturecallback: function(){ initialize360(3817); }
	});
	
	
	$("a[rel^='Honor1_360']").prettyPhoto({
			custom_markup: '<div id="360_canvas"><img id="pano" src="images/360s/Honor1.jpg" width="700" height="400"/></div>',
			changepicturecallback: function(){ initialize360(3661); }
	});
	
	
	$("a[rel^='Honor2_360']").prettyPhoto({
			custom_markup: '<div id="360_canvas"><img id="pano" src="images/360s/Honor2.jpg" width="700" height="400"/></div>',
			changepicturecallback: function(){ initialize360(3543); }
	});
	
	
	$("a[rel^='Mosoleum_360']").prettyPhoto({
			custom_markup: '<div id="360_canvas"><img id="pano" src="images/360s/MausoleumColumbarium.jpg" width="700" height="400"/></div>',
			changepicturecallback: function(){ initialize360(3470); }
	});
	
	
	$("a[rel^='PrivateEstate_360']").prettyPhoto({
			custom_markup: '<div id="360_canvas"><img id="pano" src="images/360s/PrivateEstate.jpg" width="700" height="400"/></div>',
			changepicturecallback: function(){ initialize360(3346); }
	});
	
	
	$("a[rel^='PetHaven_360']").prettyPhoto({
			custom_markup: '<div id="360_canvas"><img id="pano" src="images/360s/PetHaven.jpg" width="700" height="400"/></div>',
			changepicturecallback: function(){ initialize360(3672); }
	});
	
	
	$("a[rel^='StJohn_360']").prettyPhoto({
			custom_markup: '<div id="360_canvas"><img id="pano" src="images/360s/StJohn.jpg" width="700" height="400"/></div>',
			changepicturecallback: function(){ initialize360(3505); }
	});
	
	
	$("a[rel^='StMark_360']").prettyPhoto({
			custom_markup: '<div id="360_canvas"><img id="pano" src="images/360s/StMark.jpg" width="700" height="400"/></div>',
			changepicturecallback: function(){ initialize360(3085); }
	});
	
	
	$("a[rel^='StPaul_360']").prettyPhoto({
			custom_markup: '<div id="360_canvas"><img id="pano" src="images/360s/StPaul.jpg" width="700" height="400"/></div>',
			changepicturecallback: function(){ initialize360(3612); }
	});
	
	
	// SERVICES PAGE - PRODUCT SWITCHER
	var currentProduct = ".memorials";
	var currentproductImg = ".product_memorials";
	
	function switchProducts(newProduct) {
		
		$(currentProduct).fadeOut(function() {
			$(newProduct).fadeIn();
			currentProduct = newProduct;
		});
		
	};
	
	function switchProductImg(newProductImg) {
		
		$(currentproductImg).fadeOut(function() {
			$(newProductImg).fadeIn();
			currentproductImg = newProductImg;
		});
		
	};
	
	$(".btn_memorials").click(function(){
		switchProducts(".memorials");
		switchProductImg(".product_memorials");
	});
	
	$(".btn_benches").click(function(){
		switchProducts(".benches");
		switchProductImg(".product_benches");
	});
	
	$(".btn_vases").click(function(){
		switchProducts(".vases");
		switchProductImg(".product_vases");
	});
	
	$(".btn_vaults").click(function(){
		switchProducts(".vaults");
		switchProductImg(".product_vaults");
	});
	
	
	
	
	
	// SPECIAL EVENT
	
	$("h3.event_alert").click(function(){
		currentSection = 2;
		moveSlider(currentSection);
	});
	
	$(".link_to_contact").click(function(){
		currentSection = 8;
		moveSlider(currentSection);
	});
	
	$(".cycleShow").cycle();
	
	
});
				
// 360 VIEWER

function initialize360 (width) {
  $('#pano').reel({
	  stitched: width, 
	  saves: true,
	  speed: 0.1,
	  delay: 4,
	  laziness: 1,
	  brake: 20
  });
}




function processForm () {
	
	$("#form").fadeToggle();
	
	var form_name 			= document.getElementById('form_name').value;
	var form_email 			= document.getElementById('form_email').value;
	var form_phone 			= document.getElementById('form_phone').value;
	
	if (document.getElementById('interested_preplanning').checked) {
		var interested_preplanning = 1;
	} else {
		var interested_preplanning = 0;
	}
	
	if (document.getElementById('interested_aftercare').checked) {
		var interested_aftercare = 1;
	} else {
		var interested_aftercare = 0;
	}
	
	if (document.getElementById('interested_mausoleum').checked) {
		var interested_mausoleum = 1;
	} else {
		var interested_mausoleum = 0;
	}
	
	if (document.getElementById('interested_veterans').checked) {
		var interested_veterans = 1;
	} else {
		var interested_veterans = 0;
	}
	
	if (document.getElementById('interested_financing').checked) {
		var interested_financing = 1;
	} else {
		var interested_financing = 0;
	}
	
	if (document.getElementById('interested_petHaven').checked) {
		var interested_petHaven = 1;
	} else {
		var interested_petHaven = 0;
	}
	
	var form_comments	 	= document.getElementById('form_comments').value;
	var form_highviewForm 	= document.getElementById('form_highviewForm').value;
	
	$.post("processForm.php",{ 
			name:form_name, 
			email:form_email, 
			phone:form_phone,
			comments:form_comments, 
			highviewForm:form_highviewForm,
			
			interested_preplanning:interested_preplanning,
			interested_aftercare:interested_aftercare,
			interested_mausoleum:interested_mausoleum,
			interested_veterans:interested_veterans,
			interested_financing:interested_financing,
			interested_petHaven:interested_petHaven
			
		} ,function(data) {
			$("#form").html(data);
			$("#form").fadeToggle();
	});
		
}
