// jQuery Panels & Functions

// Preload Images Function

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


$(function(){


// Skips directly to form via CTRL + K
$(document).bind('keydown', 'ctrl+k', formDrop);

// Preload all Images while Video is Playing
$.preloadImages("http://walkingwithaustin.com/wp-content/themes/TheWall/img/form1_bg.png", "http://walkingwithaustin.com/wp-content/themes/TheWall/img/skip_to_website.png",
"http://walkingwithaustin.com/wp-content/themes/TheWall/img/mid_c.png","http://walkingwithaustin.com/wp-content/themes/TheWall/img/mid_c2.png",
"http://walkingwithaustin.com/wp-content/themes/TheWall/img/map_the_walk.png",
"http://walkingwithaustin.com/wp-content/themes/TheWall/img/join_the_campaign.png",
"http://walkingwithaustin.com/wp-content/themes/TheWall/img/get_updates.png",
"http://walkingwithaustin.com/wp-content/themes/TheWall/img/banner.jpg",
"http://walkingwithaustin.com/wp-content/themes/TheWall/img/map.png",
"http://walkingwithaustin.com/wp-content/themes/TheWall/img/back_home2.png",
"http://walkingwithaustin.com/wp-content/themes/TheWall/img/return_to_walk.png"
);


// Main Screen
				 $(".trigger_image_main").click(function () {
				 $("div#main_div").show("slide", { direction: "up" }, 1000).removeClass('hidden');
				 $("#ajax_content").load("http://walkingwithaustin.com/?page_id=712 #load");
                 });	
				
				 // $.loading({onAjax:true, mask:false, img:'http://localhost/projects/AustinWall/wp-content/themes/TheWall/img/loader.gif', align:'top'}); 
				
})
 

function formDrop() {

$("div#form_div").show("slide", { direction: "up" }, 2000).removeClass('hidden');
setTimeout(function() { $('#frm1').fadeIn(); }, 3000);
setTimeout(function() { $('.ajaxLoader').fadeOut(); }, 2900);
//$('.ajaxLoader').fadeOut();
//$('.ajaxLoader').fadeOut();
$("div#form_div").load("http://walkingwithaustin.com/wp-content/themes/TheWall/includes/forms/join.php");

}

function hideForm() {
$('#frm1').fadeOut();
$("div#form_div").hide("slide", { direction: "up" }, 900).addClass('hidden');
$("div#main_div").show("slide", { direction: "up" }, 1000).removeClass('hidden');
$("#ajax_content").load("http://walkingwithaustin.com/?page_id=712 #load");
}

function formDrop_2() {
$("div#main_div").hide("slide", { direction: "up" }, 1000).addClass('hidden');
$("div#form2_div").show("slide", { direction: "up" }, 1000).removeClass('hidden');
setTimeout(function() { $('#frm2').fadeIn(); }, 3000);
setTimeout(function() { $('.ajaxLoader').fadeOut(); }, 2900);
$("div#form2_div").load("http://walkingwithaustin.com/wp-content/themes/TheWall/includes/forms/updated.php"); 
//$("div#form2_div").hide().addClass('hidden');
}

function hideForm_2() {
$('#frm2').fadeOut();
$("div#form2_div").hide("slide", { direction: "up" }, 900).addClass('hidden');
$("div#main_div").show("slide", { direction: "up" }, 1000).removeClass('hidden');
$("#ajax_content").load("http://walkingwithaustin.com/?page_id=712 #load");
}

function switchForm() {
$("div#main_div").hide("slide", { direction: "up" }, 1000).addClass('hidden');
$("div#form_div").show("slide", { direction: "up" }, 1000).removeClass('hidden');
setTimeout(function() { $('#frm1').fadeIn(); }, 3000);
setTimeout(function() { $('.ajaxLoader').fadeOut(); }, 2900);
$("div#form_div").load("http://walkingwithaustin.com/wp-content/themes/TheWall/includes/forms/join.php #load"); 
}



//Global AJAX Function  (url_load = the URL to load | div_load = the division within the url to load | include = includes certain items and appends them to footer)

function mapDrop(url_load, div_load, include) {
	
	var url = url_load + " " + div_load;
	
    $("#ajax_content").load("http://walkingwithaustin.com/wp-content/themes/TheWall/includes/clear.php #load"); // CLEAR
	$("#ajax_content").load(url); // LOAD 
	
	$("div#main_div").hide("slide", { direction: "up" }, 1000).addClass('hidden');
	$("div#main_div").show("slide", { direction: "up" }, 1000).removeClass('hidden');
	
		
	// Include any specific bottom Nav (Map = Loads 'back to map' | Home = loads 'back to homepage')
	if (include == "map") {
		$("#ajax_include").load("http://walkingwithaustin.com/wp-content/themes/TheWall/includes/backtomap.php #load");
	}
	
	else if (include == "home") {	
		$("#ajax_include").load("http://walkingwithaustin.com/wp-content/themes/TheWall/includes/back_home.php #load");
	}
	
	//If else, clear the div from previous included items
	else {
		$("#ajax_include").load("http://walkingwithaustin.com/wp-content/themes/TheWall/includes/clear.php #load");
	
	}
}
