
/**
*
*	Klasse zum Initialisierwen einer 
*	"unaufdringlichen" AJAX/PHP 
*	Validierung
*
*	Autor: René Klatt
*
*/
// Klasse erstellen
var CustomerPage = {
	lastOpened: 1,
	
	openFirst:function(){
		new Effect.BlindDown($('game_content_1'), {duration:.6, scaleContent:false});
		$('game_row_1').style.background = '#e5e5e5';
	},
	
	closeLast:function(newContent)
	{
		if(this.lastOpened !== '' && this.lastOpened !== newContent){

			$('game_row_' + this.lastOpened).style.background = '#fff';
			
			new Effect.BlindUp($('game_content_' + this.lastOpened), {duration:.4, scaleContent:false});
		
		}
	},
	
	setOpened:function(elem)
	{
		this.lastOpened = elem;
	},
	
	loadGame:function(id, row)
	{
		if(this.lastOpened == row){
			return;
		}else{
			this.closeLast(row);
			new Ajax.Request(
				'/customer/loadgame/format/html/game/' + id,
				{
					method:"post",
					params:id,
					onSuccess:function(xhr){
						var jsondata = eval( '(' + xhr.responseText + ')' );
						if(jsondata)
						{
							$('game_content_' + row).innerHTML = jsondata['content'];
							CustomerPage.lastOpened = row;
							$('game_row_' + row).style.background = '#e5e5e5';
							new Effect.BlindDown($('game_content_' + row), {duration:.6, scaleContent:false});
							
						}else{
							alert('nich jut');
						}
					},
					onError:function(xhr){
						alert(xhr.responseText);	
					},
					onFailure:function(xhr){
						alert(xhr.responseText);	
					}
				}
			);
		}
	}	
}
Event.observe(window, 'load', function(){
	CustomerPage.openFirst();
});