
/* ********************************************************************** */

function StorePage_Init(){
	$('li.Game').each( function(  ){
    new StorePage_Game( this );
  } );

	$(window).bind('resize', function() {
    Homepage_Icon.CloseWindow();
  });
}

function StorePage_Game( element ){
	this.Init( element );

	this.game_id = null;

 	this.game_id = parseInt( element.id.substring( 5 ) );

	StorePage_Game.Games[ this.game_id ] = this;
}

StorePage_Game.Games = [];

StorePage_Game.Get = function( game_id ){
	if ( StorePage_Game.Games[ game_id ] ){
		return StorePage_Game.Games[ game_id ];
	}
	return null;
}

StorePage_Game.prototype = new Homepage_Icon();

StorePage_Game.prototype.Click = function(){

	if ( $(this.Element).children( 'div.Details' ).length > 0 ){
		this.ShowInfoWindow( $(this.Element).children( 'div.Details' ).get( 0 ).innerHTML );
	} else {
		var self = this;
		jQuery.get(
  	  '../swinxs/game_info.php',
	    {
    	  game_id : this.game_id,
  	    id : this.id
	    },
    	function( data ){
  	    self.ShowInfoWindow( data );
	      RatingTool.InitRating( );
  	  }
	  );
	}
}

StorePage_Game.prototype.ClickDownload = function(){
  var self = this;
	var node = document.createElement( 'span' );
  var downloadAllowed = $(this.Element).find( 'span.Prohibited' ).length == 0;
 	
	if ( downloadAllowed ) {
		var link = document.createElement( 'a' );
		link.appendChild( document.createTextNode( 'Download this game' ) );
  	link.href='../community/downloads.php?type=game&download='+this.game_id;

		node.appendChild( link );
	}

	if ( $(this.Element).find( 'span.Download' ).length > 0 ) {
		if ( downloadAllowed ) node.appendChild( document.createElement( 'br' ) );
		$(this.Element).find( 'span.Download' ).each( function(){
			var message = this.cloneNode(true);
			node.appendChild( message );
			message.style.display = 'block';
			// Dit werkt niet: $(message).show();
		} );
	}

  this.ShowInfoWindow( node );
}

