var nowMarked = 'player1';
var i = 0;

/*
	Ein Spiel direkt über das Profil kaufen
*/
function buyGameProfile(id, continueURL) {

	d_none('qu_' + id);
	d_block('loading_game_' + id);
	
	$('buy_' + id).style.height = 70 + 'px';
	$('buy_' + id).style.width = 75 + 'px';
	
	new Ajax.Request(
		'../ajax_works.php?mode=buy_game',
		{
			method: 'post',
			parameters: 'game_id=' + id,
			onComplete: function (x) {
				if (x.responseText == 'no error') {
					d_none('buy_' + id);

					location.href = './user/' + continueURL;
					
					d_block('qu_' + id);
					d_none('loading_game_' + id);
					
					$('buy_' + id).style.height = 113 + 'px';
					$('buy_' + id).style.width = 380 + 'px';
				} else if (x.responseText == 'not enough points') {
					d_none('buy_' + id);
					
					d_block('qu_' + id);
					d_none('loading_game_' + id);
					
					$('buy_' + id).style.height = 113 + 'px';
					$('buy_' + id).style.width = 380 + 'px';
					
					alert('Du hast leider nicht genug Punkte um dieses Spiel kaufen zu können.');
				} else {
					alert(x.responseText);
				}
			}
		}
	);

}

/*
	Ein Spiel kaufen
*/
function buyGame(id) {

	d_none('qu_' + id);
	d_block('loading_game_' + id);
	d_none('buybutton_' + id);
	
	$('buy_' + id).style.height = 70 + 'px';
	$('buy_' + id).style.width = 75 + 'px';
	
	new Ajax.Request(
		'./ajax_works.php?mode=buy_game',
		{
			method: 'post',
			parameters: 'game_id=' + id,
			onComplete: function (x) {
				if (x.responseText == 'no error') {
					d_none('send_error');
					d_none('buy_' + id);
					
					green('send_error', './');
					$('send_error').innerHTML = 'Das Spiel wurde erfolgreich gekauft und ist jetzt spielbar.';
					d_block('send_error');
					
					d_block('qu_' + id);
					d_none('loading_game_' + id);
					
					$('buy_' + id).style.height = 113 + 'px';
					$('buy_' + id).style.width = 380 + 'px';
				} else if (x.responseText == 'not enough points') {
					$('send_error').innerHTML = 'Du hast leider nicht genug Punkte um dieses Spiel kaufen zu können.';
					d_block('send_error');
					d_block('buybutton_' + id);
					
					d_none('buy_' + id);
					
					d_block('qu_' + id);
					d_none('loading_game_' + id);
					
					$('buy_' + id).style.height = 113 + 'px';
					$('buy_' + id).style.width = 380 + 'px';
				} else {
					alert(x.responseText);
				}
			}
		}
	);

}

function slideIn(id, height) {

	var styleHeight = parseInt($(id).style.height.replace(/px/, ''));
	
	if (styleHeight < height) {
		window.setTimeout("slideIn('" + id + "', '" + height + "')", 5);
		
		d_block(id);
		$(id).style.overflow = 'hidden';
		$(id).style.height = styleHeight + 5 + 'px';
	}
}

function slideOut(id, height) {

	var styleHeight = parseInt($(id).style.height.replace(/px/, ''));
	
	if (styleHeight > 0) {
		window.setTimeout("slideOut('" + id + "', '" + height + "')", 5);
		
		$(id).style.overflow = 'hidden';
		$(id).style.height = styleHeight - 5 + 'px';
	}
}
