/***
START INITIALISE VARS
***/
var dom,
	opera,
	mac,
	size,
	elID;
	
var flash_Ar = new Array();
/***
END INITIALISE VARS
***/	
	
/***
START POPULATE VARS
***/
// UA functionality detection
dom = document.getElementById?true:false;
opera = (navigator.userAgent.indexOf("Opera")!=-1)?true:false;
mac = (navigator.platform.indexOf("Mac")!=-1)?true:false;
elID = false;
/***
END POPULATE VARS
***/

/***
RESOLUTION SWITCHER
***/

function addLoadListener(fn){
	if (typeof window.addEventListener != 'undefined'){
		window.addEventListener('load', fn, false);
	}else if (typeof document.addEventListener != 'undefined'){
		document.addEventListener('load', fn, false);
	}else if (typeof window.attachEvent != 'undefined'){
		window.attachEvent('onload', fn);
	}else{
		return false;
	}
	return true;
};

function attachEventListener(target, eventType, functionRef, capture){
    if (typeof target.addEventListener != "undefined"){
		target.addEventListener(eventType, functionRef, capture);
	}else if (typeof target.attachEvent != "undefined"){
		target.attachEvent("on" + eventType, functionRef);
	}else{
		return false;
	}
    return true;
};

pageChng = function(){
	if(pageValue){
		if(flash_Ar){
			if(pageValue == 1){
				if(size == 2 || mac == true){
					flash_Ar = ["/swf/movie_1024.swf", "flashoverview", "340", "287", ""];
				}else{
					flash_Ar = ["/swf/movie_800.swf", "flashoverview", "258", "287", ""];
				}
			}else if(pageValue == 2){
				if(size == 2 || mac == true){
					flash_Ar = [];
				}else{
					flash_Ar = [];
				}
			}else if(pageValue == 3){
				if(size == 2 || mac == true){
					flash_Ar = ["/swf/news_1024.swf", "flashoverview", "220", "85", ""];
				}else{
					flash_Ar = ["/swf/news_800.swf", "flashoverview", "167", "110", ""];
				}
			}
		}
	}
}

insertFlash = function(elID_func2){
	var fo = new FlashObject(flash_Ar[0], flash_Ar[1], flash_Ar[2], flash_Ar[3], "7", "#FFFFFF");
	fo.addParam("wmode", "transparent");
	fo.addVariable('linkAddress', flash_Ar[4]);
	fo.write(elID_func2);
	
	/* to trap print preview redraw bug in Firefox */
	if (!mac){
		var tgt = document.getElementById(elID_func2);
		tgt.style.width = flash_Ar[2]+"px";
		tgt.style.height = flash_Ar[3]+"px";
		tgt.style.overflow = "hidden";
	}
}

changeFlash = function(elID_mstr){
	if (document.getElementById(elID_mstr)){
		pageChng();
		insertFlash(elID_mstr);
	}
}

function checkBrowserWidth(){
	if(mac !=true){
		var theWidth = getBrowserWidth();
//		alert(theWidth);
	
		if (theWidth == 0){
			var resolutionCookie = document.cookie.match(/(^|;)fc_layout[^;]*(;|$)/);
			if (resolutionCookie != null){
				setStylesheet(unescape(resolutionCookie[0].split("=")[1]));
			}
			else {
				setStylesheet("Large");
				document.cookie = "fc_layout=" + escape("Large");
				size = 2;
			}
			
			addLoadListener(checkBrowserWidth);
			return false;
		}

		if (theWidth > 930 || theWidth == 0){
			setStylesheet("Large");
			document.cookie = "fc_layout=" + escape("Large");
			size = 2;
		}else{
			setStylesheet("Small");
			document.cookie = "fc_layout=" + escape("Large");	
			size = 1;
		}
		changeFlash(elID);
		
		return true;
	}
};

function getBrowserWidth(){
	if (window.innerWidth){
		return window.innerWidth;
	}else if (document.documentElement && document.documentElement.clientWidth != 0){
		return document.documentElement.clientWidth;
	}else if (document.body){
		return document.body.clientWidth;
	}
	return 0;
};

function setStylesheet(styleTitle){
	var currTag;
	if (document.getElementsByTagName){
		for (var i = 0; (currTag = document.getElementsByTagName("link")[i]); i++){
			if (currTag.getAttribute("rel").indexOf("style") != -1 && currTag.getAttribute("title")){
				currTag.disabled = true;
				if(currTag.getAttribute("title") == styleTitle){
					currTag.disabled = false;
				}
			}
		}
	}
	return true;
};

checkBrowserWidth();
attachEventListener(window, "resize", checkBrowserWidth, false);
