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

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

	slideSwitch();
	setInterval( "slideSwitch()", 4000 );

});



/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}



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