$( document ).ready( function( ) {
    
	// Tabs
	$(".tagsBox div.tabs div").hide();
	$(".tagsBox div.tabs div.active").show();
	
	$(".tagsBox li").click(function(){
		// Activate tab
		$(".tagsBox li").removeClass("active");
		$(this).addClass("active");
		
		// Switch content
		var obj = ".tagsBox div.tabs div." + $(this).children("a").attr("class");
		$(".tagsBox div.tabs div").hide();
		$(obj).fadeIn("slow");
	});
	
	//
	// Path naar thumbs
	//
	
	var path = "screenshots/";
	
	// Game thumbs
	$(".vechtBox li a").hover(function(){
		$(this).parent().css("z-index", "800");
		$(this).parent().parent().parent().css("z-index", "800");
		$(this).append("<div class='gameThumb'><img src='" + path + $(this).attr("rel") + "' alt='' /><h3>" + $(this).html() + "</h3></div>");
	},function(){
		$(this).parent().css("z-index", "10");
		$(this).parent().parent().parent().css("z-index", "10");
		$(".gameThumb").remove();
	});
	
	// Zet resolutie goed voor 1024x768
	if((screen.width<=1024) && (screen.height<=768))
	{
		$("#wrapper").css("overflow", "hidden");
		$("#mainCntr").css("left", "-33px");
	}
	
	// Fix game boxes in IE
	if($.browser.msie)
	{
		$(".vechtBox li").css("margin-bottom", "-3px");
	}
	
	
	$( function( ) {
		
		$( 'img.tooltip' ).tooltip( { 
		    track: true,
		    delay: 0,
		    showURL: false,
		    extraClass: 'right',
		    bodyHandler: function( ) {
		    	
		        return ( $( this ).attr( 'data' ) );
		        
		    }
		    
		} );
		
	}) ;

});

function addFavorite( ) {
    
	if ( window.sidebar ) { // Mozilla Firefox Bookmark
        
        window.sidebar.addPanel( 'Speel de leukste spellen op Mijngame.nl', 'http://www.mijngame.nl', '' );
        
    } else if ( window.external ) { // IE
        
        window.external.AddFavorite( 'http://www.mijngame.nl', 'Speel de leukste spellen op Mijngame.nl' );
        
    } else {
        
        alert( 'Helaas, deze functie is niet mogelijk vanuit een andere browser dan Internet Explorer of FireFox.' );
        
    }
    
    return false;
    
}

function setHomepage( ) {
    
    if ( document.all ) {
        
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage( 'http://www.mijngame.nl' ); 
        
    } else if ( window.sidebar ) {
        
        alert( 'Helaas, deze functie is niet mogelijk vanuit een andere browser dan Internet Explorer' );
        
    }
    
    return false;
    
}

  function VoteGame( gameID, vote )
  {

          var handler = null;

          /*
            Set POST variable's
          */

          var posts            = new Array();

          /*
            POST'S
          */

          posts[ 'g' ]        = gameID;
          posts[ 'v' ]        = vote;

          if ( gameID != '' && vote != '' )
          {

                  do_request_function = function ()
                  {

						  if ( typeof handler.xmlhandler.responseText != undefined && handler.readystate_ready_and_ok( ) )
                          {

                                  $P = document.getElementById( 'voteBox' );

                                  if ( $P )
                                  {

                                          $P.innerHTML = 'Bedankt voor je stem!<br />';
                                          
                                  }
                                  
								  arrInfo = handler.xmlhandler.responseText.split( '|' );
                                  
                                  $Label = document.getElementById( 'votePercent' );
								  $Label.innerHTML = arrInfo[ 0 ];
                                  
                                  $Label = document.getElementById( 'voteAmount' );
								  $Label.innerHTML = arrInfo[ 1 ];
                                  
                                  $Image = document.getElementById( 'voteImage' );
                                  $Image.width = arrInfo[ 2 ];

                          }

                  }

                  handler = new XMLHttp_request();

                  handler.process( url + '/ajax/vote.php', 'POST', handler.format_for_post(posts) );
                  handler.onreadystatechange( do_request_function );

          }

  }
  
function addList( game_id ) {
	
	var handler = null;
	var posts = new Array();
	posts[ 'game_id' ] = game_id;
	
	if ( game_id != '' ) {
		
		do_request_function = function( ) {
			
			if ( typeof handler.xmlhandler.responseText != undefined && handler.readystate_ready_and_ok( ) ) {
				
				if ( handler.xmlhandler.responseText == 'OK' ) {
					
					alert( 'Dit spel is succesvol toegevoegd aan je favorieten!' );
					
				} else if ( handler.xmlhandler.responseText == 'NOTOK' ) {
					
					alert( 'Het bericht is al toegevoegd aan je favorieten.' );
					
				}
				
			}
			
		}
		
		handler = new XMLHttp_request( );
		handler.process( url + '/ajax/list.php', 'POST', handler.format_for_post(posts) );
		handler.onreadystatechange( do_request_function );
		
	}
	
}
