﻿var armHtml = null;

$(document).ready(function() {
    getARMHtml();

    $('#arm-button a').click(showARMDialog);
});

function getARMHtml() {
    $.ajax({
        dataType: 'html',
        type: 'GET',
        url: '/arm.aspx',
        success: function(html) {
            armHtml = html;
        }
    });
}

function showARMDialog() {
    var bodyBlur = $('.body-blur');

    if (bodyBlur.length == 0) {
        var doc = $(document);
        var wind = $(window);
        var body = $('body');
        var link = $(this);

        body.append('<div class="body-blur"></div>');

        bodyBlur = $('.body-blur');

        bodyBlur.css('opacity', 0);
        bodyBlur.height(doc.height());

        bodyBlur.click(hideARMDialog);

        bodyBlur.fadeTo('fast', 0.2);

        if (!armHtml)
            getARMHtml();

        if (armHtml) {
            body.append(armHtml);

            var dialog = $('#arm-dialog');
            var left = (doc.width() - dialog.width()) / 2;
            var top = (wind.height() - dialog.height()) / 2;

            if (typeof document.body.style.maxHeight == 'undefined') { // if IE 6
                top += wind.scrollTop();

                $('html').css('overflow', 'hidden');
            }

            if (left < 0) left = 0;
            if (top < 0) top = 0;

            dialog.css('left', left + 'px');
            dialog.css('top', top + 'px');

            if (dialog.find('h1').length > 0) {
                dialog.find('h1').sifr({
                    font: '/flash/breeregular.swf',
                    version: 3,
                    fontSize: '21',
                    fontWeight: 'normal',
                    //width: '270px',
                    build: 436
                });

                // Jquery sIFR  - IE Fix
                $(window).unload(function() {
                    dialog.find('h1').remove();
                });
            }

            dialog.fadeIn('fast');

            dialog.find('a.close').click(hideARMDialog);
        }
    }
}

function hideARMDialog() {
    var bodyBlur = $('.body-blur');

    if (bodyBlur.length > 0) {
        var dialog = $('#arm-dialog');

        dialog.fadeOut('fast', function() {
            dialog.remove();
        });

        bodyBlur.fadeOut('fast', function() {
            bodyBlur.remove();
        });

        if (typeof document.body.style.maxHeight == 'undefined') { // if IE 6
            $('html').css('overflow', '');
        }
    }
}
