/*!
 * FlashFit
 * 
 * Copyright 2011, Jakub Przyborowski
 * http://www.przyborowski.info/
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 */
(function( $ ){
	var methods = {
		init : function(options) {
			var overall = $('<div></div>');
			$(overall).appendTo($(this).parent());
			$(overall).append(this);
			
			methods._fit(overall, options);
			$(window).bind('resize', { target: overall, options: options } , function(e){
				methods._fit(e.data.target, e.data.options);
			});
		},
		
		_fit : function(target, options) {
			var liquid = true;
			if ($(window).width()<=options.minWidth)
			{
				liquid = false;
				$(target).css('width', options.minWidth+'px');
			}
			else
			{
				$(target).css('width', '100%');
			}
			
			if ($(window).height()<=options.minHeight)
			{
				liquid = false;
				$(target).css('height', options.minHeight+'px');
			}
			else
			{
				$(target).css('height', '100%');
			}
			
			$('html').css('overflow', liquid ? 'hidden' : 'auto');
			$('html').css('width', liquid ? '100%' : 'auto');
			$('html').css('height', liquid ? '100%' : 'auto');
			$('body').css('width', liquid ? '100%' : 'auto');
			$('body').css('height', liquid ? '100%' : 'auto');
		}
 	};

  $.fn.flashfit = function( method ) {

    // Method calling logic
    if ( methods[method] ) {
      return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
    } else if ( typeof method === 'object' || ! method ) {
      return methods.init.apply( this, arguments );
    } else {
      $.error( 'Method ' +  method + ' does not exist on jQuery.modal' );
    }    

  };

})( jQuery );
