//pops up a window with store help
function storehelpPopup(host)
{
	args = "alwaysRaised=yes,dependent=no,scrollbars=yes,width=400,Height=400,innerwidth=0,innerHeight=0";
	popUpWindow=window.open(host+"/library/store/about/?language="+language, "storehelp", args);
	popUpWindow.focus();
}


//brings up display language box
/*function lang_change()
{
	document.getElementById('grey').style.display='block';
	document.getElementById('language_select').style.display='block';
	
	//fake page path generation for google tracking code
	urchinTracker('languageselector');
	console.log('languageselector');				
}*/
function lang_change(){
	if(document.getElementById('lang_popup').style.display == "block")
		document.getElementById('lang_popup').style.display = "none";
	else
		document.getElementById('lang_popup').style.display = "block";
	urchinTracker('languageselector');
	console.log('languageselector');
}

/*function hide_lang()
{
	document.getElementById('grey').style.display='none';
	document.getElementById('language_select').style.display='none';
}*/


//menu stuff
function toggle(name)
{
	/*
	if(document.getElementById(name).style.display=='none')
	{
		Effect.BlindDown(name);
	}
	else
	{
		Effect.BlindUp(name);
	}*/
	
	Effect.toggle(name,'blind',{duration:0.5});
}

function load(name,url)
{
	Effect.Puff(name);
	self.location.href=url
}



//minisite stuff
function load_minisite_section(game,section)
{
	document.getElementById('gamecontent').innerHTML="<img src='images/loading.gif' id='loading_gif' alt='Loading...'/>";
	ajax("library/game/core2/content.php?game="+game+"&subsection="+section+"&language="+language,update_minisite_section);
	
	//fake page path generation for google tracking code
	urchinTracker('games/'+game+'/'+section);
	console.log('games/'+game+'/'+section);
}

function update_minisite_section()
{
	if(http.readyState == 4)
	{
		document.getElementById('gamecontent').innerHTML=http.responseText;
		var section=document.getElementById('game_html').className;
		init_javascript(section);

	}
}

function init_javascript(section)
{
	if(window.after_ajax)
	{
		after_ajax(section);
	}
	if(section=='screenshots')
	{
		myLightbox.updateImageList();					
	}
	if(section=='desktops')
	{
		select_correct_size();
	}
}

function createRequestObject()
{
		var ro;
		var browser = navigator.appName;
		if(browser == "Microsoft Internet Explorer")
		{
				ro = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else
	{
				ro = new XMLHttpRequest();
		}
		return ro;
}


function ajax(source,response_function)
{
		http.open('get',source);
		http.onreadystatechange = response_function;
		http.send(null);
}

function doPopup(url,name,w,h)
{
	popUpWindow=null
	x = ((screen.width/2)-w/2);
	y = ((screen.height/2)-h/2);

	args = "alwaysRaised=yes,dependent=no,scrollbars=no,width="+(w+15)+",height="+(h+20)+",innerwidth=0,innerHeight=0";
	popUpWindow=window.open(url, name ,args);
	popUpWindow.focus();
}


//sets desktops to be on the right type by default		
function select_correct_size()
{
	//This is currently disabled. I didn't like it. -Ian
	
	//options=document.getElementsByTagName('option');
	//string=screen.width + ' x ' + screen.height;
	//for (i=0;i< options.length;i++)
	//{
	//	if(options[i].innerHTML == string)
	//	{
	//		options[i].selected='selected';
	//	}
	//	
	//}
}

function get_desktop_image(image)
{
	self.location.href='/library/game/desktops/desktop.php?'+document.getElementById('res_for_'+image).value;
}

//used in the store description page
function screenshot_to_trailer(game,object,vidtype)
{
	
	//swaps out the image for the video we've created
	// a=object.parentNode;
	// object.style.display='none';
	// a.innerHTML+= "<embed class=\"screenshot\" src=\"/data/games/"+game+"/trailers/store."+vidtype+"\" width=\"200\" height=\"240\" >";
	Element.replace(object,"<embed class=\"screenshot\" src=\"/data/games/"+game+"/trailers/store."+vidtype+"\"  />");

}



//function executed on load
function on_load()
{
	language=document.getElementById('page_language').value;
}


var http = createRequestObject();
var language;
window.onload=on_load;


