﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />

jQuery.fn.initModal = function(options) {
    var settings = {
        openClass: "",
        closeClass: "",
        fadeSpeed: "normal"
    };

    jQuery.extend(settings, options);

    var inprogress = false;

    //$box is the actual modal div
    var $box = this;

    //assign click to open behaviour to all elements with the correct css class
    $("." + settings.openClass).click(function() {
        if (!inprogress) {
            inprogress = true;
            var left = $box.css("left");
            if (left != "160px") {
                $('html, body').animate({ scrollTop: 0 }, settings.fadeSpeed);
                $box
                    .hide()
                    .css("left", "160px")
                    .fadeIn(settings.fadeSpeed,
                    function() {
                        inprogress = false;
                    });
            }
            else {
                $('html, body').animate({ scrollTop: 0 }, settings.fadeSpeed);
                $box.fadeIn(settings.fadeSpeed, function() {
                    inprogress = false;
                });
            }
        }
        return false;
    });

    //assign click to close behaviour to all elements with the correct css class
    $("." + settings.closeClass).click(function() {
        if (!inprogress) {
            inprogress = true;
            $box.fadeOut(settings.fadeSpeed, function() {
                inprogress = false;
            });
        }
        return false;
    });
}