/*
DES-Resize
By Kanate U.
DigitalEYE Media
www.digitaleyemedia.com
*/
(function($){

	//Resize image on ready or resize
	$.fn.desresize = function() {
	
		var options = $.extend($.fn.desresize.defaults, $.fn.desresize.options);
		
		$().ready(function() {
			$('#des-resize').resizenow(); 
		});
		$(window).bind("resize", function(){
    		$('#des-resize').resizenow(); 
		});
	};
	
	//Adjust image size
	$.fn.resizenow = function() {
		
		var options = $.extend($.fn.desresize.defaults, $.fn.desresize.options);
		
	  	return this.each(function() {
	  		
			//Define image ratio & minimum dimensions
			var minwidth = options.startwidth;
			var maxwidth = options.maximumwidth;
			var leftrightmargin = options.percent;
			
			//Gather browser and current div size
			var divwidth = $(this).width();
			var browserwidth = $(window).width();
			
			//Check for minimum dimensions
			if (browserwidth < minwidth){
				$(this).width(minwidth);
			}
			else{	
				divwidth = Math.round(browserwidth * leftrightmargin);
				if (divwidth < maxwidth) {
					if (divwidth < minwidth) {
						$(this).width(minwidth);	
					}
					else {
						$(this).width(divwidth);
					}
				}
				else {
					$(this).width(maxwidth);
				}
			}
			return false;
		});
	};
	
	$.fn.desresize.defaults = { 
			startwidth: 1000, 
			maximumwidth: 1400,
			percent: .8
	};
	
})(jQuery);
