var menuFlashPlayer;
var pageLoaded = false;
var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);

function fixPNG() {}

/**
 * Catch left menu object and fix PNG on window load
 */
function init () {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	menuFlashPlayer = isIE ? window['flashLeftMenu'] : document['flashLeftMenu'];
	
	if (version >= 5.5 && version < 7 && document.body.filters) {
		fixPNG();
	}
	makePngVisible();
	
	pageLoaded = true;
	
	// if we are in lobby, scale menu to default size on startup
	if (isLobby) {
		hideMenu ();
	}
}

/**
 * Hide submenus area
 */
function hideMenu () {
	if (pageLoaded && document.getElementById('flashLeftMenu')) {
		document.getElementById('flashLeftMenu').width = 165;
		document.getElementById('flashLeftMenu').height = 260;
	}
}

/**
 * Show submenus area
 */
function showMenu () {
	if (pageLoaded) {
		document.getElementById('flashLeftMenu').width = 789;
		document.getElementById('flashLeftMenu').height = 454;
	}
}


/**
 * Shows wait-div and rediretct to given location
 * 
 * @param String location Target location
 */
function goTo (location) {
	Wait.show ();
	window.location = location;
}


/**
 * Show all PNG's	
 */
function makePngVisible () {
	for (var i = 0; i < document.images.length; i++) {
		var img = document.images[i];
		var imgName = img.src.toUpperCase ();
		if (imgName.substring (imgName.length-3, imgName.length) == "PNG") {
			img.style.visibility = 'visible';
		}
	}
}


function showWaitDiv () {
	Wait.show ('container', { blendColor: '#000', msg: null });
}

Event.observe (window, 'load', init);


function startAnimation() {
	$("gameAnimation_swf").PlayAnimation();
	
}
	
function stopAnimation(){
	$("gameAnimation_swf").StopAnimation();
}

/**
 * Wyświetla popup ECC
 */
function showECCMessage () {
	Cookie.init({name: 'eccpopup', expires: 60*60*24*6004});

	if (Cookie.getData('shown')) {
		return;
	}
	
	Cookie.setData('shown', 1);

	Cookie.init({name: 'pvdownload', expires: 60*60*24*6004});
	Cookie.setData('shown', 1);
	
	var dim = document.viewport.getDimensions ();
	var scroll = document.viewport.getScrollOffsets();			
	
	Interface.showWrapper (document.body, { blendColor: '#000' });
	setTimeout("$('eccPopUp').show();", 0050);
	
	$('eccPopUp').setStyle ({ 'top': 105 + 'px', 'left': dim.width/2 - 400 + 'px' });
}


/**
 * ECC popup - przycisk close
 */
function closeECCMessage () {			
	$('eccPopUp').hide();
	Interface.hideWrapper ();
}


/**
 * ECC popup - przycisk download
 */
function runDownloadNow () {
	closeECCMessage();
	download();
}


/**
 * ECC popup - przycisk instant play
 */
function runInstantPlay () {
	closeECCMessage();
	document.location = '/instantplay';
}

