var winSize = function () {
	var _x = 0, _y = 0;
	if(typeof(window.innerWidth) == "number") {
		// !=ie
		_x = window.innerWidth;
		_y = window.innerHeight;
	} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		// >= ie4
		_x = document.documentElement.clientWidth;
		_y = document.documentElement.clientHeight;
	} else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
		// == ie4
		_x = document.body.clientWidth;
		_y = document.body.clientHeight;
	}
	return {_x:_x, _y:_y}
}

window.onload = function() {
	// So as not to centre the flash and the footer to stretch across
	var wrap = document.getElementById("wrap");
	var footer = document.getElementById("footer");
	//wrap.style.margin = 0;
	var size = winSize();
	var width = size._x;
	width = width <= 950 ? 950 + "px" : width + "px";
	
	wrap.style.width = width;
	
	// On the window resize / load set the width
	setFlashWidth();
	
	// wrap and footer borders
	if( parseInt(width) > 950 ) {
		wrap.style.borderLeft = wrap.style.borderRight = "0 none";
		footer.style.borderLeft = footer.style.borderRight = "0 none";
	}
	
	// Set the logo position
	var flash = document.getElementById("mainFlash");
	var logo = document.getElementById("logo");
	var left = (flash.width / 2) - 404 - 54;
	/*logo.style.left = left + "px";*/
	
	// ie flash bug
	objectSwap();
	
	// Links
	var links = document.getElementsByTagName("a");
	for( var i = 0, len = links.length; i < len; i++ ) {
		var reg = /popup\[(.*)\]/;
		if( links[i].rel.match(reg) ) {
			links[i].onclick = function() {
				var contentId = this.rel.match(reg)[1] + "Content";
				if (document.getElementById(contentId)) {
					whitey("on");
					showContent(document.getElementById(contentId));
				}
				return false;
			}
		}
	}
	load();
}
function whitey( onOff ) {
	var display = document.getElementById("whitey").style.display;
	var whitey = document.getElementById("whitey");
	if( onOff == "on" ) {
		whitey.style.display = "block";
		return true;
	} else if( onOff == "off" ) {
		whitey.style.display = "none";
		return true;
	}
	whitey.style.display = display == "block" ? "none" : "block";
}

function showContent(content) {
	// Hide all popup Content
	var reg = /popup\[(.*)\]/;
	var allLinks = document.getElementsByTagName("a");
	for( var i = 0, len = allLinks.length; i < len; i++ ) {
		if( allLinks[i].rel.match(reg) ) {
			var contentId = allLinks[i].rel.match(reg)[1] + "Content";
			document.getElementById(contentId).style.display = "none";
		}
	}
	
	var links = content.getElementsByTagName("a");
	var logo = document.getElementById("logo");
	logo.style.display = "block";
	var flash = document.getElementById("mainFlash");
	var left = (flash.width / 2) - 404 + 70;
	
	content.style.left = left + "px";
	content.style.display = "block";
	
	for( var i = 0, len = links.length; i < len; i++ ) {
		if( links[i].className.match("closeContent") ) {
			links[i].onclick = function() {
				content.style.display = "none";
				logo.style.display = "none";
				whitey("off");
				return false;
			}
		}
	}
}

function setFlashWidth() {
	var flash = document.getElementById("mainFlash");
	var flashVars = document.getElementById("flashVars");
	var size = winSize();
	var width = size._x;
	
	flash.width = width <= 950 ? 950 : width;
	flashVars.value = "width=" + width + "&height=" + "950";
}
