var finishedInitialisation = false;

function initialiseTabs()
{
	showMoreNewOnSite();
	showMoreLatestNews();
	showMoreWhatsOn();
	document.getElementById("new_on_site_tabs").style.display = "";
	toggleNewsTabs("newsRelease");	
	
	setTimeout('finishedInitialisation = true;',1500);
}

function showDiv(divname)
{
	dojo.fadeOut({
        node: divname,
        duration:1,
        onEnd: function() {
		  document.getElementById(divname).style.display = "";
          dojo.fadeIn({
              node: divname,
              duration:300
            }).play();
        }
      }).play();
}

function showMore(tbodyname,selectorname)
{
	dojo.fadeIn({
	    node: tbodyname,
	    duration: 1600,
	    beforeBegin: function() {
	        var node = dojo.byId(tbodyname);
	        dojo.style(node, "opacity", 0);
	        dojo.style(node, "filter", 0);
	        dojo.style(node, "display", "");
	        resizeDivs('1000');
	        dojo.byId(selectorname).innerHTML = "Show Less..";
	    }
	}).play();
}

function showLess(tbodyname,selectorname)
{
	dojo.fadeOut({
	    node: tbodyname,
	    duration: 500,
	    onEnd: function() {
	        var node = dojo.byId(tbodyname);
	        dojo.style(node, "opacity", 0);
	        dojo.style(node, "filter", 0);
	        dojo.style(node, "display", "none");
	        resizeDivs('500');
	        dojo.byId(selectorname).innerHTML = "Show More..";
	    }
	}).play();
}

function toggleNewsTabs(currentlySelected)
{
	document.getElementById("newonsitesection2").style.display = "none";
	document.getElementById("newonsitenumberselector").innerHTML = "Show More..";
	
	document.getElementById("latestnewssection2").style.display = "none";
	document.getElementById("latestnewsnumberselector").innerHTML = "Show More..";
	
	try
	{
		document.getElementById("whatsonsection2").style.display = "none";
		document.getElementById("whatsonnumberselector").innerHTML = "Show More..";
	}catch(er){}
	
	resizeDivs('500');
	
	if(currentlySelected == "newOnSite")
	{
		document.getElementById("latest_news").style.display = "none";
		document.getElementById("whatsOn").style.display = "none";
		showDiv("new_on_site");
		document.getElementById("newOnSiteTab").className = "current";	
		document.getElementById("newsReleaseTab").className = "";
		document.getElementById("informationTab").className = "";
	}
	else if(currentlySelected == "newsRelease")
	{			
		document.getElementById("new_on_site").style.display = "none";
		document.getElementById("whatsOn").style.display = "none";
		showDiv("latest_news");
		document.getElementById("newOnSiteTab").className = "";	
		document.getElementById("newsReleaseTab").className = "current";
		document.getElementById("informationTab").className = "";

	}
	else
	{
		document.getElementById("latest_news").style.display = "none";
		document.getElementById("new_on_site").style.display = "none";
		showDiv("whatsOn");
		document.getElementById("newOnSiteTab").className = "";	
		document.getElementById("newsReleaseTab").className = "";
		document.getElementById("informationTab").className = "current";
	}
}

function getDivHeight(divName)
{
	var maxHeight = 0;
	
	if(document.getElementById(divName).style.display == "none")
	{
		document.getElementById(divName).style.display = "";
		
		if(document.getElementById(divName).clientHeight > maxHeight)
		{
			maxHeight = document.getElementById(divName).clientHeight;
		}
		
		document.getElementById(divName).style.display = "none";
	}
	else
	{
		if(document.getElementById(divName).clientHeight > maxHeight)
		{
			maxHeight = document.getElementById(divName).clientHeight;
		}
	}
	
	return maxHeight;
}

function resizeDivs(lengthduration)
{
		var maxHeight = 0;
		var tempHeight = 0;
	
		tempHeight = getDivHeight("new_on_site");
		
		if(maxHeight < tempHeight)
		{
			maxHeight = tempHeight;
		}
		
		tempHeight = getDivHeight("latest_news");
		
		if(maxHeight < tempHeight)
		{
			maxHeight = tempHeight;
		}
		
		tempHeight = getDivHeight("whatsOn");
		
		if(maxHeight < tempHeight)
		{
			maxHeight = tempHeight;
		}
		
		var currentHeight = document.getElementById("new_on_site_tab_content").style.height.slice(0,-2);
			
		if(maxHeight != 0 && finishedInitialisation)
		{
			//alert(currentHeight-maxHeight);
			
			if(currentHeight - maxHeight != 0)
			{
				dojo.animateProperty({ node: "new_on_site_tab_content", duration:eval(lengthduration),
				    properties: {
				        height: {end:maxHeight, unit:"px" }
				    }
				}).play();
			}
		}
		else
		{
			document.getElementById("new_on_site_tab_content").style.height = maxHeight+"px";
		}
}

function showMoreNewOnSite()
{
	if(document.getElementById("newonsitesection2").style.display == "")
	{
		showLess("newonsitesection2","newonsitenumberselector");
		//document.getElementById("newonsitesection2").style.display = "none";
		//document.getElementById("newonsitenumberselector").innerHTML = "Show More..";
	}
	else
	{
		showMore("newonsitesection2","newonsitenumberselector");
		//document.getElementById("newonsitesection2").style.display = "";
		//document.getElementById("newonsitenumberselector").innerHTML = "Show Less..";
	}
}

function showMoreLatestNews()
{
	if(document.getElementById("latestnewssection2").style.display == "")
	{
		showLess("latestnewssection2","latestnewsnumberselector");
		//document.getElementById("latestnewssection2").style.display = "none";
		//document.getElementById("latestnewsnumberselector").innerHTML = "Show More..";
	}
	else
	{
		showMore("latestnewssection2","latestnewsnumberselector");
		//document.getElementById("latestnewssection2").style.display = "";
		//document.getElementById("latestnewsnumberselector").innerHTML = "Show Less..";
	}
}

function showMoreWhatsOn()
{
	try
	{
		if(document.getElementById("whatsonsection2").style.display == "")
		{
			showLess("whatsonsection2","whatsonnumberselector");
			//document.getElementById("whatsonsection2").style.display = "none";
			//document.getElementById("whatsonnumberselector").innerHTML = "Show More..";
		}
		else
		{
			showMore("whatsonsection2","whatsonnumberselector");
			//document.getElementById("whatsonsection2").style.display = "";
			//document.getElementById("whatsonnumberselector").innerHTML = "Show Less..";
		}
	}catch(er){}
}