$(document).ready(function(){
	setInterval("preLoad()",300);
});

$(window).bind('resize',function(){
	adaptImg(".backgroundImg")
});


function preLoad(){
	adaptImg(".backgroundImg");
	$(".backgroundImg").fadeTo(4000,1,function(){
		adaptImg(this);
	});
}

function adaptImg(imgBg){
	if($(window).width() > $(imgBg).width()){
		$(imgBg).css({
			"width":"100%",
			"height":"auto"
		});
	}
	else if($(window).height() > $(imgBg).height()){
		$(imgBg).css({
			"height":"100%",
			"width":"auto"
		});
	}
	
	var browserName=navigator.appName;
	
	if(browserName!="Microsoft Internet Explorer"){
		$(imgBg).css(
			"top",Math.round(-(($(imgBg).height()-$(window).height())/2))
		);
	}
	else {
		$(imgBg).css(
			"top",Math.round(($(imgBg).height()-$(window).height())/2)*(-1)
		);
	}
}
