﻿// Borrowed from http://www.queness.com/post/77/simple-jquery-modal-window-tutorial
// Modified by dotAgency

var currentModalSelector;

$(window).bind("hashchange", function (event) {
    if (window.location.href.indexOf('#') < 0) {
        $('.modalCloseButton').click();
    }
});

$(window).trigger("hashchange");

function showModal(selector) {
    window.location.href += '#openDialog';

    currentModalSelector = selector;
    $(selector + "_mask").css({ "width": $(window).width(), "height": $(document).height(), "opacity": 0.5 }).fadeIn("fast");
    $(selector).css("position", "fixed").css("top", $(window).height() / 2 - $(selector).height() / 2).css("left", $(window).width() / 2 - $(selector).width() / 2).fadeIn("fast");
    $(selector + "_mask").unbind("click").click(function () {
        hideModal();
    });
    $(currentModalSelector + " img.modalCloseButton").unbind("click").click(function () {
        //location.reload(false);
        //window.location.href = window.location.href.replace('#openDialog', '');
        hideModal();
        return false;
    });
}

function hideModal() {
    $(currentModalSelector + "_mask").fadeOut("fast");
    $(currentModalSelector).fadeOut("fast");
    $(currentModalSelector + "_mask").unbind("click");
}
