$(function(){

	// Background array
	var bgs = ['css/images/body-bg.jpg', 'css/images/body-bg2.jpg', 'css/images/body-bg3.jpg','css/images/body-bg4.jpg'];
	
	// Set random background image
	var rand_index = rand(0, bgs.length-1);
	var rand_bg_image = bgs[ rand_index ];
	$('#bg').attr('src', rand_bg_image);
			    			    		
	           			
	$(window).resize(function() { 
		if ( ($(window).width() / $(window).height()) < $('#bg').width() / $('#bg').height() ) {
		    $("#bg").removeClass().addClass('bgheight');
		} else {
		    $("#bg").removeClass().addClass('bgwidth');
		}
		
		$('#content').css('height', parseInt($('.shell').height() - 161));
	}).trigger("resize");
	
	// Fix navigation hover
	$(document).click(function() {
		$("#navigation li").removeClass('hover');
		$("#navigation li .dd").hide();
	});
		
	// navigation hover
	$("#navigation li").hover(
		function(){
			$(this).addClass('hover');	
			$(this).find('.dd').show();
		}, function(){
			$(this).removeClass('hover');	
			$(this).find('.dd').hide();
    	});
    	
    // fancy box
	$(".images a").fancybox();
  	
});

function rand(from, to){
	return Math.floor(Math.random() * (to - from + 1) + from);
}

