﻿$(document).ready(function () {
    $('a[name=modal]').click(function () {
        return showModal($(this).attr('href'));
    });
    $('.window .close').click(function (e) {
        e.preventDefault();
        $('#mask, .window').hide();
        return false;
    });
    $('#mask').click(function () {
        $(this).hide();
        $('.window').hide();
        return false;
    });

    if (window.location.hash) {
        $(window.location.hash.replace("-tab", "")).show();
        $('a[href=' + window.location.hash.replace("-tab", "") + ']').addClass('current'); 
    }
    else { $('.tab').first().show(); $('.tab_nav li a').first().addClass('current'); }
    $('.tab h3').add('.plan_page h3').each(function () {
        if ($(this).next('div.tab_collapse').length > 0)
            $(this).css({ 'cursor': 'pointer' });
    }).click(function () {
        $('div.tab_collapse').not($(this).parent()).not($(this).next('div.tab_collapse')).slideUp();
        var activePanel = $(this).next('div.tab_collapse').slideToggle().focus();
        return false;
    });
    $('ul.tab_nav a').click(function (e) {
        $('.tab').hide();
        $($(this).attr('href')).show();
        $('ul.tab_nav a.current').removeClass('current');
        $(this).addClass('current');
        window.location.hash = $(this).attr('href') + "-tab";
        return false;
    });

});

function showModal(id) {
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();
    $('#mask').css({ 'width': maskWidth, 'height': maskHeight });
    $('#mask').fadeTo("slow", 0.5);
    var winH = $(window).height();
    var winW = $(window).width();
    //$(id).css({ 'width': $(id).outerWidth(), 'height': $(id).outerHeight() });
    $(id).css('top', winH / 2 - $(id).height() / 2);
    $(id).css('left', winW / 2 - $(id).width() / 2);
    $(id).fadeIn(500);
    return false;

}
