jQuery.fn.YDialog = function(qOptions){
	var options={
        container       :   'dialog',
        dataSource      :   false,
        dataParams      :   {},
        title           :   '',
        icon            :   '',
        height          :   300,
        width           :   500,
        minHeight       :   150,
        resize          :   undefined,
        minWidth        :   300,
        fullscreen      :   false,
        unfullscreen    :   true,
        onclose         :   false,
        resizable       :   true
        ,buttons      :   {
			'Cancel': function(event) {
				$(this).dialog('destroy');
			}

		}	
    };
    $.extend(options,qOptions);
    if( typeof($('#'+options.container).get(0))!='undefined'){
        $('#'+options.container).unbind();
        $('#'+options.container).empty().remove();
        if(document.getElementById(options.container))
            document.getElementById(options.container).innerHTML='';
    //return;
    }
    if( typeof($('#'+options.container).get(0))=='undefined'){
        
        $('body').append('<div id="'+options.container+'"></div>');
    }
    
    if(options.dataSource!=false){
        setTimeout(function(){
            $('#'+options.container).html('<div class="shadow_right"><div class="backg_white" id="content"><img src="/themes/1/i/loadinfo.gif"  align="center"></div></div>');
        },10);
        $.post(options.dataSource, options.dataParams, function(data){
            $("#"+options.container).html('<div class="shadow_right"><div class="backg_white" id="content">'+data+'</div></div>');
        });
    }
    if(options.icon!=''){
    //   options.title = '<div style="float:left"><img src="' + QCode.SKIN_URL + 'icons/' + options.icon + '" width="16" height="16" alt=""/>&nbsp;</div><div style="float:left">' + options.title + '</div>';
    }
    $('body').css('overflow','hidden');
    if(options.fullscreen){
        options.height=$(window).height()-20;
        options.width=$(window).width()-5;
    }
    var _dialog=$('#'+options.container);
    _dialog.dialog({
        bgiframe    :   true,
        autoOpen    :   true,
        height      :   options.height,
        width       :   options.width,
        modal       :   true,
        //show      :   'drop',
        //hide      :   'drop',
        title       :   options.title,
        stack       :   true,
        buttons     :   options.buttons,
        minHeight   :   options.minHeight,
        minWidth    :   options.minWidth,
        resizable   :   options.resizable,
        resize      :   options.resize,
        overlay: {
            backgroundColor: '#000',
            opacity: 0.5
        },
        open: function(){
          $('button',$(this).parent()).each(function(i){
					$(this).attr({'class':'btn_'+$(this).html()});
				});
        },
        close       :   function() {
            _dialog.dialog('destroy');
            setTimeout(function(){
                $('#'+options.container).remove();
            },100);
            if(typeof(options.onclose)=='function'){
                options.onclose(options.dataParams);
            }
            //alert(options.onclose);
            //if(options.unfullscreen){
            $('body').css('overflow','visible');
            // }
            document.getElementById(options.container).innerHTML='';
        }
    });
};
