/*
Javascript for Deckchair UK Ltd
@author Simon Pollard
*/

// On page load
$(function() {
	// Change all map links to load up pop-up
	$(".view_map").attr("href","javascript: showBox(\"500\",\"650\",\"DCK_map\");");	
	
	// When user clicks on email box for newsletter, remove message inside
	$("#drddkj-drddkj").focus(function() {
		if ($("#drddkj-drddkj").attr("value")=="Please enter your email address")
		{
			$("#drddkj-drddkj").attr("value","");
		}
	});
	
	// If they click away from the newsletter email box without typing anything, return the message
	$("#drddkj-drddkj").blur(function() {
		if ($("#drddkj-drddkj").attr("value")=="")
		{
			$("#drddkj-drddkj").attr("value","Please enter your email address");
		}
	});
	
});

// Konami Code
var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
$(document).keydown(function(e) {
  kkeys.push( e.keyCode );
  if ( kkeys.toString().indexOf( konami ) >= 0 ){
    $(document).unbind('keydown',arguments.callee);
    // Launch easter egg here 
	alert("koooooooooooooooooooooonami!!!!!!!");
	window.location = "konami.php"
  }
});

// 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));
	$("#cover-content").load("include/loading.php");
	
	// 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("include/"+include+".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();
	});
}



// Show Box
function showMap()
{
	$("body").append( $("#cover") );
	//$("body").append( $("#map-holder") );
	
	// Now fade them in, cover first then content
	/*
	$("#cover").fadeIn("1000", function(){
		$('#map-holder').fadeIn('1000');
	});
	*/
	$('#map-holder').css("display","block");
	
	// Add a click function to replicate hideBox()
	$("#cover").click(function () { 
      	// Fade out cover-content div and remove from dom
		$("#map-holder").fadeOut("1000");
		
		// Fade out cover div and remove from dom
		$("#cover").fadeOut("1000");
    });	
	
}

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