/****************************************
|
| Cantorion Choir
| Created by: Kevin Biskaborn
| Copyright 2008 ScriptReaction
| http://www.scriptreaction.com
|
****************************************/

var global = {
	level: "", //include folder level
	launch: function (){
		//flashFilter: params: brd=borderWidth, brdclr=borderColour(default=fff), var=varInName, value=varInValue, name=flashMovieId, src, wmode(default=opaque)
		var divArray = document.getElementsByTagName("div");
		for(var divCount=0; divCount<divArray.length; divCount++){
			var whichDiv = divArray[divCount];
			var divClass = whichDiv.className;
			if(divClass != "" && divClass == "flash"){
				var divId = "flashCtr_" + divCount;
				whichDiv.setAttribute('id',divId);
				var _width = parseInt(whichDiv.style.width);
				var _height = parseInt(whichDiv.style.height);
				var _border = parseInt(whichDiv.getAttribute("brd"));
				if(_border > 0){
					var _colour = whichDiv.getAttribute("brdclr");
					_colour = (_colour == null) ? "fff" : _colour;
					whichDiv.style.border = _border + "px solid #" + _colour;
				}else{
					whichDiv.style.border = "0px";
				}
				var _var = whichDiv.getAttribute("var");
				if(_var != null){
					_value = whichDiv.getAttribute("value");	
				}else{
					_var = _value = "";
				}
				var _name = whichDiv.getAttribute("name");
				var _id = (_name != null) ? _name : "";
				var _src = whichDiv.getAttribute("src");
				var _wmode = whichDiv.getAttribute("wmode");
				_wmode = (_wmode != null) ? _wmode : "opaque";
				
				var x = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+flashFilter.fv[0]+',0,0,0" width="'+_width+'" height="'+_height+'" id="'+_id+'" align="absmiddle">';
					x+= '<param name="movie" value="'+_src+'" /><param name="quality" value="high" /><param name="menu" value="false" /><param name="wmode" value="'+_wmode+'" /><param name="flashvars" value="'+_var+'='+_value+'" /><param name="swliveconnect" value="true" /><param name="allowScriptAccess" value="always" />';
					x+= '<embed src="'+_src+'" width="'+_width+'" height="'+_height+'" flashvars="'+_var+'='+_value+'" name="'+_id+'" wmode="'+_wmode+'" quality="high" menu="false" swliveconnect="true" allowScriptAccess="always" align="absmiddle" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></object>';
				
				//no flash player
				if(!global.hasFlash){
					var checkA = "global_banner.swf";
					var checkB = "side_photo_arm.swf";
					var checkC = "page_masthead.swf";
					var checkD = "contentbox_index";
					var checkE = "contentbox_cmm";
					var checkF = "contentbox_robotic";
					if(_src.slice(-(checkA.length)) == checkA){
						x = "<img src=\"images/common/global_masthead.jpg\" alt=\"AMTI - Advance Manufacturing Technologies Inc.\" />";
					} else if (_src.slice(-(checkB.length)) == checkB){
						x = "<img src=\"images/common/global_side_arm.jpg\" alt=\"AMTI - Advance Manufacturing Technologies Inc.\" />";
					} else if (_src.slice(-(checkC.length)) == checkC){
						x = "<img src=\"images/common/page_masthead.jpg\" alt=\"AMTI - Advance Manufacturing Technologies Inc.\" />";
					} else if (_src.slice(-(checkD.length)) == checkD){
						x = "<img src=\"images/amti_gfx_logo.jpg\" alt=\"AMTI - Advance Manufacturing Technologies Inc.\" />";
					} else if (_src.slice(-(checkE.length)) == checkE){
						x = "<img src=\"images/amti_cmm_inspection.jpg\" alt=\"AMTI - Advance Manufacturing Technologies Inc.\" />";
					} else if (_src.slice(-(checkF.length)) == checkF){
						x = "<img src=\"images/amti_robotic_weldcell.jpg\" alt=\"AMTI - Advance Manufacturing Technologies Inc.\" />";
					} else {
						x = '<div class="noflash" style="width:'+_width+'px;height:'+_height+'px;line-height:'+_height+'px;text-align:center;"><a href="http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">Your Flash Player needs to be upgraded to view this content. Visit Adobe.com...</a></div>';
					}
				}
				
				global.setDivContent(divId,x);
			}
		}
		//control document images
		for(var a=0; a<document.images.length; a++){
			var b = document.images[a];
			b.galleryimg = "no";
			b.border = 0;
			if(shell.browser == "ie"){
				b.alt = "";
			}
		}
	},
	goTop: function (){
		var y1=y2=y3=0;if(document.documentElement){y1=document.documentElement.scrollTop||0;};if(document.body){y2=document.body.scrollTop||0;};
		y3=window.scrollY||0;var y=Math.max(y1,Math.max(y2,y3));window.scrollTo(0,Math.floor(y/1.4));if(y>0){window.setTimeout("global.goTop()",25);};
	},
	emailcount: 0,
	email: function (){
		global.emailcount++;
		/*domain*/ var a = arguments[0];
		/*ca,com*/ var b = arguments[1];
		/*idname*/ var c = arguments[2];
		if(typeof(c)=='undefined'){
			c = b;
			b = 'com';
		}
		this['email' + global.emailcount] = c + '@' + a + '.' + b;
		document.write('<span onclick="global.doEmail(' + global.emailcount + ')" style="font-weight:normal;margin:0px;"><a href="#" onclick="return false">' + this['email' + global.emailcount] + '</a></span>');
	},
	doEmail: function (){
		var a = arguments[0]; top.location = 'mailto:' + this['email' + a];
	},
	forceEmail: function (){
		/*domain*/ var a = arguments[0];
		/*ca,com*/ var b = arguments[1];
		/*idname*/ var c = arguments[2];
		if(typeof(c)=='undefined'){
			c = b;
			b = 'com';
		}
		var address = c + '@' + a + '.' + b;
		top.location = 'mailto:' + address;		
	},
	setDivContent: function (divId,content){
		if(document.all){
			document.all[divId].innerHTML = content;
		}else{
			document.getElementById(divId).innerHTML = content;
		}
	},
	addEvent: function (object,eventType,functionName){
		if(object.addEventListener){
			object.addEventListener(eventType, functionName, false);
			return true;
		}else if(object.attachEvent){
			var x = object.attachEvent("on"+eventType, functionName);
			return x;
		}else{
			return false;
		}	
	},
	setAlpha: function (object,opacity){
		opacity = (opacity == 100) ? 99.999 : opacity;
		object.style.filter = "alpha(opacity:" + opacity + ")"; //ie/win
		object.style.KHTMLOpacity = opacity/100; //safari<1.2,konqueror
		object.style.MozOpacity = opacity/100; //older mozilla/firefox
		object.style.opacity = opacity/100; //safari 1.2,newer firefox/mozilla,css3
	}
}
var flashFilter = { //a ScriptReaction extension of: Unobtrusive Flash Objects (flashFilter) v3.20 <http://www.bobbyvandersluis.com/ufo/
	controls: {
		minPlayerVersion: 6
	},
	launch: function (){
		flashFilter.fv = [0,0];
		flashFilter.detectVersion();
		global.hasFlash = (flashFilter.hasVersion(flashFilter.controls.minPlayerVersion)) ? true : false;
	},
	hasVersion: function (major) {
		return (flashFilter.fv[0] > major) ? true : false;
	},
	detectVersion: function (){
		if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object") {
			flashFilter.pluginType = "npapi";
			var _d = navigator.plugins["Shockwave Flash"].description;
			if (typeof _d != "undefined") {
				_d = _d.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
				var _m = parseInt(_d.replace(/^(.*)\..*$/, "$1"), 10);
				var _r = /r/.test(_d) ? parseInt(_d.replace(/^.*r(.*)$/, "$1"), 10) : 0;
				flashFilter.fv = [_m, _r];
			}
		}
		else if (window.ActiveXObject) {
			flashFilter.pluginType = "ax";
			try { // avoid fp 6 crashes
				var _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
			}
			catch(e) {
				try { 
					var _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
					flashFilter.fv = [6, 0];
					_a.AllowScriptAccess = "always"; // throws if fp < 6.47 
				}
				catch(e) {
					if (flashFilter.fv[0] == 6) return;
				}
				try {
					var _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				}
				catch(e) {}
			}
			if (typeof _a == "object") {
				var _d = _a.GetVariable("$version"); // bugs in fp 6.21/6.23
				if (typeof _d != "undefined") {
					_d = _d.replace(/^\S+\s+(.*)$/, "$1").split(",");
					flashFilter.fv = [parseInt(_d[0], 10), parseInt(_d[2], 10)];
				}
			}
		}
	},
	get: function (id, vars){
		var output = "";
		switch(id){
			case "index_banner":
				output += '<div class="flash" src="assets/flash/index_banner.swf" var="inputRequest" value="' + vars + '" style="width:602px;height:130px;"></div>';
				break;
		}
		document.writeln(output);
	}
}

/********** global init **********/
flashFilter.launch();
global.addEvent(window, "load", global.launch);
