function set_cookie(name, value, days)
{
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function get_cookie(name)
{
  var ca = document.cookie.split(';');
  var nameEQ = name + "=";
  for(var i=0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
  return null;
}

function delete_cookie(name)
{
  createCookie(name, "", -1);
}
function fix_ie_hover_nav()
{
	if (document.all&&document.getElementById) 
	{
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) 
		{
			with(navRoot.childNodes[i])
			{
				if (nodeName=="LI") 
				{
					onmouseover=function() { this.className = "hover"; }
  					onmouseout=function() { this.className=""; }
   				}
			}
 		}
	}
}
 /* adds roll-over effect for games sections */
function fix_ie_hover_games()
{
	if(document.all&&document.getElementById)
	{
		roots = new Array(2);
		roots[0] = 'game_type_group';
		roots[1] = 'game_pictures';
		for(n=0;n<roots.length;n++)
		{
			gamesRoot = document.getElementById(roots[n]);
			if(gamesRoot)
			{
				for(i=0;i<gamesRoot.childNodes.length;i++)
				{
					with(gamesRoot.childNodes[i])
					{
						if(nodeName=="A")
						{ 
							onmouseover = function() { i = 5; find_div = this; while(find_div.nodeName != 'DIV' && i--) find_div = find_div.nextSibling; if(i) find_div.className += " hover"; }
							onmouseout = function()  { i = 5; find_div = this; while(find_div.nodeName != 'DIV' && i--) find_div = find_div.nextSibling; if(i) find_div.className = find_div.className.substring(0,find_div.className.length-5); }
						}
					}
				}
			}
		}
	}
}

function set_currency(x,y)
{
	//alert(get_cookie('currency'));
	old_currency = get_cookie('currency');
	//document.cookie = "currency=" + x;
	set_cookie('currency',x,30);
	//alert(document.cookie);
	bodytag = document.getElementsByTagName("body")[0];
	if(y) {
		with(bodytag)
			className = className.substring(0,className.length - old_currency.length);
		//location.reload();
	}
	bodytag.className += (" " + x);
}

function setup_currency_nav()
{
	ctag = document.getElementById("usd").childNodes[0];
	if(ctag)
		ctag.onclick = function() { set_currency('usd',true); }
	ctag = document.getElementById("euro").childNodes[0];
	if(ctag)
		ctag.onclick = function() { set_currency('euro',true); }
	ctag = document.getElementById("pound").childNodes[0];
	if(ctag)
		ctag.onclick= function() { set_currency('pound',true); }
	ctag = document.getElementById("yen").childNodes[0];
	if(ctag)
		ctag.onclick = function() { set_currency('yen',true); }
}
do_onloads = function() 
{
	fix_ie_hover_nav();
	fix_ie_hover_games();
	currency = get_cookie('currency');
	if(!currency) currency = 'usd';
	set_currency(currency,false);
	setup_currency_nav();
	if(window.initLayer)
		initLayer();
}
/*
doreload = function()
{
	location.reload();
}
*/
function set_graphic(x,y)
{
	document.getElementById(x).src= 'images/download/' + y; 
	return true;
}
window.onload=do_onloads;
//window.onresize = doreload;