//this variable retains the dart game data while other tabs are clicked on and restores it when dart is clicked
$(document).ready(function() 
	{
	   //$("#sliderButton").click(function() {openSlider();} );
	   $(".tab").mouseover(function() {tabMouse($(this));});
	   $(".tab").mouseout(function() {tabMouseOut($(this));});
	   $(".tab").click(function() {tabClick($(this));});
	   $(".tabActive").css("height","30px").animate({height:20},100,"swing");
	   $(".fadeImage").hide().fadeIn("slow");
	   $(".galleryThumb").click(function() {galleryClick($(this));});
	   //$("#tabbedContainerInner").hide().show("slow");
	});

	
function tabMouse(currentTab)
{
	if (currentTab.attr("class") != "tabActive")
	{
		currentTab.animate({height: 30}, 100 ,"swing");
	}
}

function tabMouseOut(currentTab)
{
		currentTab.animate({height: 20}, 100 ,"swing");
}

function tabClick(currentTab)
{
	if (currentTab.attr("class") != "tabActive")
	{
		$(".tabActive").removeClass('tabActive').addClass('tab');
		currentTab.removeClass('tab').addClass('tabActive').mouseout();
		var tabId = currentTab.attr("id");
		if ($("#tabbedContent").css("height") != "250px"  && tabId != "tabHome")
		{
			//$("#tabbedContent").animate({height:250},200,"swing",function() {tabChange(currentTab);});
			tabChange(currentTab);
		}
		else
		{
			tabChange(currentTab);
		}
	}
}

function tabChange(currentTab)
{
	if ($('#dartGameRound').is('*'))
	{
		saveDartGame = $("#tabbedContentInner").html();
	}
	switch(currentTab.html())
	{
	case "Dog":
	  $("#tabbedContentInner").hide().html('<img height="200" src="http://www.spurgeon.org/images/Suge/uglyfatdog.jpg">').fadeIn("slow");
	  document.location = currentAnchor = "#Dog";
	  break;    
	case "Cat":
	  $("#tabbedContentInner").hide().html('<img height="200" src="http://lukewrites.com/gallery/d/2425-1/ugly+cat.jpg">').fadeIn("slow");	
	  document.location = currentAnchor = "#Cat";
	  break;
	case "Frog":
	  $("#tabbedContentInner").hide().html('<img height="200" src="http://www.daily-blessings.com/frogstory_files/001_image0022.jpg">').fadeIn("slow");	
	  document.location = currentAnchor = "#Frog";
	  break;
	case "Snake":
	  $("#tabbedContentInner").hide().html('<img height="200" src="http://news.bbc.co.uk/olmedia/1910000/images/_1910471_snake300.jpg">').fadeIn("slow");				
	  document.location = currentAnchor = "#Snake";
	  break;
	case "Dart":
	  if (saveDartGame == "")
	  {
		$("#tabbedContentInner").hide().html("&nbsp;").load("dart.html").fadeIn("slow");	
		document.location = currentAnchor = "#Dart";
	  }
	  else 
	  {
		$("#tabbedContentInner").hide().html(saveDartGame).fadeIn("slow");	
		document.location = currentAnchor = "#Dart";
	  }
	  break;
	case "Home":
	  document.location = currentAnchor = "#Home";
	}
}

function galleryClick(currentThumbnail)
{
	//get the uri for the image from the thumbnail
	var imagePath = currentThumbnail.attr("src");
	imagePath = imagePath.substring(0,imagePath.length - 9) + imagePath.substring(imagePath.length - 4);
	
	$("#galleryDisplay").hide().html('<br><img src="'+imagePath+'"><br>'+currentThumbnail.attr("title")).fadeIn("slow");
}

