var game_active = false;
var game_muted = true;
var is_mute = true;
var host = "";

function pop_game()
{
	pwidth = 893;
	pheight = 512;
	$("#pop_game_div").remove();
	game_active = true;
	var t_left = (doc_width - pwidth)/2 - 1;
	var t_top = 113;
	
	var d = '';
	d+= '<div id="pop_game_div" style="';
	d+= 'width:'+pwidth+'px;';
	d+= 'height:'+pheight+'px;';
	d+= 'top:'+t_top+'px;';
	d+= 'left:'+t_left+'px;';
	d+= 'z-index:1000';
	d+= '">';
	d+= '';
	d+= '';
	d+= '<div id="game_volume" style="left:300px;"></div>';
	d+= '';
	d+= '<div id="pop_game_div_flv" ></div>';
	d+= '';
	d+= '';
	d+= '';
	d+= '</div>';
	$("body").append(d);
	
	var flashvars = {};
	flashvars.is_mute = is_mute;
	var params = {};
	var attributes = {};
	attributes.allowScriptAccess = "always";
	attributes.scale = "noscale";
	attributes.id = "pop_game_div_flv";
	if( b.name  == "safari" || b.name == "ie" )
	{
		attributes.wmode = "transparent";
		params.wmode = "transparent";
	}
	swfobject.embedSWF("Index.swf?lang=EN", "pop_game_div_flv", pwidth, pheight, "10.0.0","swfobject/expressinstall.swf", flashvars, params, attributes);

	
	var flashvars = {};
	var params = {};
	var attributes = {};
	attributes.allowScriptAccess = "always";
	attributes.scale = "noscale";
	attributes.id = "SoundFake_flv";
	if( b.name  == "safari" )
	{
		attributes.wmode = "transparent";
		params.wmode = "transparent";
	}
	swfobject.embedSWF("SoundFake/SoundFake.swf", "game_volume", 20, 20, "10.0.0","swfobject/expressinstall.swf", flashvars, params, attributes);
	
	
	mute_players( "site", "false");
}

function pop_game_close()
{
	mute_players( "site", "true");
	$("#pop_game_div").remove();
	game_active = false;
}

function share_facebook( score )
{
	score = score || "";

	var title = document.title;
	var url = window.location.href;
	title = "I just played the ExxonMobil Valve Solve Game!  Score points and get facts about your intake valves.";
	//var url = short_url;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent( url )+'&amp;t='+encodeURIComponent(title),'sharer','toolbar=0,status=0,width=626,height=436');
}

function share_twitter(score)
{
	//console.log('http://twitter.com/home?status=' + content);
	score = score || "";
	
	var title = document.title;
	var url = window.location.href;
	
	title = "I just played the ExxonMobil Valve Solve Game!  Score points and get facts about your intake valves";
	var content = '';
	if( title.length > 100)
	{
		title = title.substr(0,100)+"...";
	}
	content = title + ' ' + url;
	window.open('http://twitter.com/home?status=' + content , 'sharer','toolbar=0,status=0,width=800,height=436');
}

function getFlash( flash_id )
{
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[flash_id] : document[flash_id];
}

function mute_players( flash_id, param_to_mute )
{
	if( flash_id == "site")
	{
		var obj = getFlash("panel-flash");
		obj.to_mute2(param_to_mute);
		is_mute = param_to_mute;
	}
	else if( flash_id == 'game')
	{
		if( game_active == true)
		{
			var obj = getFlash("pop_game_div_flv");
			obj.to_mute(param_to_mute);
		}	
	}
}

function track_muted_game()
{
	if( game_muted == true )
	{
		mute_players("game", "false");
		game_muted = false;
		
		$("#game_volume_css").removeClass("mute_button").addClass("unmute_button");
	}
	else
	{
		mute_players("game", "true");
		$("#game_volume_css").removeClass("unmute_button").addClass("mute_button");
		game_muted = true;
	}
}

function site_flash_position()
{
	var t = (doc_height - 507)/2;
	var l = (doc_width - 900)/2;
	//$("#wrapper").css({"top" : t+"px", "left" : l+"px"});
}

function game_flash_position()
{
	if( game_active == true)
	{
		var t_left = (doc_width - 893)/2 - 1;
		var t_top = ( (doc_height - 512)/2 )+35;
		$("#pop_game_div").css({"left" : t_left+"px"});
	}
}
