//Initialize JS actions
$(document).ready(function(){
						   
	//Setup In-Field Labels for forms
	$("#searchform label").inFieldLabels({
		fadeOpacity: "0.1",
		fadeDuration: 150
	});
	$("#newsletter label").inFieldLabels({
		fadeOpacity: "0.1",
		fadeDuration: 150
	});
	
});


//Function for loading Games List via AJAX
(function($){
	$.fn.gamesLoad = function(){
		$(this).live('click', function(event){
			//... stop the link from doing it's default thing...
			event.preventDefault();
			//... make sure to remove any loader that was out there...
			$('.loader').remove();
			//Set variables for use
			var currentHeight = $('#games_list').height();
			var currentWidth = $('#games_list').width();
			var loadLink = $(this).attr('href');
			var loader = '<div class="loader">Loading...</div>';
			//Show the loader and then hide it; also place an overflow holder on container
			$(this).parent().append(loader);
			$('.game_wrapper').css({'overflow':'hidden', 'width':currentWidth, 'height':currentHeight});
			//Some clerical styling stuff
			if($(this).parent().hasClass('right')){
				$('.navigation .loader').addClass('right');
			} else {
				$('.navigation .loader').addClass('left');
			}
			$('.loader').hide().fadeIn();
			//Fade out the content while loading and make sure the new content doesn't extend the container... yet
			$('#games_list').fadeOut();
			//Using the link var from above, load info from the associated URL (paginated, in this case)
			$('#content .game_wrapper').load(loadLink+' #games_list', function(){
				$('#games_list').hide();
				$('.navigation').fadeOut();
				$('#content .nav_wrapper').load(loadLink+' .navigation', function(){
					$('.navigation').fadeIn();
					var newHeight = $('#games_list').height();
					$('.game_wrapper').animate({height : newHeight}, 1000, 'swing', function(){
						$('#games_list').fadeIn();
						$('html, body').animate({scrollTop: $("#content").offset().top}, 500, 'swing');
					});
					//Tell Cufon to get it's lazy butt off the bench again
					Cufon.refresh();
					//... and get rid of that loader!
					$('.loader').fadeOut();
				});
			});
		});
		return this;
	};
})
(jQuery);


(function($){
	$.fn.gamesFilter = function(loadLink,loaderLoc){
		$(this).change(function(event){
			var countOpt = $('#games_count option:selected').val();
			var platformOpt = $('#games_platform option:selected').val();
			var genreOpt = $('#games_genre option:selected').val();
			$.get(loadLink, { count: countOpt, platform: platformOpt, genre: genreOpt }, function(html){
				var content = $('#games_list > *', html);
			});
			/*
			alert(countOpt + " " + platformOpt + " " + genreOpt);
			//... stop the link from doing it's default thing...
			event.preventDefault();
			//... make sure to remove any loader that was out there...
			$('.loader').remove();
			//Set variables for use
			var currentHeight = $('#games_list').height();
			var currentWidth = $('#games_list').width();
			var loader = '<div class="loader">Loading...</div>';
			//Show the loader and then hide it; also place an overflow holder on container
			$(loaderLoc).append(loader);
			$('.loader').hide().fadeIn();
			$('.game_wrapper').css({'overflow':'hidden', 'width':currentWidth, 'height':currentHeight});
			//Using the link var from above, load info from the associated URL (paginated, in this case)
			$.get(loadLink, { name: "John", time: "2pm" }, function(html){
				var content = $('#games_list > *', html);
			});
			*/
		});
		return this;
	};
})
(jQuery);


//Cufon replacement declarations
Cufon.replace('.cufon-visitor', { hover: true, fontFamily: 'Visitor' });
Cufon.replace('.cufon-silkscreen', { hover: true, fontFamily: 'Silkscreen' });

