﻿// KW.SpecialFeatures.js

/// <reference path="jquery-1.2.6-vsdoc.js"/>
/// <reference path="KW.Core-vsdoc.js"/>
/// <reference path="SiteService-vsdoc.js"/>

(function() {

    KW.CreateNamespace('KW');

    var showOverlay = function(name) {
        if ($('div.Overlay').is(':visible')) {
            $('div.Overlay').fadeOut(function() {
                setTimeout(function() {
                    $('div.' + name + ':last').centerElement().fadeIn();
                }, 500);
            });
        }
        else {
            $('div.' + name + ':last').centerElement().fadeIn();
        }
    };

    var handleOverlay = function(name, context) {
        var html = $('div.' + name, context).html();
        $('div.' + name, context).remove();
        $('div:first').before(html);

        $('.Buttons a.' + name, context).click(function() {
            showOverlay(name);
        });
        $('div.' + name + ':last').click(function() {
            $(this).hide();
        });
        $('a.' + name + 'Opener').click(function() {
            showOverlay(name);
        });
    };

    var initSpecialFeatures = function(clientId) {
        var selector = '#' + clientId;
        //console.log(selector);
        var context = $(selector);

        handleOverlay('PCA', context);
        handleOverlay('JSM', context);
    };

    KW.InitSpecialFeatures = initSpecialFeatures;

    KW.ShowPCA = function() {
        showOverlay('PCA');
    };

    KW.ShowJSM = function() {
        showOverlay('JSM');
    };

} ());
