window.onresize = function()
{
	for(id in overlayPopupId)
	{
		document.getElementById(overlayPopupId[id]).style.marginLeft = 0;
		document.getElementById(overlayPopupId[id]).style.marginTop = 0;
		if(document.getElementById(overlayPopupId[id]).style.display!='none'){
			if(substr(overlayPopupPosition[id], 0, 5)!='mouse') setElementPosition(overlayPopupId[id], overlayPopupPosition[id]);
		}
	}
}

window.onscroll = function()
{
	for(id in overlayPopupId)
	{
		document.getElementById(overlayPopupId[id]).style.marginLeft = 0;
		document.getElementById(overlayPopupId[id]).style.marginTop = 0;

		if(document.getElementById(overlayPopupId[id]).style.display!='none'){
			if(substr(overlayPopupPosition[id], 0, 5)!='mouse') setElementPosition(overlayPopupId[id], overlayPopupPosition[id]);
		}
	}
}

function switchOverlay(id){
	objPopup = new grayOverlayPopup("objPopup", id);
	objPopup.setGray();	
}

function showOverlayPopup(id,closeAll){
	if(closeAll==null) closeAll = false;
	if(overlayPopupOpacityBackground[id] == 1) switchOverlay(id);
	document.getElementById(overlayPopupId[id]).style.display = 'block';
	setElementPosition(overlayPopupId[id], overlayPopupPosition[id], overlayPopupOffset[id]);
}

function hideOverlayPopup(id){
	if(overlayPopupOpacityBackground[id] == 1) switchOverlay(id);
	document.getElementById(overlayPopupId[id]).style.display = 'none';
}

function grayOverlayPopup(objName, id){
	this.grayDivId = "site"; 
	this.objName = objName;
	this.opacityDivId = "opacity";

	this.popMeDivId = overlayPopupId[id]; 
	this.popMeDivIdContent = "popupContent";
	this.popMeDivIdDescription = "popupDescription";
	this.popMeDivIdTitle = "popupHeader";
	this.grayFilter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)"; // css propertie om grijs te maken IE

	this.killFlash = "true";

	this.bodyBackground = "#900000"; // If != false, dan body is deze kleur
	this.bodyBackgroundGray = "#F0C0C0"; // if != false, dan body is deze kleur in Gray

	this.timer = false; // De timer welke de resize van de opacity div regelt
	this.timerInterval = 100; // En de interval er van

	this.enablegray = false;

	version = parseFloat(navigator.appVersion.split("MSIE")[1]);
	if ( version == 7 && this.enablegray == true ) { // Als het IE 7 is haal het gray eruit en doe de opacity optie ( schijnbaar fuckt IE7 een beetje )
		this.enablegray = false;
	}
}

grayOverlayPopup.prototype.moveOpacity = function () {
	windowHeight = document.documentElement.clientHeight;
	if ( document.getElementById(this.opacityDivId).style.height == "100%" ) {
		document.getElementById(this.opacityDivId).style.height = windowHeight + "px";
	}
	opacheight = document.getElementById(this.opacityDivId).style.height;
	l = opacheight.length;
	posH = opacheight.substr(0, l - 2);
	newPos = document.documentElement.scrollTop + windowHeight;
	if ( newPos > posH ) {
		document.getElementById(this.opacityDivId).style.height = newPos + "px";
	}

	windowWidth = document.documentElement.clientWidth;
	if ( document.getElementById(this.opacityDivId).style.width == "100%" ) {
		document.getElementById(this.opacityDivId).style.width = windowWidth + "px";
	}
	opacwidth = document.getElementById(this.opacityDivId).style.width;
	l = opacwidth.length;
	posW = opacwidth.substr(0, l - 2);
	newPos = document.documentElement.scrollLeft + windowWidth;
	if ( newPos > posW ) {
		document.getElementById(this.opacityDivId).style.width = newPos + "px";
	}
}

grayOverlayPopup.prototype.openAdditional = function () {
	// alle browsers
	// Hier dus de shit als de popup OPEN gaat ( naar gray toe )
//		if ( typeof(document.all) != 'object' ) {
		var flashStats = document.getElementById('flashStats');
		var flashStats2 = document.getElementById('flashStats2');
		if (flashStats!=null) {
			flashStats.style.visibility='hidden';
			}
		if (flashStats2!=null)
			flashStats2.style.visibility='hidden';
//		}
}

grayOverlayPopup.prototype.closeAdditional = function () {
	// alle browsers
	// Hier dus de shit als de popup CLOSE gaat ( naar normaal toe )
//		if ( typeof(document.all) != 'object' ) {
		var flashStats = document.getElementById('flashStats');
		var flashStats2 = document.getElementById('flashStats2');
		if (flashStats!=null)
			flashStats.style.visibility='visible';
		if (flashStats2!=null)
			flashStats2.style.visibility='visible';
//		}
}

grayOverlayPopup.prototype.isInternetExplorer = function () {
	if( typeof(document.all) == 'object' && this.enablegray == true ){
		return true;
	}
}

grayOverlayPopup.prototype.setGray = function () {
	b = document.getElementsByTagName("body");
	objBody = b[0];
	if ( this.isInternetExplorer() == true && this.enablegray == true ) {
		if ( objBody.style.filter == this.grayFilter && objBody.style.filter != undefined ) {
			// Object is gray, set object to normal
			if ( this.bodyBackground != '' || this.bodyBackground != false ) {
				document.bgColor = this.bodyBackground;
			}
			objBody.style.filter = "";
			this.closeSpecial();
			if ( this.killFlash == "true" ) {
				this.startFlashObjects();
			}
		}
		else {
			// Object is normal, set object to gray
			if ( this.bodyBackgroundGray != '' || this.bodyBackgroundGray != false ) {
				document.bgColor = this.bodyBackgroundGray;
			}
			objBody.style.filter = this.grayFilter;
			this.openSpecial();
			if ( this.killFlash == "true" ) {
				this.stopFlashObjects();
			}
		}
	}
	else {
		this.setOpacity(25);
	}
	this.popMe();
}

grayOverlayPopup.prototype.popMe = function () {
	objectPopup = document.getElementById(this.popMeDivId).style;
	if ( objectPopup.display == 'block' ) {
		// Gray stage, set popup div and opacity div (gecko) to normal stage
		if ( this.isInternetExplorer() != true && this.isDiv(this.opacityDivId) == true ) {
			document.getElementById(this.opacityDivId).style.display = 'none';
		}
		else if ( this.isInternetExplorer() == true && this.isDiv(this.opacityDivId) == true ) {
			document.getElementById(this.opacityDivId).style.display = 'none';
			document.getElementById(this.opacityDivId).style.visibility = '';
		}
		clearInterval(this.timer);
		this.closeAdditional();
		objectPopup.display = 'none';
	}
	else {
		// Normale stage, set popup div and opacity div (gecko) to gray stage
		if ( this.isInternetExplorer() != true && this.isDiv(this.opacityDivId) == true ) {
			document.getElementById(this.opacityDivId).style.display = 'block';
		}
		else if ( this.isInternetExplorer() == true && this.isDiv(this.opacityDivId) == true ) {
			document.getElementById(this.opacityDivId).style.display = 'block';
			document.getElementById(this.opacityDivId).style.visibility = 'visible';
			this.setOpacity(0);
		}

		this.timer = setInterval(this.objName + ".moveOpacity()", this.timerInterval);
		this.openAdditional();
		objectPopup.display = 'block';
	}
}

grayOverlayPopup.prototype.setOpacity = function (opacity) {
	if ( this.isDiv(this.opacityDivId) == true ) {
		var object = document.getElementById(this.opacityDivId).style;
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";
	}
}

grayOverlayPopup.prototype.isDiv = function(div) {
	if ( document.getElementById(div) ) {
		return true;
	}
}
grayOverlayPopup.prototype.startFlashObjects = function () {
	flash = document.getElementsByTagName("object");
	for (var i = 0; i < flash.length; i++) { 
		if ( flash[i] ) {
			flash[i].Play(); 
		}
	}
}
grayOverlayPopup.prototype.stopFlashObjects = function () {
	flash = document.getElementsByTagName("object");
	for (var i = 0; i < flash.length; i++) { 
		if ( flash[i] ) {
			flash[i].StopPlay(); 
		}
	}
}

var d_MOUSEPOSITION = Array();
d_MOUSEPOSITION['x'] = 0;
d_MOUSEPOSITION['y'] = 0;

function traceMousePosition(e){
	if(checkBrowser()=='ie'){
		d_MOUSEPOSITION['x'] = event.clientX + (window.pageXOffset || document.documentElement.scrollLeft);
		d_MOUSEPOSITION['y'] = event.clientY + (window.pageYOffset || document.documentElement.scrollTop);
	}else{
		d_MOUSEPOSITION['x'] = e.pageX;
		d_MOUSEPOSITION['y'] = e.pageY;
	}	

	if(d_MOUSEPOSITION['x'] < 0) d_MOUSEPOSITION['x'] = 0;
	if(d_MOUSEPOSITION['y'] < 0) d_MOUSEPOSITION['y'] = 0;

	return true;
}

function getMousePosition(axis){
	if(!axis) return d_MOUSEPOSITION;
	else return d_MOUSEPOSITION[axis];
}
function getScrollPosition(){
	scrollPosition = Array();

	if(typeof(window.pageYOffset) == 'number'){
		scrollPosition['top'] = window.pageYOffset;
		scrollPosition['left'] = window.pageXOffset;
	}
	else if(document.documentElement.scrollTop != undefined){
		scrollPosition['top'] = document.documentElement.scrollTop;
		scrollPosition['left'] = document.documentElement.scrollLeft;
	}
	else if(document.body != undefined){
		scrollPosition['top'] = document.body.scrollTop;
		scrollPosition['left'] = document.body.scrollLeft;
	}
	else {
		scrollPosition['top'] = 0;
		scrollPosition['left'] = 0;
	}

	return scrollPosition;
}
function getScrollSize(){
	scrollSize = Array();
	scrollSize['width'] = document.body.scrollWidth;
	scrollSize['height'] = document.body.scrollHeight;
	return scrollSize;
}


function setElementPosition(id, position, offset) {

	windowSize = getWindowSize();
	scrollPosition = getScrollPosition();
	elementSize = getElementSize(id);

	offsetAr = Array();

	if(offset) {
		if(is_array(offset)) {
			offsetAr['left'] = parseInt(offset['left']);
			offsetAr['top'] = parseInt(offset['top']);
		}else{
			offsetAr['left'] = parseInt(offset);
			offsetAr['top'] = parseInt(offset);
		}
	}else{
		offsetAr['left'] = 0;
		offsetAr['top'] = 0;
	}
	
	if(position=='middle-center') {
		elementTop = Math.round(windowSize['height'] / 2 - elementSize['height'] / 2 + scrollPosition['top']);
		elementLeft = Math.round(windowSize['width'] / 2 - elementSize['width'] / 2 + scrollPosition['left']);
		document.getElementById(id).style.top = elementTop+'px';
		document.getElementById(id).style.left = elementLeft+'px';
	}

	if(substr(position, 0, 5) == 'mouse') {
		elementTop = Math.round(getMousePosition('y'));
		elementLeft = Math.round(getMousePosition('x'));

		if(position == 'mouse-left-bottom' || position == 'mouse-left-top') {
			offsetAr['left'] = offsetAr['left'] * -1;
			elementLeft -= elementSize['width'];
		}

		if(position == 'mouse-left-top' || position == 'mouse-right-top') {
			offsetAr['top'] = offsetAr['top'] * -1;
			elementTop -= elementSize['height'];
		}

		elementLeft = elementLeft + offsetAr['left'];
		elementTop = elementTop + offsetAr['top'];

		document.getElementById(id).style.top = elementTop+'px';
		document.getElementById(id).style.left = elementLeft+'px';

	}
	
}

function getPosition(obj) {
	position = Array();
	if (obj.offsetParent) {
		do {
			position['left'] += obj.offsetLeft;
			position['top'] += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return position;
}
function substr( f_string, f_start, f_length ) {

	if(f_start < 0) {
        f_start += f_string.length;
    }
 
    if(f_length == undefined) {
        f_length = f_string.length;
    } else if(f_length < 0){
        f_length += f_string.length;
    } else {
        f_length += f_start;
    }
 
    if(f_length < f_start) {
        f_length = f_start;
    }
 
    return f_string.substring(f_start, f_length);

}
function in_array(stringToSearch, arrayToSearch) {
	for (s = 0; s < arrayToSearch.length; s++) {
		thisEntry = arrayToSearch[s].toString();
		if (thisEntry == stringToSearch) {
			return true;
		}
	}
	return false;
}

function getWindowSize(){

	if(self.innerWidth){
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}else if(document.documentElement && document.documentElement.clientWidth){
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}else if(document.body){
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	windowSize = Array();
	windowSize['width'] = windowWidth;
	windowSize['height'] = windowHeight;
	return windowSize;

}

function setWindowSize(newWidth, newHeight){
	windowSize = getWindowSize();

	extraWidth = newWidth - windowSize['width'];
	extraHeight = newHeight - windowSize['height'];

	window.resizeBy(extraWidth, extraHeight);
}

function getWindowPosition(){
	position = Array();
	if(document.all){
		position['left'] = window.screenLeft;
		position['top'] = window.screenTop;
	}else{
		position['left'] = window.screenX;
		position['top'] = window.screenY;
	}
	return position;
}

function setWindowPosition(left, top){
	window.moveTo(left, top);
}

function moveWindowTop() {
	setWindowPosition(0,0);
}





function getScreenCenterPosition(windowWidth, windowHeight){
	screenSize = getScreenSize();
	centerPosition = Array();
	centerPosition['left'] = (screenSize['width'] - windowWidth) / 2;
	centerPosition['top'] = (screenSize['height'] - windowHeight) / 2;
	return centerPosition;
}

function getWindowCenterPosition(mainWindowSize, mainWindowPosition, centerWindowSize){

	mainWindowPosition['left'] -= 0;
	mainWindowPosition['top'] -= 0;

	centerPosition = Array();
	centerPosition['left'] = mainWindowSize['width'] / 2 - centerWindowSize['width'] / 2 + mainWindowPosition['left'];
	centerPosition['top'] = mainWindowSize['height'] / 2 - centerWindowSize['height'] / 2 + mainWindowPosition['top'];
	return centerPosition;
}
function checkBrowser(){
	ie = (navigator.appName=="Microsoft Internet Explorer")?true:false; 
	ns = (navigator.appName=="Netscape")?true:false; 
	if(ie) return 'ie';
	else if(ns) return 'ns';
}
function getElementSize(id){
	elementSize = Array();
	elementSize['width'] = document.getElementById(id).clientWidth;
	elementSize['height'] = document.getElementById(id).clientHeight;
	return elementSize;
}




var overlayPopupId = Array();
var overlayPopupPosition = Array();
var overlayPopupOpacityBackground = Array();
var overlayPopupOffset = Array();
overlayPopupId['1'] = 'overlayPopup1';
overlayPopupPosition['1'] = 'middle-center';
overlayPopupOpacityBackground['1'] = '1';
overlayPopupOffset['1'] = '';
function selectGame(){ showOverlayPopup(1); }
