$(document).ready(function() {

 //facebox application 
$("#foot_gift_shop").click(function() {
	$.facebox.settings.opacity = 0.6;
	var cnt_string = "Gift shop under construction and coming soon.";
	jQuery.facebox(cnt_string);
	return false;
});


//passeyAccordian for accordian slider(s)
$.passeyAccordian = function(containerId) {

	$(containerId + ' div.accordian_content').hide();										//hide all content divs
	$(containerId + ' div.accordian_content:first').slideDown("fast");						//slides down first content
	$(containerId + ' div.accordian_holder').hover(function() {
		
		var parent_div = $(this).attr("id");												//container div
		var child_div = '#' + $('#' + parent_div + ' .accordian_content').attr("id");		//slide this div
		if($(child_div).is(":hidden")) {													//if sliding div is hidden
			animating = true;
			$(child_div).slideDown("fast");													//slide it	
			$('.accordian_content').not(child_div).slideUp("fast");							//then slide up all other divs
		}
	});
};

//home page
$.passeyAccordian("#news_holder");	//apply the passeyAccordian to news box

//simple toggle->slide for hidden content	
$.enable_toggle = function(linkId,toggleId) {
	$(toggleId).hide();
    $(linkId).click(function() {
    	$.toggle(linkId,toggleId);
    	return false;
    });
};

$.toggle = function(linkId,toggleId) {
	$(toggleId).slideToggle("slow");
	if($(linkId).hasClass("down")) {
		$(linkId).removeClass("down");
		$(linkId).addClass("up");
		} else {
			$(linkId).removeClass("up");
			$(linkId).addClass("down");
		}
	return false;
};

$.hide_toggle = function(hider,sliderId,linkId) {
	$(hider).click(function() {
		$(sliderId).slideToggle("slow");
		$(linkId).removeClass("up");
		$(linkId).addClass("down");
	});
};

//sea lion section
$.enable_toggle("#family_life_link","#family_life");
	$.hide_toggle("#family_life_hide","#family_life","#family_life_link");
$.enable_toggle("#family_and_species_link","#family_and_species");
	$.hide_toggle("#family_and_species_hide","#family_and_species","#family_and_species_link");
$.enable_toggle("#physical_characteristics_link","#physical_characteristics");
	$.hide_toggle("#physical_characteristics_hide","#physical_characteristics","#physical_characteristics_link");
$.enable_toggle("#diet_link","#diet");
	$.hide_toggle("#diet_hide","#diet","#diet_link");

//sea birds
$.enable_toggle("#pigeon_guillemot_link","#pigeon_guillemot");
	$.toggle("#pigeon_guillemot_link","#pigeon_guillemot");
	$.hide_toggle("#pigeon_guillemot_hide","#pigeon_guillemot","#pigeon_guillemot_link");
$.enable_toggle("#cormorants_link","#cormorants");
	$.hide_toggle("#cormorants_hide","#cormorants","#cormorants_link");
$.enable_toggle("#gulls_link","#gulls");
	$.hide_toggle("#gulls_hide","#gulls","#gulls_link");
	
//whales
$.enable_toggle("#killer_whale_link","#killer_whale");
	$.toggle("#killer_whale_link","#killer_whale");
	$.hide_toggle("#killer_whale_hide","#killer_whale","#killer_whale_link");
$.enable_toggle("#gray_whale_link","#gray_whale");
	$.hide_toggle("#gray_whale_hide","#gray_whale","#gray_whale_link");
	
//map
$.enable_toggle("#drive_time_link","#drive_time");
	$.toggle("#drive_time_link","#drive_time");
	$.hide_toggle("#drive_time_hide","#drive_time","#drive_time_link");


//global for inforation section "hide buttons"
$("a.hide_this").click(function() {
	//$("div.slider_content:parent").one.slideToggle("slow");
	//$(this " ~ div.slider_content").slideToggle("slow");
	var a_id = $(this).attr("href");
		$(a_id).removeClass("up"); $(a_id).addClass("down");
	return false;	
});

//global
$('.to_top').click(function(){$('#top').ScrollTo(500); return false; });

//contact form ajax loader
$("#contact_form").submit(function() {									//if contact form is submitted
$("#loading_circle").show();
    $("#callback").empty();												//empty callback div to prepare for response
    $.ajax({															//jQuery ajax call
    	type: "POST",													//ajax type
    	url: "/ajax/contact.php",										//ajax url
    	data: 	'name_first='+$("#name_first").val()+					//ajax data
    			'&name_last='+$("#name_last").val()+
    			'&phone_area='+$("#phone_area").val()+
    			'&phone_ext='+$("#phone_ext").val()+
    			'&email='+$("#email").val()+
    			'&inquiry='+$("#inquiry").val()+
    			'&fooldyou='+$("#fooldyou").val()+
    			'&submit='+$("#submit").val(),
    	cache: false,													//deny browser cache
    	success: function(html){										//if data sent successfully
			$("#callback").append(html);								//append response to callback
			$("#loading_circle").hide();
			$("#name_first").val("");
			$("#name_last").val("");
			$("#phone_area").val("");
			$("#phone_ext").val("");
			$("#email").val("");
			$("#inquiry").val("");
				//$("#ajax_reply").fadeOut(10000);
				$("#close").click(function() {
					$("#ajax_reply").fadeOut(500);
				return false;
			});
    	}
    });
    $("#ajax_reply").slideDown(500);
    return false;														//no page reset
});

//contact form ajax loader
$("#bug_form").submit(function() {									//if contact form is submitted
$("#loading_circle").show();
    $("#callback").empty();												//empty callback div to prepare for response
    $.ajax({															//jQuery ajax call
    	type: "POST",													//ajax type
    	url: "/ajax/report_a_problem.php",										//ajax url
    	data: 	'name_first='+$("#name_first").val()+					//ajax data
    			'&name_last='+$("#name_last").val()+
    			'&email='+$("#email").val()+
    			'&url='+$("#url").val()+
    			'&repeat='+$("#repeat").val()+
    			'&fooldyou='+$("#fooldyou").val()+
    			'&submit='+$("#submit").val(),
    	cache: false,													//deny browser cache
    	success: function(html){										//if data sent successfully
			$("#callback").append(html);								//append response to callback
			$("#loading_circle").hide();
			$("#name_first").val("");
			$("#name_last").val("");
			$("#email").val("");
			$("#url").val("");
			$("#repeat").val("");
				//$("#ajax_reply").fadeOut(10000);
				$("#close").click(function() {
					$("#ajax_reply").fadeOut(500);
				return false;
			});
    	}
    });
    $("#ajax_reply").slideDown(500);
    return false;														//no page reset
});

/* sea lion challenge! */
	
	//answers
	$("#ul_answers a").click(function() {
		$("#ul_answers a").removeClass();								//remove all active from ul, then add to this one
			$(this).addClass("active");									//make this button active
		var clicked = $(this).attr("id");								//get the id to add to the form
		$("#chosen_answer").val(clicked);								//add value to form
			$("#continue:hidden").fadeIn("slow");
		return false;													//no clicky!
	});

	//for name entry
	$("#name_first").change(function() {
		var tmp = $("#name_first").val();
		if(tmp != "") {
			$("#start:hidden").fadeIn("slow");
		} else {
			$("#start").fadeOut("fast");
		}

	});

//scroll to bottom section!
var url = document.location.toString();			//get document location w/ anchors
	if(url.match("#")) {
		//$("#top").ScrollTo(500);
		//$('body').animate({ scrollTop: 0 }, 1);
		//$('body').append('<div id="testing_thing" style="width:100%; height:100px; background: white;"></div>');
		
		url = url.replace("http://76.12.54.62/","");
		url = url.replace("http://www.sealioncaves.com/","");
		url = url.replace("http://sealioncaves.com/","");	
		var empty = "";
		//url = url.replace("#","");
		//$("#testing").html(url); 					//error checking
		var split = url.split("/",14);				//split into /'s
		/* 
		for (var i in split) {
		empty = empty + i;
			if (i.match("#")) {
			
			}
		}
		
		$("#top").ScrollTo(1);
		$(split[2]).ScrollTo(500);
		$('#testing_thing').html(split[2]);
		
		$('.to_top').click(function(){$('#top').ScrollTo(500); return false; });
		*/
		return false;
	}
	
	// make all rel="target_blank" open in a new window
	$("a").each(function() {
		if( $(this).attr("rel") == "target_blank" ) {
			$(this).click(function() {
				window.open( $(this).attr("href") );
				return false;
			});
		}
	});

}); 