// requires clickable element with class="toggleShow" and 
// corresponding element with class="hideFirst showThis"
// elements have to be in order for array to function
$(document).ready(function(){
	$(".hideFirst").hide();
	$(".toggleShow").toggle(
		function () {
			var index = $(".toggleShow").index(this);
			var itm = $(".showThis").get(index);
			$(itm).blur();
			$(itm).fadeIn(500,function(){
				$(itm).show(500);
				
			});
			//$(itm).slideDown(500);
		},
		function () {
			var index = $(".toggleShow").index(this);
			var itm = $(".showThis").get(index);
			$(itm).blur();
			$(itm).slideUp(500);//,function(){
			//	$(itm).fadeOut(500);
			//});
			//$(itm).slideUp(500);
		}
	);
	//-- tabbed divs --//
	// to use tabbed divs the link needs the same name
	// as the divs id to associate correct content
	var thisLink;
	// colours or images for tab background
	var navBkg = "#7da3d1"; // "url('') repeat-x"
	var navBkgOvr = "#3371b6"; // "url('') repeat-x"
	
	//enable an anchor to be passed that will display that tab first
	if(location.hash.length>0){
		var hash = location.hash;
		hash = hash.replace(/#/i,"");
		val = $("a[name='"+hash+"']").parent() //get relevant id from hash
		val = $(val).attr("id");
		//alert("Hash string passed: "+hash);
		//alert("id of parent div: "+val);
		$("div.infoTab:not(#"+val+")").hide(); // hide all tabs except passed id
		thisLink = $("a[name='"+val+"']"); // use id as the currently selected link
		thisLink.css("background",navBkgOvr); //Change bkg colour of selected link
		$(".infoTabbed > li a[name!='"+val+"']").css("background",navBkg); //Change colour of others under the class .tabbed
		
	}else{
	
	//enable an id to be passed that will display that tab first (using querystring)
//	if(getQuerystring('tab').length>0){
//		var val = getQuerystring('tab');
//		//alert("Querystring"+val);
//		
//		$("div.tab:not(#"+val+")").hide(); // hide all tabs except passed id
//		thisLink = $("a[name='"+val+"']"); // use id as the currently selected link
//		thisLink.css("background",navBkgOvr); //Change bkg colour of selected link
//		$(".tabbed > li a[name!='"+val+"']").css("background",navBkg); //Change colour of others under the class .tabbed
//		
//	}else{
	//alert("No location passed");
		$("div.infoTab:not(:first)").hide();
		thisLink = $(".infoTabbed li a:first");
		thisLink.css("background",navBkgOvr); //Change bkg colour of first nav
		$(".infoTabbed li a:not(:first)").css("background",navBkg); //Change all others
	
	}
	
	$(".infoTabbed li a").click(function(){
		thisLink = $(this); // assign current tab
		$(".infoTabbed li a").css("background",navBkg); //Reset bkg colour of nav
		thisLink.css("background",navBkgOvr); //Change bkg colour of selected
		thisLink.blur(); // remove focus from this tab
		$("div.infoTab:visible").fadeOut(200,function(){ //fadeOut then callback to fadeIn
			var div = thisLink.attr("name");
			$("#"+div).fadeIn(400);
		});
		return false;
	});
	// hover function for tabs
	$(".tabbed li a").hover(
		function(){
			$(this).css("background",navBkgOvr);
		},
		function(){
			if($(this).text() != thisLink.text()){ // prevent hover out firing for clicked tab
				$(this).css("background",navBkg);
			}
		}
	);
	
	
	
/* ================================================================ 
This copyright notice must be untouched at all times.
Copyright (c) 2008 Stu Nicholls - stunicholls.com - all rights reserved.
=================================================================== */
if($("#mininav")) {
	var navBkg = "#7da3d1";
	var navBkgOvr = "#3371b6";
	var timeMe = 0;
	
	$("#mininav span").mouseover(function() {
		clearTimeout(timeMe);
		var thisLink = $(this);
		$("#mininav ul:visible").slideUp(200);
		thisLink.parent().next().slideDown(300);
		thisLink.addClass("hilite");
	});
	$("#mininav span").mouseout(function() {
		$("#mininav span").removeClass("hilite");
	});
	$("#mininav").mouseover(function(){
		clearTimeout(timeMe);
		thisLink.addClass("hilite");
	});
	$("#mininav").mouseout(function(){
		timeMe = window.setTimeout(function(){
			$("#mininav ul:visible").slideUp(300);
			$("#mininav span").removeClass("hilite");
		}, 1500);
	}); 
	
//	$("#mininav span").hover(
//		function(){
//			$(this).css("background",navBkgOvr);
//		},
//		function(){
//			$(this).css("background",navBkg);
//		}
//	);	
	
}
	
	
});

function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}


/*	//-- tabbed divs --//
	// to use tabbed divs the link needs the same name
	// as the divs id to associate correct content
	var thisLink;
	// colours or images for tab background
	var navBkg = "#7da3d1"; // "url('') repeat-x"
	var navBkgOvr = "#3371b6"; // "url('') repeat-x"
	
	//enable an anchor to be passed that will display that tab first
	if(location.hash.length>0){
		var hash = location.hash;
		hash = hash.replace(/#/i,"");
		val = $("a[name='"+hash+"']").parent() //get relevant id from hash
		val = $(val).attr("id");
		$("div.tab:not(#"+val+")").hide(); // hide all tabs except passed id
		thisLink = $("a[name='"+val+"']"); // use id as the currently selected link
		thisLink.css("background",navBkgOvr); //Change bkg colour of selected link
		$(".tabbed > li a[name!='"+val+"']").css("background",navBkg); //Change colour of others under the class .tabbed	
	}else{	
		$("div.tab:not(:first)").hide();
		thisLink = $(".tabbed li a:first");
		thisLink.css("background",navBkgOvr); //Change bkg colour of first nav
		$(".tabbed li a:not(:first)").css("background",navBkg); //Change all others
	}
	$(".tabbed li a").click(function(){
		thisLink = $(this); // assign current tab
		$(".tabbed li a").css("background",navBkg); //Reset bkg colour of nav
		thisLink.css("background",navBkgOvr); //Change bkg colour of selected
		thisLink.blur(); // remove focus from this tab
		$("div.tab:visible").fadeOut(200,function(){ //fadeOut then callback to fadeIn
			var div = thisLink.attr("name");
			$("#"+div).fadeIn(400);
		});
		return false;
	});
*/
