/*
	© 2008 SERIOUS Marketing Communications Ltd
	Written by Mark Jackson specifically for http://www.seriousideas.com
	All rights reserved

*/

function init() {
	f_content = document.getElementById("div_flashContent");
	s_content = document.getElementById("div_staticContent");
	//alert("Initialise page");
	s_content.innerHTML = '';
	s_content.style.display = 'none';
	f_content.innerHTML = '<h1>Flash loaded successfully</h1>';
	insertFlash(f_content);
	resize(f_content);
	//sendID();
}

function resize(obj) {
	var min_w = '780'; // set flash minimum width
	var min_h = '500'; // set flash minimum height
	
	var w_height = (document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight; // window height
	var w_width = (document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.clientWidth; // window width
	var tm_height = document.getElementById("div_topMenu").offsetHeight;
	var f_content = document.getElementById("div_flashContent");
	var f_obj = flashObj();
	var new_height = w_height-tm_height;
	
	flash_w = (w_width<=min_w) ? min_w+'px' : '100%';
	flash_h = (w_height<=min_h) ? min_h+'px' : new_height+"px"; // IE does not handle 100% well so force physical height to match container
	
	f_content.style.height = new_height+"px"; // resize flash containing div
	f_obj.style.height = flash_h; // resize flash object
	f_obj.style.width = flash_w; // resize flash object
	document.getElementById("div_topMenu").style.width = flash_w; // resize top navbar width
}

function flashObj() {
		obj = document.getElementById("f_obj");
		emb = document.getElementById("f_emb");
		if (navigator.appName.indexOf("Microsoft") != -1) {
			return obj; // for IE
		} else {
			return emb; // for FF
		}
}

function insertFlash(obj) {
	//flashFile = "flash/seriousScaled.swf";
	flashFile = "flash/serious.swf";
	quality = "high";
	scale = "noscale";
	//scale = "default";
	flash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="100%" height="100%" id="f_obj"><param name="movie" value="'+flashFile+'" /><param name="quality" value="'+quality+'" /><param name="menu" value="true" /><param name="scale" value="'+scale+'" /><param name="allowScriptAccess" value="always" /><param name="swliveconnect" value="true" /><embed src="'+flashFile+'" id="f_emb" quality="'+quality+'" menu="true" scale="'+scale+'" allowScriptAccess="always" swliveconnect="true" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100%" height="100%"></embed></object>';
	obj.innerHTML = flash;
}

function sendID() { // tells the Flash object what the current page is
	var f_obj = flashObj();
	f_obj.setDefaultPage(myID);
	if((myMessage)&&(myMessage!='')) {
		f_obj.setPersonalisation(myMessage);	
	}
}

function setText(page) {
	var f_obj = flashObj();
	if(f_obj.getContent) {
		if(page=="showcases") { f_obj.getContent(page,"showShowcases"); } 
		else if(page=="clients") { f_obj.getContent(page,"showClients"); } else {
		f_obj.getContent(page); }
		activeMenu(page);
	} else {
		alert('Hang on a second - it\'s still loading!');
	}
}

function jsAlert(txt) { // can be called from the Flash to output a JavaScript alert
	alert(txt);
}

function activeMenu(id,btn,passedID) {
	btn = (btn) ? btn : id;
	passedID = (passedID) ? passedID : '';
	
	ar_pages = new Object();
	ar_pages.home = "index.php";
	ar_pages.who = "who_we_are.php";
	ar_pages.showcases = "showcases.php";
	ar_pages.portfolio = "portfolio.php";
	ar_pages.contact = "contact.php";
	ar_pages.clients = "clients.php";
	ar_pages.showcase_lbs = "showcase_lbs.php";
	ar_pages.showcase_royal_marsden = "showcase_royal_marsden.php";
	ar_pages.showcase_three = "showcase_three.php";
	ar_pages.showcase_vertex = "showcase_vertex.php";
	
	page = (ar_pages[id]) ? ar_pages[id] : "index.php";
	
	button = document.getElementById("siteButton");
	curURL = window.location.href;
	curPage = window.location.pathname;
	curPage = curPage.substring(curPage.lastIndexOf('/') + 1);
	host = curURL.replace(curPage,'');
	host = host.replace('?site=flash','');
	newURL = host+page+'?site=static';
	newURL += (id=="client") ? "&client_ID="+passedID : '';
	button.href = newURL;
	tm = document.getElementById("div_topMenu");
	activeLink = document.getElementById("menu_"+btn);
	items = tm.getElementsByTagName("a");
	for(i=0;i<items.length;i++){
		if(items[i].className=="active") {
			items[i].className = '';
		}
	}
	activeLink.className = "active";
}

<!-- DETECT FLASH
var MM_contentVersion = 9;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
	var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	for (var i = 0; i < words.length; ++i) {
		if (isNaN(parseInt(words[i])))
		continue;
		var MM_PluginVersion = words[i]; 
	}
	var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
   && (navigator.appVersion.indexOf("Win") != -1)) {
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
	document.write('</SCR' + 'IPT\> \n');
}
//-->
if(!MM_FlashCanPlay) { // FLASH 9 IS NOT INSTALLED
	var answer = confirm("Oops, Flash 9 seems to be unavailable\n\nClick OK to try our HTML site\nClick CANCEL to try your luck loading the Flash (it may not work!)");
	if(answer) {
		curURL = window.location.href;
		curPage = window.location.pathname;
		curPage = curPage.substring(curPage.lastIndexOf('/') + 1);
		host = curURL.replace(curPage,'');
		host = host.replace('?site=flash','');
		host += (host.charAt(host.length-1)!='/') ? '/' : '';
		newURL = host+'index.php?site=static';
		window.location = newURL;
	} else {
		// forced Flash to play
		if(window.addEventListener) window.addEventListener("load", init, false); // for non IE browsers
		else if(window.attachEvent) window.attachEvent("onload", init);			 // for IE
	}
} else {
	if(window.addEventListener) window.addEventListener("load", init, false); // for non IE browsers
	else if(window.attachEvent) window.attachEvent("onload", init);			 // for IE	
}