/*
Javascript for FGE
@author Simon Pollard
*/

$(function() {
		
	$(".view_map").attr("href","javascript: showBox(\"500\",\"650\",\"map.html\");");	
	
	// Set the initial value
	$("#keywords_site").attr("value","Search the site");
	$("#keywords").attr("value","Search FAQs");
	$("#keywords_blog").attr("value","Search the Blog");
	$("#keywords2").attr("value","Search Information");
	$("#keywords3").attr("value","Search Videos");
	$("#keywords4").attr("value","Search Jargon");

	// When user clicks on input box, remove message inside
	$("#keywords_site").focus(function() {
		if ($("#keywords_site").attr("value")=="Search the site")
		{
			$("#keywords_site").attr("value","");
		}
	});
	
	// If they click away from the newsletter email box without typing anything, return the message
	$("#keywords_site").blur(function() {
		if ($("#keywords_site").attr("value")=="")
		{
			$("#keywords_site").attr("value","Search the site");
		}
	});
	
	
	// When user clicks on input box, remove message inside
	$("#keywords").focus(function() {
		if ($("#keywords").attr("value")=="Search FAQs")
		{
			$("#keywords").attr("value","");
		}
	});
	
	// If they click away from the newsletter email box without typing anything, return the message
	$("#keywords_blog").blur(function() {
		if ($("#keywords_blog").attr("value")=="")
		{
			$("#keywords_blog").attr("value","Search the Blog");
		}
	});
	
	// When user clicks on input box, remove message inside
	$("#keywords_blog").focus(function() {
		if ($("#keywords_blog").attr("value")=="Search the Blog")
		{
			$("#keywords_blog").attr("value","");
		}
	});
	
	// If they click away from the newsletter email box without typing anything, return the message
	$("#keywords").blur(function() {
		if ($("#keywords").attr("value")=="")
		{
			$("#keywords").attr("value","Search FAQs");
		}
	});
	
	
	
	// When user clicks on input box, remove message inside
	$("#keywords2").focus(function() {
		if ($("#keywords2").attr("value")=="Search Information")
		{
			$("#keywords2").attr("value","");
		}
	});
	
	// If they click away from the newsletter email box without typing anything, return the message
	$("#keywords2").blur(function() {
		if ($("#keywords2").attr("value")=="")
		{
			$("#keywords2").attr("value","Search Information");
		}
	});



	// When user clicks on input box, remove message inside
	$("#keywords3").focus(function() {
		if ($("#keywords3").attr("value")=="Search Videos")
		{
			$("#keywords3").attr("value","");
		}
	});
	
	// If they click away from the newsletter email box without typing anything, return the message
	$("#keywords3").blur(function() {
		if ($("#keywords3").attr("value")=="")
		{
			$("#keywords3").attr("value","Search Videos");
		}
	});
	


	// When user clicks on input box, remove message inside
	$("#keywords4").focus(function() {
		if ($("#keywords4").attr("value")=="Search Jargon")
		{
			$("#keywords4").attr("value","");
		}
	});
	
	// If they click away from the newsletter email box without typing anything, return the message
	$("#keywords4").blur(function() {
		if ($("#keywords4").attr("value")=="")
		{
			$("#keywords4").attr("value","Search Jargon");
		}
	});


});


// Show Box
function showBox(height,width,include)
{
	if (height==undefined)
	{ height = 300; }
	
	if (width==undefined)
	{ width = 300; }
	
	if (include==undefined)
	{ include = "/DCK_map"; }
	
	// Add cover and cover-content divs to the dom
	$("body").append("<div id='cover'></div><div id='cover-content'></div>");
	// Add content to cover-content
	
	// Now position and size the box
	$("#cover").css("filter","alpha(opacity=0)");
	$("#cover-content").css("height",+height);
	$("#cover-content").css("margin-top",+-(height/2));
	$("#cover-content").css("width",+width);
	$("#cover-content").css("margin-left",+-(width/2));
	
	// Now fade them in, cover first then content
	$("#cover").animate({opacity: 0.75}, 600, function(){
		$('#cover-content').fadeIn('1000',function(){
			$("#cover").css("filter","alpha(opacity=75");
			$("#cover-content").load("/DCK_map.inc.php");});
	});
	
	// Add a click function to replicate hideBox()
	$("#cover").click(function () { 
      	// Fade out cover-content div and remove from dom
		$("#cover-content").fadeOut("1000", function(){
			$('#cover-content').remove();
		});
		
		// Fade out cover div and remove from dom
		$("#cover").fadeOut("1000", function(){
			$('#cover').remove();
	  	});
    });	
	
	$("#close_map_link").click(function () { 
      	// Fade out cover-content div and remove from dom
		$("#cover-content").fadeOut("1000", function(){
			$('#cover-content').remove();
		});
		
		// Fade out cover div and remove from dom
		$("#cover").fadeOut("1000", function(){
			$('#cover').remove();
	  	});
    });	
}

// Hide Box
function hideBox()
{
	// Fade out cover-content div and remove from dom
	$("#cover-content").fadeOut("1000", function(){
		$('#cover-content').remove();
	});
	
	// Fade out cover div and remove from dom
	$("#cover").fadeOut("1000", function(){
		$('#cover').remove();
	});
}