(function($) {   
        
	$.fn.InfoBox = function(opts) {
	    
	    var defaults = {
            width: 480,
            position: ['center', 'top'],
            modal: true,
            autoOpen: false,
            id: 'info-box'  
	    },
	    
	    options = $.extend(true, {}, defaults, opts);
		
		return this.each(function() {    
            var $this = $(this),
                $dialog = null,               
                url = $this.attr('href'),        
                o = $.metadata ? $.extend({}, options, $this.metadata({type:'attr', name:'data'})) : options;
                
            if(!o.title) {
                o.title = $this.attr('title');
            }
            
            $dialog = $('<div></div>') 
                .attr({
                    'id': o.id,
                    'class': 'loading'
                })                                                               
	            .dialog(o);
  
        	$this.click(function(e) {
        	    var dh = $dialog.parent().height(),
        	        wh = $(window).height();             

                if(dh > wh) {
                    dh = parseInt(wh / 1.2);   
                } else {
                    dh = 'auto';    
                }

        		$dialog.dialog('option', 'height', dh)
        		       .dialog('open')
        		       .load(url, function(response, status, xhr) {
        		            if(status != 'error') {
        		                $(this).removeClass('loading');        
        		            } 
        		       });

        		return false;
        	});      		    	    
		});
    }    
})(jQuery);  

