function isIE(){
	return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

function resizeBackground(){
	
	// Get the Container and Image
   var container = $(document.body).getElement('div.img-container');
   var test = container.getElement('img');
   var imgs = container.getElementsByTagName('img');

   for(var i = 0 ; i < imgs.length ; i++){
       image = imgs[i];
       shadow = container.getElement('div');
       // Get aspect ratio
	   if(isIE()){
	   		var x = image.clientWidth;
	   		var y = image.clientHeight;
	   }else{
	   		var x = image.getSize().x;
	   		var y = image.getSize().y;
	   }
       var ratio = x / y;
       //var ratioShadow = shadow.getSize().x/shadow.getSize().y;
       // Get page content size
       var min = contentheight = 0;
       $each($(document.body).getChildren().erase(container), function(item) {
           min = item.getSize().x>min ? item.getSize().x : min;
           contentheight = contentheight + item.getSize().y;
       });
       // Calculate image size
       var width = container.getSize().x.limit(min, min+container.getSize().x), height = Math.floor(width/ratio);
       // Apply sizes to container and image
       container.setStyle('min-width', min);
	   //container.setStyles({'min-width': min, 'height': height.limit(0, (window.getSize().y>contentheight ? window.getSize().y : contentheight))});
       
	   //imgs[i].set({'width': width, 'height': height});
	   imgs[i].style.width = width + 'px';
	   //imgs[i].style.height = height + 'px';
	   $$('.img-container').setStyle('display','block');
	   
	   
	   
	   //imgs[i].fade(1);
   }

}

var background = function() {
	
	resizeBackground();
	// Create a div over the image
	//if ($chk(container.getElement('div'))) container.getElement('div').setStyles({'width': width, 'height': height})
	//else new Element('div', {'styles': {'position': 'absolute', 'z-index': '10', 'width': width, 'height': height}}).inject(container);
	// Footer
	//var footer = $(document.body).getElement('div.footer');
	//var footersize = (container.getStyle('height').toInt() - (contentheight - footer.getSize().y)).limit(5, 10000);
	//footer.setStyle('min-height', footersize);
};

window.addEvent('load', function() {	
	background.run();
	window.addEvent('resize', function() { background.run(); });
});
