var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

// Handle all the the FSCommand messages in a Flash movie
function Navigation_DoFSCommand(command, args)
{
	clearTimeout(openPageTimeout);
	
	var NavigationObj = InternetExplorer ? Navigation : document.Navigation;
	if (command=="Home")
	{
		toggleBreakingNews(true);
		openPage('php/home.php');
	}
	else
	{
		toggleBreakingNews(false);
		if (command=="AboutUs")
			openPage('php/about.php');
		else if (command=="Staff")
			openPage('php/staff.php');
		else if (command=="Resources")
			openPage('php/resources.php');
		else if (command=="Projects")
			openPage('php/projects.php');
		else if (command=="MemberOrgs")
			openPage('php/memberOrgs.php');
		else if (command=="AboutUs")
			openPage('php/about.php');
		else if (command=="MembersArea")
			openPage('php/membersArea.php');
		else if (command=="InfoHub")
			openPage('php/infoHub.php');
		else if (command=="Gallery")
			openPage('php/gallery.php');
		else if (command=="Business")
			openPage('php/business.php');
		else if (command=="News")
			openPage('php/news.php');
		else if (command=="UsefulLinks")
			openPage('php/links.php');
		else if (command=="ContactUs")
			openPage('php/contact.php');
	}
}

// Hook for Internet Explorer 
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && 
  navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1)
{
	document.write('<script language="VBScript"\> \n');
	document.write('on error resume next \n');
	document.write('Sub Navigation_FSCommand(ByVal command, ByVal args)\n');
	document.write('  call Navigation_DoFSCommand(command, args)\n');
	document.write('end sub\n');
	document.write('</script\> \n');
}

// Open a page
function openPage(page)
{
	openPageWithId(page,'main');
}

// Open the next page in a particular region
function openPageWithId(page,id)
{
	openPageWithPostWithId(page,id,"GET",null)
}

// Post information for a particular page
function openPageWithPost(page,params)
{
	openPageWithPostWithId(page,'main',"POST",params);
}

// Post information for a particular page
function openPageWithPostWithId(page,id,post,params)
{
	var xmlHttp=getHTTP();

	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			// WRITE THE RESPONSE
			document.getElementById(id).innerHTML = '<td class="main" id="main" valign="top">'
								  +	xmlHttp.responseText
								  + '</td>';
			// Execute any javascript required
			openPageJS(getJSPage(page));
		}
	}

	xmlHttp.open(post,page,true);
	
	//Send the proper header information along with the request
	if (post == "POST" && params!=null)
	{
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
	}

	xmlHttp.send(params);
}

// Get the relevant page's javascript
function getJSPage(page)
{
	var s1=page.substring(0,page.indexOf('.'));
	var s2=page.substring(page.indexOf('.'));
	return s1+'JS'+s2;
}

// Get the XmlHTTP object
function getHTTP()
{
	var xmlHttp;

	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return null;
			}
		}
	}
	return xmlHttp;
}

// Open a page's javascript
function openPageJS(page)
{	
	var xmlHttp=getHTTP();

	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			// EVALUATE THE RESPONSE
			//alert(xmlHttp.responseText);
			eval(xmlHttp.responseText);
		}
	}

	xmlHttp.open("GET",page,true);
	xmlHttp.send(null);
}

// Open a fixed height text box
function expandBox(id,id2)
{
	expandBoxActual(id,id2,false);
}

function expandBox2(id,id2)
{
	expandBoxActual(id,id2,true);
}

function expandBoxActual(id,id2,larger)
{
	var div=document.getElementById(id);
	div.style.height="";

	var expand=document.getElementById(id2);
	expand.innerHTML='<a href="#" onclick="closeBox'
					+ (larger ? '2' : '')
					+ '(\''+id+'\',\''+id2+'\'); return false;">close</a>';
}

// Close a fixed height text box
function closeBox(id,id2)
{
	closeBoxActual(id,id2,false);
}

function closeBox2(id,id2)
{
	closeBoxActual(id,id2,true);
}

function closeBoxActual(id,id2,larger)
{
	var div=document.getElementById(id);
	if (larger)
		div.style.height="555px";
	else
		div.style.height="300px";

	var expand=document.getElementById(id2);
	expand.innerHTML='<a href="#" onclick="expandBox'
					+ (larger ? '2' : '')
					+'(\''+id+'\',\''+id2+'\'); return false;">expand</a>';
}
