/* ===========================================================================
 * Filename: javascript/functions.js
 * Author: Rebecca Skeers, rebecca@webmistress.com.au, www.webmistress.com.au
 * Copyright: Rebecca Skeers
 * Date: 29 Sep 2009
 * Description: Contains JavaScript functions for the Alcorso Foundation website.
 *
 * This file may not be used for any purpose other than for the Alcorso Foundation
 * website and may not be modified without written permission from the author.
 * =========================================================================== 
 */

$(document).ready(function()
{	
	$("a[rel='external']").attr("target","_blank");
	$("p > a > img.image-left").parent().parent().css("padding-bottom","0");
	$("p > a > img.image-right").parent().parent().css("padding-bottom","0");
	$("p > img.image-left").parent().css("padding-bottom","0");
	$("p > img.image-right").parent().css("padding-bottom","0");

	$("#nav li").hover(
		function () 
		{
			$(this).addClass("hover");
		},
		function()
		{
			$(this).removeClass("hover");
		}
	);
	
	$("#nav li a").focus(
		function () 
		{
			$(this).parent().addClass("hover");
		}
	);
	
	$("#nav li a").blur(
		function()
		{
			$(this).parent().removeClass("hover");
		}
	);
	
	$("#nav li li a").focus(
		function () 
		{
			$(this).parent().parent().parent().addClass("hover");
		}
	);
	
	$("#nav li li a").blur(
		function () 
		{
			$(this).parent().parent().parent().removeClass("hover");
		}
	);
	
	
	
	$('#slideshow li').removeClass("current");
	$('#slideshow li:first').addClass("current");	
	slideSwitch();
	
	
	
	
	
	
	
	
	
	
	
	
	
	// Menu toggles
	$("a.reveal-toggle").show();
	$("div.reveal").hide();
	/*
	$("a.reveal-toggle").each(
		function( intIndex )
		{
			var closeLink = $("<p><a href=\"#\" class=\"reveal-close\">Close</a></p>");
			$(this).next(".reveal").append(closeLink);
			
			$(closeLink).click(function () 
				{
					$(this).closest("div.reveal").slideUp();
					
					var showHideLink = $("a.reveal-toggle").eq(intIndex);
					var showHideLinkText = $(showHideLink).text();
					var showHideNewText = showHideLinkText.replace(/Hide/, "View");
					$(showHideLink).text(showHideNewText);
					
					return false;
				});
			}
	);
	
	
	$("a.reveal-close").click(function () 
	{
		var linktext = $(this).text();
		if ($(this).parent().next("div.reveal").eq(0).is(":hidden")) 
		{
			var newtext = linktext.replace(/View/, "Hide");
			$(this).text(newtext);
			$(this).parent().next("div.reveal").eq(0).slideDown();
			return false;
		} 
		else 
		{
			var newtext = linktext.replace(/Hide/, "View");
			$(this).text(newtext);
			$(this).parent().next("div.reveal").eq(0).slideUp();
			return false;
		}
	});
	*/
	$("a.reveal-toggle").click(function () 
	{
		var linktext = $(this).text();
		if ($(this).parent().prev("div.reveal").eq(0).is(":hidden")) 
		{
			var newtext = linktext.replace(/Show/, "Hide");
			$(this).text(newtext);
			$(this).parent().prev("div.reveal").eq(0).slideDown();
			return false;
		} 
		else 
		{
			var newtext = linktext.replace(/Hide/, "Show");
			$(this).text(newtext);
			$(this).parent().prev("div.reveal").eq(0).slideUp();
			return false;
		}
	});
	
});

function slideSwitch() 
{
	var slideshowSize = $("#slideshow li").size();
	var currIndex = $("#slideshow li").index($("#slideshow li.current").eq(0));
	$("#slideshow li").removeClass("current");
	$("#slideshow li").eq(currIndex==slideshowSize-1 ? 0 : currIndex+1).addClass("current");
	
	randomNumber = Math.ceil(Math.random() * 4);
	if(randomNumber==1)
		setTimeout( "slideSwitch()", 2000 );
	else
		setTimeout( "slideSwitch()", 500 );
}
