// =================================================================
// FLACCESS v1.3 LITE (c)2004 Sergi Meseguer (http://zigotica.com/)
// For DOM browsers only and builds always on the fly (on call)
// Released under Creative Commons ShareAlike license:
// http://creativecommons.org/licenses/by-sa/2.0/
// Check out http://meddle.dzygn.com/eng/tools/ or
// http://meddle.dzygn.com/esp/utilidades/ for further info
// BizNuge (16/May/06) incorporated Cross Browser and XHTML capability
// BizNuge (27/Sept/06) for ICIS to include nodal intro to fully rendered page in <body>
// =================================================================

// Set this variable to 1 if you want to alert intermediate steps:
var flaccess_debug;

function checkFlash(min){
	var version = 0;
	if(!min) min = 10;
	if (navigator.plugins)  {
		if(navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var desc = navigator.plugins["Shockwave Flash"].description;
			version = parseInt(desc.substring(16));
		}
		else if(navigator.appVersion.indexOf("MSIE")>-1){
			// loop by Geoff Stearns (geoff@deconcept.com, http://blog.deconcept.com/)
			result = false;
	   		for(var i = min; i >= 3 && result != true; i--){
	    			execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
				version = i;
			}
		}
	}
	return version;
}

function addFlash(minversion,path,width,height,node,imagealt) {
	if(!document.getElementById) return false;

	// defining arguments (from arguments array) in object and embed elements:
	var minargs = 6;
	var objpars = '<param name="movie" value="'+path+'">';
	var empars = ' src="'+path+'" ';
	var align = '';
	var flashid = '';
	var salign = '';
	var flvars = '';
	var allowedObjParams = ["menu","play","quality","scale","devicefont","bgcolor","wmode"];
	var allowedEmbParams = ["menu","play","quality","scale","devicefont","bgcolor","wmode","base","swliveconnect"];

	for(var op=parseInt(arguments.length);op>minargs;op--) {
		var tmp = arguments[op-1].split(":"); var tmpname = tmp[0];var tmpvalue = tmp[1];
		if(allowedObjParams.indexOf(tmpname.toLowerCase()) >-1) {
			objpars += '<param name="'+tmpname+'" value="'+tmpvalue+'">';
		}
		if(allowedEmbParams.indexOf(tmpname.toLowerCase()) >-1) {
			empars += ' '+tmpname+'="'+tmpvalue+'" ';
		}
		if(tmpname.toLowerCase() == "align") {
			align = ' align="'+tmpvalue+'" ';
		}
		if(tmpname.toLowerCase() == "salign") {
			salign = ' salign="'+tmpvalue+'" ';
		}
		if(tmpname.toLowerCase() == "flashvars") {
			if(minversion>=6) flvars = tmpvalue;
			else alert("flashVars support was not available until flash version 6");
		}
	}


	if(checkFlash(minversion) >= minversion){
		if(flaccess_debug==1) alert("minimum flash " + minversion + " is ok, we have version " + checkFlash())

		var col = node.split(",");
		var flid = col[0];
		var parentid = col[1];
		if(minversion>=6){
			if(flvars!='') flvars += '&';
			//flvars += 'flid='+node;
			objpars += '<param name="movie" value="'+flvars+'">';
		}

		var embedTag = '<embed src="http://www.brownesmithbaker.com/'+path+'.swf" id="myFlash" width="'+width+'" height="'+height+'" name="'+path+'" wmode="transparent" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
		var menuTag = '<a href="/Section/Architecture/1/">Architecture</a>&nbsp;&nbsp;&nbsp;<a href="/Section/Interior Design/3/">Interior Design</a>&nbsp;&nbsp;&nbsp;<a href="/Section/Project Management/4/">Project Management</a>&nbsp;&nbsp;&nbsp;<a href="/Section/CDM Coordinator/5/">CDM Coordinator</a>&nbsp;&nbsp;&nbsp;<a href="/Section/Energy Consultancy/7/">Energy Consultancy</a>&nbsp;&nbsp;&nbsp;<a href="/Section/Access Consultancy/8/">Access Consultancy</a>&nbsp;&nbsp;&nbsp;<a href="/Visualisation.asp">Gallery</a>&nbsp;&nbsp;&nbsp;<a href="/Animation.asp">Animation</a>&nbsp;&nbsp;&nbsp;<a href="/Section/Urban Design/10/">Urban Design</a>';

		var obj = '<object type="application/x-shockwave-flash" data="http://www.brownesmithbaker.com/'+path+'.swf" width="'+width+'" height="'+height+'"><param name="movie" value="http://www.brownesmithbaker.com/'+path+'.swf" /><param name="scale" value="noscale" /><param name="wmode" value="transparent" />'+embedTag+'</object>'
		if(flaccess_debug==1) alert(" flid: " + flid + "\n\n" + obj);
               
			flashsection = document.createElement("div");
			flashsection.id = "flashsection";
			flashsection.style.position="absolute";
			flashsection.style.marginLeft="-387.5px";
			flashsection.style.marginTop="-296px";
			flashsection.style.left="50%";
			flashsection.style.top="50%";
			//flashsection.style.height="592px"
			flashsection.innerHTML = obj;
			flashLinks = document.createElement("div");
			flashLinks.id = "flashLinks";
			flashLinks.innerHTML = menuTag;
			flashsection.appendChild(flashLinks);
			tag = document.getElementsByTagName("body");
			tag[0].innerHTML = "";
			tag[0].appendChild(flashsection);
//		tag[0].appendChild(flashLinks);
			
	}
	else {
		var col = node.split(",");
                var parentid = col[1];

                if(flaccess_debug==1) alert("we have version " + checkFlash() + " and we need flash " + minversion)
                
	}

}

// extending Array, by Aaron Boodman (youngpup.net):
Array.prototype.indexOf = function(foo) {
	for (var i = 0; i < this.length; i++)
	if (foo == this[i]) return i;
	return -1;
}
