
	
	 jQuery(function($){
			
		$(".container").hide();

		var numRand = Math.floor(Math.random()*37)
		
		$('<img src="/img/bg/UK/bg_'+numRand+'.jpg" id="bg-image"/>')
					.css("position","static")
					.css("width","100%")
					.css("display","none")
					.appendTo('body')
					.wrap("<div class='img-container'/>")
		$(".img-container")
					.css('top', '0')
					.css('left', '0')
					.css("width","100%")
					.css("height","100%")
					.css("position","fixed")
					.css("z-index","-20")
					.css("overflow","hidden");
					
		
		$('<div id="overlay"></div>')
					.css('top', '0')
					.css('opacity', '0')
					.css("width", "100%")
					.css("height","100%")
					.css("position","fixed")
					.appendTo('body');
					
		
		$('#overlay').delay(1000).fadeTo('slow', 0.8);
		
		$('.container').delay(2000).fadeIn('400');
		
		$(document).ready(function() {

 var bgImage = $('#bg-image');		

    function resizeImg() {
      var imgwidth = bgImage.width(),
		   imgheight = bgImage.height(),
		   winwidth = $(window).width(),
		   winheight = $(window).height(),
		   widthratio = winwidth / imgwidth,
		   heightratio = winheight / imgheight,
		   widthdiff = heightratio * imgwidth,
		   heightdiff = widthratio * imgheight;

      if(heightdiff>winheight) {
        bgImage.css({
          width: winwidth+'px'//,
          //height: heightdiff+'px'
        });
      } else {
        bgImage.css({
          width: widthdiff+'px'//,
          //height: winheight+'px'
        });
      }

	 $("#bg-image").show();

    }
   $(window).load(function(){
    	resizeImg();
	});
    $(window).resize(function() {
      resizeImg();
    }); 

});
		
   // function resizeImg() {
//		var imgwidth = $("#bg-image").width();//eg 1024
//      	var imgheight = $("#bg-image").height();//eg 1024
//		
//		var winwidth = $(window).width(); //eg 1280
//     	 var winheight = $(window).height();// 1024
// 
//      	var widthratio = winwidth / imgwidth; 
//		//1280/1024 = 1.25
//      	var heightratio = winheight / imgheight;
//		//1024/1025 =1
// 
//      	var widthdiff = heightratio * imgwidth;
//		//1*1280 = 1280
//      	var heightdiff = widthratio * imgheight;
//		//1.25*1024 = 1280
//		
//		if(heightdiff>winheight) {
//			$("#bg-image").css({
//				  width: winwidth+'px',
//				  height: heightdiff+'px'
//				});
//				if($(document).height() <= 800){
//					$("body").css({"overflow-x":"hidden"});
//					$("body").css({"overflow-y":"visible"});
//				}else{
//					$("body").css({"overflow":"hidden"});
//				}
//			  } else {
//			$("#bg-image").css({
//				  width: widthdiff+'px',
//				  height: winheight+'px'
//				});	
//				if($(document).height() <= 800){
//					$("body").css({"overflow-x":"hidden"});
//					$("body").css({"overflow-y":"visible"});
//				}else{
//					$("body").css({"overflow":"hidden"});
//				}	
//			  }
//	}
	//resizeImg();
//	
//    $(window).resize(function() {
//    	resizeImg();
//    }); 
			
			/*$('body').css("height",ch);*/

			/*if(ch > wh){
				$("#overlay").css("height", bgh)

				$('body').css("height",ch);
				$('body').css("overflow-x","hidden")

			}else{
				$('body').css("overflow","hidden")
				$('body').css("height","100%");	
				$("#overlay").css("height", "100%")
	
			}*/
	  
	});
