$(function() {	
	var numOfImages = $('#bgbody img').size();
	var strSelector = '#bgbody img[style="position: absolute; top: 0px; left: 0px; display: block; z-index: '+numOfImages+'; opacity: 1;"]';
	//alert(strSelector);
	var element = $(strSelector);
	var allElements = $('#bgbody img');
	//alert(element.size())
	/*element.each(function() {
		alert($(this).attr("style"));
	})*/
	//alert(element.text());
	
	var ratio = element.attr('width') / element.attr('height');	
	$(window).resize(function() {
		var w = $(window).width();
		var h = $(window).height();
		//alert(h);
		//$("#header").height(h/4);
		
		if (ratio < w / h) {
			//allElements.each(function() {
				
				$(this).height(w / ratio);
			//});
			allElements.each(function() {
				$(this).width(w);
			});
		}
		else {
			//allElements.each(function() {
				$(this).height(h);
			//});
			allElements.each(function() {
				$(this).width(h * ratio);
			});
		}
	});	
	$(window).resize();
	element.css('visibility','visible');
	
});
