
/**
 * Scalles an img to fill the page
 */

function scaleToFullScreen()
{
	var _stageWidth = window.innerWidth;
	var _stageHeight = window.innerHeight;
	var _imageRatio;
	var image = $$('#background_container').getElement('img');
	var _imageRatio = image.get('width') / image.get('height');
	var IMAGE_RATIO = Math.round(_imageRatio * 1000) / 1000;
	
	var _stageRatio = _stageWidth / _stageHeight; // Calc current Stage ratio and rount to 3 digits
	var STAGE_RATIO = Math.round(_stageRatio * 1000) / 1000;
	
	//trace('w:' + _stageWidth + '  h:' + _stageHeight);
	
	// Compare ratios and resize image
	
	// both ratios are equal
	if (IMAGE_RATIO == STAGE_RATIO) 
	{	
		image.set({'width' : _stageWidth });
		image.set({'height' : _stageHeight });
		return;
	}
	// Stage is wider than image
	if (IMAGE_RATIO < STAGE_RATIO)
	{
		image.set({'width' : _stageWidth });
		image.set({'height' : Math.round( image.getWidth() / IMAGE_RATIO ) });
		return;
	}
	// Stage is taller than image
	if (IMAGE_RATIO > STAGE_RATIO)
	{
		image.set({'height' : _stageHeight });
		image.set({'width' : image.getHeight() * IMAGE_RATIO });
		return;
	}
	//trace('scale to fullscreen');
}
	
window.addEvent('domready', function()
{
	
	scaleToFullScreen();
});

window.addEvent('resize' , function (event)
{
	scaleToFullScreen();
});


