// resize.js
// Resizes an image to fill the browser window proportionately.

	// Original image size
	var image_width = 400;
	var image_height = 400;

function resizeimage() {
	var window_width = jQuery(window).width();
	var window_height = jQuery(window).height();
	var window_ratio = window_width / window_height;

	current_width = jQuery('#background img').width();
	if (current_width > 1) {
		image_width = current_width;
	}	

	current_height = jQuery('#background img').height();
	if (current_height > 1) {
		image_height = current_height;
	}
	
	image_ratio = image_width / image_height;
	
	
	// Scale image
	if (window_ratio > image_ratio) {
		// Scale image to fit window width
		var scaled_height = (window_width / image_width) * image_height;
		var scaled_width = window_width;
	} else {
		// Scale image to fit window height		
		var scaled_height = window_height;
		var scaled_width = (window_height / image_height) * image_width;
	}
	
	jQuery('#background img').css({height: scaled_height, width: scaled_width});
	jQuery('#background').css({height: window_height, width: window_width});
	
	
	// Position image
	new_top = 0 - ((scaled_height - window_height) / 2);
	new_left =  0 - ((scaled_width - window_width) / 2);
	
	jQuery('#background img').css({top: new_top, left: new_left});
	
	
	// Image visibility
	jQuery('#background').css({visibility:"visible", display:"inline"});
	
	
}