var posx = 300;
var posy = 240;
var active = 'start';

function load() {
	if (self.innerHeight) // all except Explorer
	{
		posx = self.innerWidth/2;
		posy = self.innerHeight/2;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		posx = document.documentElement.clientWidth/2;
		posy = document.documentElement.clientHeight/2;
	}
	else if (document.body) // other Explorers
	{
		posx = document.body.clientWidth/2;
		posy = document.body.clientHeight/2;
	}
/* alert(posx + " <-x, y-> " + posy); */
}

function makemenu() {
}

function spielupdate (cmd, params) {
	new Ajax.Updater(elem, 'get.php', params);
	return false;
}

/* Warten.... */
function wstart() {
	elm = document.createElement('div');
	elm.id = 'wait';
	img = document.createElement('img');
	img.setAttribute('src', 'img/wait.gif');
	elm.appendChild(img);
	$('body').appendChild(elm);
	Element.hide('wait');
	$('wait').style.left  = (posx - 100) + 'px';
	$('wait').style.top = (posy - 40) + 'px';
	$('wait').style.zIndex = 9999;
	new Effect.Appear('wait');

}
function wend() {
	new Effect.Opacity('wait', {to: 0, afterFinish : function () { $('body').removeChild($('wait')); }});
}

/* Menubefehle */
function ubersicht() {
	wstart();
	new Ajax.Updater('content', 'get.php', {method: 'get', parameters: 'action=ubersicht&'+s()});
	wend();
	active = 'ubersicht';
	return false;
}
function meinewetten() {
	wstart();
	new Ajax.Updater('content', 'get.php', {method: 'get', parameters: 'action=meinewetten&'+s()});
	wend();
	active = 'meinewetten';
	return false;
}
function spiele() {
	wstart();
	new Ajax.Updater('content', 'get.php', {method: 'get', parameters: 'action=spiele&'+s(), onComplete: wend});
	active = 'spiele';
	return false;
}
function punkte() {
	wstart();
	new Ajax.Updater('content', 'get.php', {method: 'get', parameters: 'action=punkte&'+s(), onComplete: wend});
	active = 'punkte';
	return false;

}
function allespieler() {
	wstart();
	new Ajax.Updater('content', 'get.php', {method: 'get', parameters: 'action=alle&'+s(), onComplete: wend});
	active = 'allespieler';
	return false;
}
function einst() {
	wstart();
	new Ajax.Updater('content', 'get.php', {method: 'get', parameters: 'action=einst&'+s(), onComplete: wend});
	active = 'einst';
	return false;

}
function anleitung() {
	wstart();
	new Ajax.Updater('content', 'get.php', {method: 'get', parameters: 'action=anleitung&'+s(), onComplete: wend});
	active = 'anleitung';
	return false;

}
function stats() {
	wstart();
	new Ajax.Updater('content', 'get.php', {method: 'get', parameters: 'action=stats&'+s(), onComplete: wend});
	active = 'stats';
	return false;
}

function logout() {
	return true;
}
function s() {
//	global sidname, sid;
	return sidname+'='+sid;
}

/* Wettenabgabe vorbereiten */
function wetten(gid) {
	$('body').appendChild(createDiv('dover', 'over'));
	$('dover').style.position = 'fixed';
	$('dover').style.zIndex = 1000;
	Element.hide('dover');
	new Ajax.Updater('over', 'get.php', {method: 'post', parameters: 'action=wetten&type=ajax&gid='+gid});
	$('dover').style.left = (posx - 200) + 'px';
	$('dover').style.top = (posy - 150) + 'px';
	new Effect.Appear('dover');
	return false;

}

/* Wette setzten */
function setzwette() {
	wstart();
	// Parameter zusammenbauen
	params = 'action=wetten&submit=senden&type=ajax&gid=' + document.wetten.gid.value + '&stand1=' +
		document.wetten.stand1.value + '&stand2=' + document.wetten.stand2.value;
	new Ajax.Updater('over', 'get.php', {method: 'post', parameters: params, onComplete: wend});
	meinupdate();
	return false;
}
function meinupdate() {
	if(active == 'meinewetten') meinewetten();
//	if(active == 'spiele') spiele();

}

function setzeinst() {
	wstart();
	params = 'action=einst&submit=&Uuml;bernehmen&type=ajax';
	len = document.einst.elements.length;
	for(i=0; i<len; i++) {
		params += '&' + document.einst.elements[i].name + '=' + document.einst.elements[i].value;
	}
	new Ajax.Updater('content','get.php', {method: 'post', parameters: params, onComplete: wend});
	return false;
}

function ausbl(elem) {
	new Effect.Opacity(elem, {to: 0, afterFinish: function () { body.removeChild($(elem)); }});
	return false;
}

function createDiv(name, contentname) {
	ov = document.createElement('div');
	ov.id = name;
	close = document.createElement('p');
	close.setAttribute('style', 'width:100%;text-align:right;');
	cli = document.createElement('img');
	cli.setAttribute('src','img/x.gif');
	close.appendChild(cli);
	//ov.appendChild(close);
	cont = document.createElement('div');
	cont.id = contentname;
	ov.appendChild(cont);
	return ov;
}

