/*
 -------------------------------
 The Eat creative 
 JavaScript frontpage document
 2011
 -------------------------------
*/

/*
 -------------------------------
 When all set
 -------------------------------
*/
$(document).ready( function(){
	
	if($(window).width() > 500){
		var picNum = Math.floor(Math.random()*img_list.length);

		$('<img />')
    	.attr('src', img_list[picNum][0])
    	.load(function(){
    		
    		// --- Stick it on to your mom!
    		$(this).appendTo(
        		$('<div />', {'id':'bg_pic' }).css({'display':'none'}).appendTo($('#wrapper'))
        	);
        	
        	// --- Resize if window is to freakin big!
        	shouldIgrow();
        	
        	// --- Fade in ... Maybe
        	$('#bg_pic').fadeIn('slow');
        	
    	});
	}
	
	// Check window when resizing
	$(window).bind('resize scroll', function(){
		shouldIgrow();
	});
	
	function shouldIgrow(){
		if($(window).height() > 1024){
        	$('#bg_pic img').css({'height':$(document).height()});
        }else{
        	$('#bg_pic img').css({'height':'auto'});
        }
        
        if($(window).width() > 1395){
        	$('#bg_pic img').css({'width':$(document).width()});
        }else{
        	$('#bg_pic img').css({'width':'auto'});
        }

        //$('#bg_pic').css({'height':$('#wrapper').height()});
        
	}
	
});
