var contentHeight;
var contentTop = 244; 
var footerHeight= 53;
var pageHeight;

var isIE = (navigator.appVersion.indexOf("MSIE") != -1);

if( isIE ) versionIE = parseFloat(navigator.appVersion.split("MSIE")[1]);

function initializeSite()
{
	setSearchValidation();
	embedFlash();
	
	if( !showIntro ) checkPageHeight();
}


function checkPageHeight()
{
	contentHeight = document.getElementById("content").scrollHeight;
	pageHeight = contentHeight + contentTop + footerHeight + 24 /* The margings */;
	
	if ( isIE && versionIE <=6 )
	{
		document.getElementById("layout_wrapper").style.height = "100%";
		document.getElementById("menu").style.paddingLeft = "50px";
	}
	
	if( pageHeight < document.body.scrollHeight )
	{
		positionFooter();
		window.onresize = positionFooter;
	}
}


function positionFooter()
{
	document.getElementById("content").style.height = contentHeight + "px";
	
	if( pageHeight < document.body.scrollHeight )
	{
		var newContentHeight = (document.body.scrollHeight - contentTop - footerHeight - 24);
		
		document.getElementById("content").style.height = newContentHeight + "px";
	}
}


var sForm = document.searchForm;
var sField = document.getElementById("search_input");


function setSearchValidation()
{
	var submitButton = document.getElementById("search_button");
	
	if( sField.value != "Enter keywords" ) sField.style.color = "#000000";
	
	sField.onfocus = function() {
		if( this.value == "Enter keywords") this.value = "";
		this.style.color = "#000000";
	}
	
	sField.onblur = function() { 
		if( this.value == "")
		{
			this.value = "Enter keywords";
			this.style.color = "#999999";
		}
	}
	
	submitButton.onclick = function() {
		
		if( sField.value != "" && sField.value != "Enter keywords" ) sForm.submit();
		else
		{
			alert("Please enter keywords");
			sField.focus();
		}
	}
}

function embedFlash()
{
	if( showIntro )
		swfobject.embedSWF("themes/minova/images/intro.swf", "flash_intro", "100%", "100%", "8.0.0");
	
	var flashvars = new Object();
	
	flashvars.photoURL = topImageURL;
	flashvars.textLine = topImageCaption;
	swfobject.embedSWF("themes/minova/images/top-image.swf", "flash_img", "724", "160", "8.0.0", null, flashvars);
}

function hideIntro()
{
	var oDiv = document.getElementById("flash_intro");
	
	document.body.removeChild(oDiv);
	
	oDiv = document.getElementById("layout_wrapper");
	oDiv.style.display = "block";
	
	checkPageHeight();
}

function toggleDisplay(id)
{
	oDiv = document.getElementById("holder_"+id);
	oAnchor = document.getElementById("link_"+id);
	
	if( oDiv.style.display == "none" )
	{
		oDiv.style.display = "block";
		oAnchor.style.color = "#c41230";
	}
	else
	{
		oDiv.style.display = "none";
		oAnchor.style.color = "#ff9933";
	}
}

initializeSite();