/*
Javascript for Evolve
@author Simon Pollard
*/

$(function() {

        // Change link for map to use javascript
	$(".view_map").attr("href","javascript: showBox(\"500\",\"650\",\"map.html\");");


        $('#gallery').galleryView({
		pause_on_hover: true,
                show_filmstrip: false,
                transition_interval: 5000
            })
});


// Show Box
function showBox(height,width,include)
{
	if (height==undefined)
	{ height = 300; }
	
	if (width==undefined)
	{ width = 300; }
	
	if (include==undefined)
	{ include = "/evolve/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)");// 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);
	$("#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();
	});
}
