$(window).load(function() {

	//DYNAMIC BACKGROUND
	//resizeBackground();
	//$(window).resize(resizeBackground);
	
    function resizeBackground() {
    	//set image variables
		imagewidth = $("img#background").width();
		imageheight = $("img#background").height();
   
		//set browser variables
		browserwidth = $(window).width();
		browserheight = $(window).height();
   		
   		//set background box to browser varaibles
		$("div#background-container").css({ width: browserwidth, height: browserheight});
   		
 		//Resize window
 		//Image height adopts browser width and muliply difference to height
		var new_imagewidth = browserwidth;
		var new_imageheight = browserheight;
		
		//for some reason it doesn't take variables at the moment
		var new_imageheight = (($(window).width()/ $("img#background").width()) * $("img#background").height());
   		$("img#background").css({ width: new_imagewidth, height: new_imageheight });
   		
   		//Resize image if image width is less than image height (height is taller)
  		
		if (new_imageheight < browserheight) {
			var new_imageheight = browserheight;
			var new_imagewidth = ((new_imageheight / imageheight) * imagewidth);

			$("img#background").css({ width: new_imagewidth, height: new_imageheight });
		}
		
		//BROWSER TEST
		var browserName = $.browser.name;
	
		if (browserName == "msie") {
			if(parseInt(jQuery.browser.version) == 6) {
				$(window).scroll(function() {
					var distance = $(document).scrollTop();
					$("div#background-container").css({ top: distance});
				});
			}
		}	
    }										

	//DYNAMIC BACKGROUND
	setTimeout(function() {									
		//$('#background').fadeIn(500);							
	}, 500);
	
	
	// ADJUST #ENTRY HEIGHT TO MATCH SIDEBARS!
	// WHICH IS TALLER? 1 or 2?
	var sidebar1height = $("#sidebar_1").height();
	var sidebar2height = $("#sidebar_2").height();
	
	
	if(!sidebar2height) {
	var entryheight = sidebar1height;
	}
	else if(sidebar1height>sidebar2height || sidebar1height==sidebar2height) {
	var entryheight = sidebar1height;
	$("#sidebar_2").css({ height: entryheight+'px' });
	}
	else {
	var entryheight = sidebar2height;
	}
	
	entryheight = entryheight-20;
	
	
	// MAKE SURE THAT, IF THE CONTENT IS LONGER THAN THE SIDEBAR, MOST OF THIS IS SKIPPED.
	
	var currententryheight = $("#entry").height();
	
	if(currententryheight<entryheight) {	
	$("#entry").css({ height: entryheight+'px' });
	}
});
