jQuery(window).load(function(){ 
		$('div#bg img:first').show();

		$('div#bg .images').cycle({
  		fx: 'fade',
  		speed:  1000,
  		timeout: 8000,
			fit: 0,
			slideExpr: 'img'
  	});
});

$(document).ready(function() {    

if ($.browser.msie) {
		$("div#bg img:first").ready(function() {
	    resizeBg();
		});

} else {
		$("div#bg img:first").load(function() {
	    resizeBg();
		});
}

		
});


function resizeBg() {
    var theWindow  = $(window);
	
		$("div#bg img").css('left', 0);
		$("div#bg img").css('top', 0);
    
		if ( (theWindow.width() / theWindow.height()) > 1 ) {
			
			$("div#bg img").each(function(index) {
			    
						
				$(this).removeAttr('width');
				$(this).attr('height','100%');
	
				if (theWindow.width()<$(this).width()) {
					
					var leftPosition = 0 - (Math.abs(($(this).width() - theWindow.width())) / 2);
					$(this).css('left', leftPosition);
					$(this).attr('width',$(this).width());
				} else {
					$(this).removeAttr('height'); 
					$(this).attr('width','100%'); 
					var topPosition = 0 - (($(this).height() - theWindow.height()) / 2);
					$(this).css('top', 0);
					$(this).attr('height',$(this).height());
				}

			});

		
		} else if ( (theWindow.width() / theWindow.height()) < 1 ) {

			$("div#bg img").each(function(index) {
			    
				$(this).removeAttr('height').attr('width','100%');               
				if (theWindow.height()<$(this).height()) {
					var topPosition = 0 - (Math.abs(($(this).height() - theWindow.height())) / 2);
					$(this).css('top', topPosition);
				} else {
					$(this).removeAttr('width').attr('height','100%'); 
					var leftPosition = 0 - (Math.abs(($(this).width() - theWindow.width())) / 2);
					$(this).css('left', leftPosition);
				}


			});

   	}
           
}
