function AjustaMedidas(img, width, height, option)
{
	var ratioWindow;
	var ratioImage;
	var resizeX;
	var resizeY;
	var left;
	var top;
	
	if (option == 1)
	{
		ratioImage = width/height;
		ratioWindow = pageWidth()/pageHeight();
		
		if(ratioImage > ratioWindow)
		{
			if(width < pageWidth())
			{
				resizeX = width;
				resizeY = height;
				left = pageWidth() - width;
				left = left/2;
				top = pageHeight() - height;
				top = top/2;
				
				$('#'+img).css('position','fixed');
				$('#'+img).css('z-index','-1');
				$('#'+img).css('left',left);
				$('#'+img).css('top',top);
			}
			else
			{
				resizeX = pageWidth();
				resizeY = (width/pageWidth());
				resizeY = height/resizeY;
			}
		
		}
		else
		{
			if(height < pageHeight())
			{
				resizeX = width;
				resizeY = height;
				left = pageWidth() - width;
				left = left/2;
				top = pageHeight() - height;
				top = top/2;
				
				$('#'+img).css('position','fixed');
				$('#'+img).css('z-index','-1');
				$('#'+img).css('left',left);
				$('#'+img).css('top',top);
			}
			else
			{
				resizeY = pageHeight();
				resizeX = (height/pageHeight());
				resizeX = width/resizeX;
			}
		}
		
		$('#'+img).css('width',resizeX);
		$('#'+img).css('height',resizeY);
	}
	else if (option == 2)
	{
		ratioImage = width/height;
		ratioWindow = pageWidth()/pageHeight();
		
		if(ratioImage < ratioWindow)
		{
			if(width < pageWidth())
			{
				resizeX = width;
				resizeY = height;
				left = pageWidth() - width;
				left = left/2;
				top = pageHeight() - height;
				top = top/2;
			}
			else
			{
				resizeX = pageWidth();
				resizeY = (width/pageWidth());
				resizeY = height/resizeY;
				left = 0;
				top = resizeY - pageHeight();
				top = -top/2;
			}
		
		}
		else
		{
			if(height < pageHeight())
			{
				resizeX = width;
				resizeY = height;
				left = pageWidth() - width;
				left = left/2;
				top = pageHeight() - height;
				top = top/2;
			}
			else
			{
				resizeY = pageHeight();
				resizeX = (height/pageHeight());
				resizeX = width/resizeX;
				top = 0;
				left = resizeX - pageWidth();
				left = -left/2;

			}
		}
		
		$('#'+img).css('position','fixed');
		$('#'+img).css('z-index','-1');
		$('#'+img).css('left',left);
		$('#'+img).css('top',top);
		$('#'+img).css('width',resizeX);
		$('#'+img).css('height',resizeY);
	}
	
	$('#'+img).css('visibility','visible');
}

///define pagewidth & height for determining size backgroundimage
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}