/* ===========================================================================
 * SCHEDULE THE BEHAVIOURS
 * =========================================================================== 
 */

/* Google map functions */
$(window).resize(function()
{
	if(typeof loadMap==='function')
		loadMap();
});

$(window).unload(function()
{
	if(typeof GUnload==='function')
		GUnload();
});

$(document).ready(function()
{
	if(typeof loadMap==='function')
		loadMap();
});

$(document).ready(function()
{
	//geo();
});

/* Animate image boxes */
$(document).ready(function()
{	
	$("div.caption").hide(); 
	/*
	$("div.title").click(
		function () 
		{
			if ($(this).siblings("div.caption").is(":hidden")) 
			{
				$(this).siblings("div.caption").slideDown("normal");
			} 
			else 
			{
				$(this).siblings("div.caption").slideUp("normal");
			}
		}
	);
	*/
	
	
	$("div.content-image").mouseenter(
		function () 
		{
			if ($(this).children("div.caption").is(":hidden")) 
			{
				$(this).children("div.caption").slideDown("fast");
				//$(this).children("div.caption").show();
				//$(this).fadeTo(0, 1);
			} 
		}
	);
	
	$("div.content-image").mouseleave(
		function () 
		{
			if ($(this).children("div.caption").not(":hidden")) 
			{
				$(this).children("div.caption").slideUp("fast");
				//$(this).children("div.caption").hide();
				//$(this).fadeTo(0, 0.7);
			}
		}
	);
	
	
});

/* Animate gallery thumbnails */
$(document).ready(function()
{		
	//$("div.thumbnail").fadeTo(0, 0.7);	
	$("div.thumbnail").mouseenter(
		function () 
		{
			if ($(this).children("div.caption").is(":hidden")) 
			{
				$(this).children("div.caption").slideDown("fast");
				//$(this).children("div.caption").show();
				//$(this).fadeTo(0, 1);
			} 
		}
	);
	
	$("div.thumbnail").mouseleave(
		function () 
		{
			if ($(this).children("div.caption").not(":hidden")) 
			{
				$(this).children("div.caption").slideUp("fast");
				//$(this).children("div.caption").hide();
				//$(this).fadeTo(0, 0.7);
			}
		}
	);
});

/* Set links */
$(document).ready(function()
{	
	$("a.tool-print").click(
		function () 
		{
			if (window.print)
				window.print();
			else
				alert("Sorry, your browser doesn't support the print feature. Use the File menu on your browser to select Print.");
			return false;	
		}
	);
	
	$("a[rel='external']").attr("target","_blank");
});

$(document).ready(function()
{	
	/*
	$("#navigation li ul").hide(); 
	*/
	$("#navigation li").hover(
		function () 
		{
			$(this).addClass("hover");
		},
		function()
		{
			$(this).removeClass("hover");
		}
	);//hover
	
});

/* Set text resizing */
$(document).ready(function()
{	
	textresize();
});



$(document).ready(function()
{
	// Use this example, or...
	//$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
	// This, or...
	//$('#gallery a').lightBox(); // Select all links in object with gallery ID
	// This, or...
	$('a.lightbox').lightBox(); // Select all links with lightbox class
	// This, or...
	//$('a').lightBox(); // Select all links in the page
	// ... The possibility are many. Use your creative or choose one in the examples above
});



/* Do some page tidying */
$(document).ready(function()
{
	// Alternate image box titles
	$("#main .content-image:odd").addClass("alt");
	$("#side .content-image:odd").addClass("alt");
	
	// Add inner class to header for image mask
	$("#header").wrapInner("<div id=\"header-inner\"></div>");
	
	// Fix HR's for IE
	$("hr").wrap("<div class=\"hr\"></div>");
	
	// Fix sibling selectors for IE
	$("#navigation li.active + li a").css("background-image","none");
	$("#navigation li.last.active").css("background-image","none");
	
	
	
});

/* Set the tooltips */
$(document).ready(function()
{	
	/* http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/ */
	$('#tools a').tooltip(
	{
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		opacity: 1.0,
		fade: 100
	});
});

/* http://www.shopdev.co.uk/blog/text-resizing-with-jquery/ */
function textresize()
{
	// show text resizing links
	$(".FontSize").show();
	var $cookie_name = "sitename-FontSize";
	var originalFontSize = $("html").css("font-size");
	
	// if exists load saved value, otherwise store it
	if($.cookie($cookie_name)) 
	{
		var $getSize = $.cookie($cookie_name);
		$("html").css({fontSize : $getSize + ($getSize.indexOf("px")!=-1 ? "" : "px")}); // IE fix for double "pxpx" error
	} 
	else 
	{
		$.cookie($cookie_name, originalFontSize);
	}
	
	// reset link
	$(".tool-textreset").bind("click", function() 
	{
		$("html").css("font-size", originalFontSize);
		$.cookie($cookie_name, originalFontSize);
	});
	
	// text "+" link
	$(".tool-textup").bind("click", function() 
	{
		var currentFontSize = $("html").css("font-size");
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum+1;
		if (newFontSize,  11) 
		{
			$("html").css("font-size", newFontSize);
			$.cookie($cookie_name, newFontSize);
		}
		return false;	
	});
	
	$(".tool-textdown").bind("click", function() 
	{
		var currentFontSize = $("html").css("font-size");
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum-1;
		if (newFontSize, 11) 
		{
			$("html").css("font-size", newFontSize);
			$.cookie($cookie_name, newFontSize);
		}
		return false;
	});
}



