(function($) {
	setScreenshotImage = function(className) {
		$('#screenshot').attr('style', '');
		$('#screenshot').attr('class', className);
	};
})(jQuery);

(function($) {
	toggleScreenshotInfo = function(className) {
		var state = $('#' + className + '-info').css('display');
		
		if (state == 'block') {
			$('#' + className + '-info').css('display', 'none');
		} else {
			$('#' + className + '-info').css('display', 'block');
		}
		
	};
})(jQuery);

jQuery(document).ready(function($) {
	
	/* Preload images from CSS */
	$.preloadCssImages();
	
	/* Outbound links */
	$("#page a[href^=http], #detailinfo a[href^=http]").each(
	    function(){
			if(this.href.indexOf(location.hostname) == -1) {
				$(this).attr({
					target: "_blank"
				});
			}
		}
	);
	
	$('body.home #maincontent h2, body.home #headerimg h1 a').click(function() {
		$('#detailinfo').fadeIn('slow');
		
		return false;
	});
	
	$('#detailinfo').click(function() {
		$(this).fadeOut('slow');
	});
	
	$('#simulator-items li a').each(function() {
		$(this).hover(
			function() {
				setScreenshotImage($(this).attr('rel'));
				
				toggleScreenshotInfo($(this).attr('rel'));
			},
			function() {
				toggleScreenshotInfo($(this).attr('rel'));
			}
		)
		
		$(this).click(
			function() {
				setScreenshotImage($(this).attr('rel'));
				
				return false;
			}
		)
	});
	
	
	$('#infobox p a[rel=screenshot]').each(function() {
		$(this).click(function() {
			
			var bgurl = $(this).attr('href');
			
			$('#screenshot').css('background', 'url(' + bgurl + ')');
			
			return false;
		});
	});
	
	$('#simulator-items li:first-child a').click();
	
	$('#query-close').click(function() {
		$('#search-query').fadeOut();
	});
	
});