function showHome( id ){
	new jQuery.ajax({
  		url: 'ajax/home.php',
    	success: function(data){ $(id).innerHTML = data; },
    	error: function(){ alert('Something went wrong...'); }
	});
}


function showSearch( id , search ){
	new jQuery.ajax({
		url: 'ajax/search.php?searchText=' + search,
    success: function(data){ $(id).innerHTML = data; },
    error: function(){ alert('Something went wrong...'); }
	});
}


function showGame( id , game ){
	jQuery.ajax({
		url: 'ajax/game.php?game=' + game,
    success: function(data){ $(id).innerHTML = data; },
    error: function(){ alert('Something went wrong...'); }
	});
}


function showTag( tag , id ){
	jQuery.ajax({
		url: 'ajax/showtag.php?tag=' + tag,
    success: function(data){
    		$(id).innerHTML = data;
    		activeTags = [];
    },
    error: function(){ alert('Something went wrong...'); }
	});
}

function addTag( tag ){
	activeTags.push( tag );
	updateGames();
}

function removeTag( tag ){
	activeTags = activeTags.filter( function(elm){ return elm != tag; } );
	updateGames();	
}

function updateGames(){

	//find all divs
	var dd = jQuery(".gameWrapper");
	
	var noTags = true;
	
	for( property in activeTags ){
		noTags = noTags && activeTags[property] == null;
	}

	if( noTags ){
		dd.css("display","block");
		return;
	}else{
		dd.css("display","none");
	}

	dd.filter(
		function( index ){
			var allow = true;
			var currentId = this;
			activeTags.forEach( function( elm ){ allow = allow && jQuery(currentId).attr("id").match( elm ); } );
			return allow;
		}
	).css("display","block");

}

