/*
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\");");

        // Check what page we are on
        $page = $("body").attr("class");
        // If its not the contact page
        if($page!="contact") {
            $("#contact_popup_link").attr("href","javascript: showBox(\"600\",\"620\",\"DCK_email\",\"email\");");
        } else {
            // If on the contact page remove it, to avoid dupplicate forms
            $("#contact_popup_linkk").remove();
        }

	// When user clicks on email box for newsletter, remove message inside
	$("#mce-EMAIL").focus(function() {
		if ($("#mce-EMAIL").attr("value")=="Please enter your email address")
		{
			$("#mce-EMAIL").attr("value","");
		}
	});
	
	// If they click away from the newsletter email box without typing anything, return the message
	$("#mce-EMAIL").blur(function() {
		if ($("#mce-EMAIL").attr("value")=="")
		{
			$("#mce-EMAIL").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"
  }
});

// jQuery Ajax function to display a box over the top of the current page
//
// height - the height of the box
// width - the width of the box
// include - the page to display in the box
// type - the type of function - if "email" this will enable inline form checking
function showBox(height,width,include,type)
{
    // If values have not been set for the variables set default ones
    if (height==undefined)
    { height = 400; }

    if (width==undefined)
    { width = 600; }

    if (include==undefined)
    { include = "DCK_map"; }

    if (type==undefined)
    { type = null; }

    // Add cover and cover-content divs to the dom
    $("body").append("<div id='cover'></div><div id='cover-content'></div>");

    // Now position and size the box
    $("#cover").css("filter","alpha(opacity=0)");
    // work out the height of the page
    $doc_height =  (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
    // Now set the cover to be that height (so it works in IE)
    $("#cover").css("height",$doc_height);
    // Now size and position the cover content
    $("#cover-content").css("height",+height);
    $("#cover-content").css("margin-top",+-(height/2));
    $("#cover-content").css("width",+width);
    $("#cover-content").css("margin-left",+-(width/2));
    // Add a loading page
    $("#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");
            // Add content to cover-content
            $("#cover-content").load("include/"+include+".inc.php",function(){
                // If this is an email pop-up then add inline validation functionality
                if(type == "email") { enableForm(); }
            });
        });
    });

    // Add a click function to replicate hideBox()
    $("#cover").click(function () {
        hideBox();
    });

    $("#close_map_link").click(function () {
        hideBox();
    });
}

// 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();
	});
}