var fsImage,origWidth;
var fsInit = false;

function fullscreen()
{
	origWidth = fsImage.width();
	origHeight = fsImage.height();
	
	$('#images img').css('position','fixed');
	
	var setDims = function()
	{
		var w = $(window).width();
		var h = $(window).height();
		var widthRatio = (origHeight/origWidth) * 100;
		var heightRatio = (origWidth/origHeight) * 100;
		var followWidth = new Array();
		var followHeight = new Array();
		
		// Calculate dimensions based on width
		
		followWidth.push(w); // width
		followWidth.push(Math.ceil((w / 100) * widthRatio)); // height
		followHeight.push(Math.ceil((h / 100) * heightRatio)); // width
		followHeight.push(h); // height
		
		if(followWidth[1] > h)
		{
			fsImage.css('width',followWidth[0]+'px');
			fsImage.css('height',followWidth[1]+'px');
			var offsetTop = Math.round((followWidth[1] - h) / 2);
			fsImage.css('top','-'+offsetTop+'px');
			fsImage.css('left','0px');
		}
		else if(followHeight[0] > w)
		{
			fsImage.css('width',followHeight[0]+'px');
			fsImage.css('height',followHeight[1]+'px');
			var offsetLeft = Math.round((followHeight[0] - w) / 2);
			fsImage.css('left','-'+offsetLeft+'px');
			fsImage.css('top','0px');
		}
	}
	
	setDims();
	$('window').unbind('resize');
	$(window).resize(function()
	{
		setDims();
	});
	
	fsInit = true;
}
