/*

*/

(function($){

	//Resize image on ready or resize
	$.fn.xresizer = function() {
		
		
		$(window).bind("load", function(){
			$('#xwrap').resizenow(); 
			});
				
		$(document).ready(function() {
		    $('#xwrap').resizenow(); 
			});

		$(window).bind("resize", function(){
		    $('#xwrap').resizenow();
			});
				
	};/*  End xresizer */
	
	//Dynamically resize the image relatively to the DIVs
	$.fn.resizenow = function() {

	  	return this.each(function() {
	  		
	  		var currentHeight = $('#xresizer').height();
	  		var parentHeight = $(window).height();
			
			$(this).css('height', (currentHeight) );
			$(this).parent().css('height', (parentHeight) );
	  		
			//Define image ratio
			/* Ratio = Height of Image / Width of Image */
			var ratio = 0.6665
			
			//Gather browser and current image size
			var imagewidth = $(this).width();
			var imageheight = $(this).height();
			var browserwidth = $(window).width();
			var browserheight = $(window).height();
			
			var wrapwidth = $('#xresizer').width();
			var wrapheight = $('#xresizer').height();
			/* var divheight = $('.xslideshow').height(); */
			
			var divheight = $('#xresizer').height();

			//Resize image to proper ratio
			
			if ((divheight/browserwidth) > ratio){
				    $(this).height(divheight);
				    $(this).width(divheight / ratio);
				    centerit = 0;
				    $(this).css('left', -(imagewidth-wrapwidth)/2 );
					$(this).css('top', 0 );
				} else {
				    $(this).width(browserwidth);
					$(this).height(browserwidth * ratio);
					var centerit = 1;
				}		
			if (centerit == 1){
				$(this).css('left', -( browserwidth - wrapwidth)/2);
				$(this).css('top', - ( $(this).height() - wrapheight)/2);
			}
			return false;
		});
	};/* End #resizenow */

})(jQuery);


