var finishedInitialisation = false;

function loadingfinished()
{
	finishedInitialisation = true;
}

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 showDiv(divname)
{
	if(!dojo.isOpera)
	{
		dojo.fadeOut({
	        node: divname,
	        duration:1,
	        onEnd: function() {
			  document.getElementById(divname).style.display = "";
	          dojo.fadeIn({
	              node: divname,
	              duration:300
	            }).play();
	        }
	      }).play();
	}
	else
	{
		document.getElementById(divname).style.display = "";
	}
}

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)
		{
			if(currentHeight - maxHeight !== 0)
			{
				if(!dojo.isOpera)
				{
					dojo.animateProperty({ node: "new_on_site_tab_content", duration:parseInt(lengthduration),
					    properties: {
					        height: {end:maxHeight, unit:"px" }
					    }
					}).play();
				}
				else
				{
					dojo.byId("new_on_site_tab_content").style.height = maxHeight;
				}
			}
		}
		else
		{
			document.getElementById("new_on_site_tab_content").style.height = maxHeight+"px";
		}
}

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..";
		
	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 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)
{
	var node = dojo.byId(tbodyname);
	
	if(!dojo.isOpera)
	{
		dojo.fadeOut({
		    node: tbodyname,
		    duration: 500,
		    onEnd: function() {
		        dojo.style(node, "opacity", 0);
		        dojo.style(node, "filter", 0);
		        dojo.style(node, "display", "none");
		        resizeDivs('500');
		        dojo.byId(selectorname).innerHTML = "Show More..";
		    }
		}).play();
	}
	else
	{
		dojo.style(node, "display", "none");
		resizeDivs('500');
        dojo.byId(selectorname).innerHTML = "Show More..";
	}
}

function showMoreNewOnSite()
{
	if(document.getElementById("newonsitesection2").style.display == "")
	{
		showLess("newonsitesection2","newonsitenumberselector");
	}
	else
	{
		showMore("newonsitesection2","newonsitenumberselector");
	}
}

function showMoreLatestNews()
{
	if(document.getElementById("latestnewssection2").style.display == "")
	{
		showLess("latestnewssection2","latestnewsnumberselector");
	}
	else
	{
		showMore("latestnewssection2","latestnewsnumberselector");
	}
}

function showMoreWhatsOn()
{
	try
	{
		if(document.getElementById("whatsonsection2").style.display == "")
		{
			showLess("whatsonsection2","whatsonnumberselector");
		}
		else
		{
			showMore("whatsonsection2","whatsonnumberselector");
		}
	}catch(er){}
}

function initialiseTabs()
{
	//showMoreNewOnSite();
	showMoreLatestNews();
	//showMoreWhatsOn();
	//document.getElementById("new_on_site_tabs").style.display = "";
	toggleNewsTabs("newsRelease");	
	
	setTimeout(loadingfinished,1500);
}
