﻿/// <reference path="typings\jquery\jquery.d.ts" />
/// <reference path="typings\jqueryui\jqueryui.d.ts" />
var DragonDoor = (function () {
    function DragonDoor() {
    }
    DragonDoor.prototype.initialize = function () {
        $("body").append('<div id="leavingSiteDialogContainer"><div id="leavingSiteDialog" title="Leaving DragonDoor.com" style="display: none; width: 590px;"><p>You are leaving <b>DragonDoor.com</b> and going to <b>Dragon Door Direct</b>.</p> <p>Dragon Door Direct uses a separate shopping cart and unique usernames and passwords. Changes made on one site will not affect the other.</p></div></div>');

        $("a").filter(function () {
            return this.href.match(/^https?:\/\/direct\.dragondoor\.com/);
        }).click(function (e) {
            e.preventDefault();

            var screenWidth = Math.min($(window).width(), 590);
            var targetUrl = $(this).attr("href");
            $("#leavingSiteDialog").dialog({
                modal: true,
                autoOpen: false,
                width: screenWidth + "px",
                buttons: {
                    "Continue": function () {
                        var expiresDate = new Date();
                        expiresDate.setDate(expiresDate.getDate() + 1);
                        $.cookie("LeavingSiteWarning", "", { expires: expiresDate });

                        $(this).dialog("close");
                        window.location.href = targetUrl;
                    },
                    "Cancel": function () {
                        $(this).dialog("close");
                    }
                }
            });
            $("#leavingSiteDialog").parent().find("button").css("margin-right", "10px");

            if ($.cookie("LeavingSiteWarning") === undefined || $.cookie("LeavingSiteWarning") === null)
                $("#leavingSiteDialog").dialog("open");
            else
                window.location.href = targetUrl;
        });

        // make SPECIALS menu yellow
        $("#cssmenu").find("span:contains('SPECIALS')").css("color", "#ff9933");
    };
    return DragonDoor;
})();

$(function () {
    new DragonDoor().initialize();
});
