$( function() {
	$( '#homepage-division a img' ).fadeTo( 0, 0.3 );
	$( '#footer-right a img' ).fadeTo( 0, 0.1 );
	
	// side games hover

	$( '#game-characters-range li, #characters-list li, #number-pages li' ).hover( function() {
		$( this ).addClass( 'selectedListGrey' );
	}, function() {
		$( this ).removeClass( 'selectedListGrey' );
	} );
	
	// top nav hover
	
	$( '#homepage-division a img' ).hover( function() {
		$( this ).fadeTo( 100, 1 );
	}, function() {
		$( this ).fadeTo( 100, 0.3 );
	} );
	
	// footer dev icon
	
	$( '#footer-right a img' ).hover( function() {
		$( this ).fadeTo( 250, 1 );
	}, function() {
		$( this ).fadeTo( 250, 0.1 );
	} );
} );

// SIDE GAMES LIST

function swapGamesList( page, character, game_id ) {
	$.ajax( {
		url: '/ajax/games_list/',
		type: 'post',
		data: ( {
			character: character,
			page: page,
			game_id: game_id
		} ),
		dataType: 'json',
		success: function( response ) {
			var pages_list_html;
			
			$( '#character-page li' ).removeClass();
			$( '#number-pages li' ).removeClass();
			
			pages_list_html = '';
			$.each( response.games, function( i, v ) {
				pages_list_html += '<div>' + response.arrow_image_path + ' <a href="' + v.url + '">' + v.name + '</a></div>';
			} );
			$( '#games-title' ).html( pages_list_html );
			
			$( '#games-list-character-' + response.current_character ).addClass( 'selectedList' );
			$( '#number-pages-' + response.page ).addClass( 'selectedList' );
			
			$.each( $( '#pages-list li' ), function( i, v ) {
				if( i < response.pages ) {
					$( this ).attr( 'onclick', 'swapGamesList( ' + ( i + 1 ) + ', \'' + response.current_character + '\', \'\' )' );
				} else {
					$( this ).attr( 'onclick', '' );
				}
			} );
			
			$( '#number-pages-' + response.pages ).nextAll().addClass( 'noPage' );
		}
	} );
}

// END SIDE GAMES

// TOP GAMES

function swapToplist( list ){
	$.ajax( {
		url: '/ajax/top_games/',
		type: 'post',
		data: ( {
			list: list
			
		} ),
		dataType: 'json',
		success: function( response ) {
			var toplistDivision, i;
			
			toplistDivision = '';
			
			$.each( response.games, function( i, v ) {
				toplistDivision += '<div>' + response.arrow_image_path + ' <a href="' + v.url + '">' + v.name + '</a></div>';
			} );
			
			$( '#toplist-division' ).html( toplistDivision );
		}
	} );
}

// END TOP GAMES
