﻿var dialogFirst = true;
function dialog(title, content, width, height) {

    if (dialogFirst == true) {
        var temp_float = new String;
        temp_float = "<div id=\"floatBoxBg\" class=\"floatBoxBg\" style=\"height:" + $(document).height() + "px;filter:alpha(opacity=0);opacity:0;position:absolute;\">&nbsp;</div>";
        temp_float += "<div id=\"floatBox\" class=\"floatBox\">";
        temp_float += "<div class=\"floatBoxtitle\"><h4></h4><span>关闭</span></div>";
        temp_float += "<div class=\"floatBoxcontent\"></div>";
        temp_float += "</div>";
        $("body").append(temp_float);
        dialogFirst = false;
    }

    $("#floatBox .floatBoxtitle h4").html(title);

    contentType = content.substring(0, content.indexOf(":"));
    content = content.substring(content.indexOf(":") + 1, content.length);
    switch (contentType) {
        case "id":
            $("#floatBox .floatBoxcontent").html($("#" + content + "").html());
            break;
        case "url":
            location.href = "#";
            $("#floatBox .floatBoxcontent").load(content, function () { $.getScript("/Script/jquery.galleria.pop.js", function () { }); });
            break;
        default:
            break;
    }

    $("#floatBox .floatBoxtitle span").click(function () {
        $("#floatBoxBg").animate({ opacity: "0" }, "normal", function () { $(this).hide(); });
        $("#floatBox").animate({ top: ($(document).scrollTop() - (height == "auto" ? 300 : parseInt(height))) + "px" }, "normal", function () { $(this).hide(); });

    });

    $("#floatBoxBg").show();
    $("#floatBoxBg").animate({ opacity: "0.5" }, "normal");
    $("#floatBox").css({ display: "block", left: (($(document).width()) / 2 - (parseInt(width) / 2)) + "px", top: ($(document).scrollTop() - (height == "auto" ? 300 : parseInt(height))) + "px", width: width, height: height });
    $("#floatBox").animate({ top: ($(document).scrollTop() + 50) + "px" }, "normal");
}



jQuery.fn.extend({
    pressEnter: function (fun) {
        this.keypress(function (e) {
            if (e.which == "13") {
                fun();
            }
        });
    }
});

