﻿function ajaxGet(link, callback, data) {
    var url = link.href;
    $.ajax({
        type: "GET",
        url: url.replace(/#\w+$/, ''),
        data: $.extend({ r: Math.random() }, data || {}),
        dataType: "json",
        complete: function(xhr, textStatus) {
            //$("#loading").hide();
        },
        success: function(data) {
            return callback(data);
        },
        error: function(xhr, textStatus, errorThrown) {
            //$("#message").html("请求失败，请联系管理员或者稍候再试！status:" + textStatus).show();
        }
    });

    return false;
}

function adapt(img, maxWidth, maxHeight) {
    var $image = $(img);
    
    var imageWidth = $image.width();
    var imageHeight = $image.height();

    if (imageHeight > maxHeight) {
        $image.height(maxHeight);
        $image.width(imageWidth * (maxHeight / imageHeight));
        imageHeight = maxHeight;
        imageWidth = $image.width();
    }

    if (imageWidth > maxWidth) {
        $image.width(maxWidth);
        $image.height((maxWidth / imageWidth) * imageHeight);
    }
}

;(function($) {
    $.messageUI = function(title, message, css) {
        var $m = $('<div class="growlUI"></div>');
        if (title)
            $m.append('<h1>' + title + '</h1>');
        if (message)
            $m.append('<h2>' + message + '</h2>');

        var defaultCss = {
            width: '250px',
            top: '10px',
            left: '',
            right: '10px',
            border: 'none',
            padding: '5px',
            opacity: 0.8,
            cursor: null,
            color: '#fff',
            backgroundColor: '#000',
            '-webkit-border-radius': '10px',
            '-moz-border-radius': '10px'
        };

        $.blockUI({
            message: $m,
            fadeIn: 700,
            fadeOut: 1000,
            centerY: false,
            timeout: 3000,
            showOverlay: false,
            css: $.extend(defaultCss,css||{})
        });
    };
})(jQuery);