﻿/* HelpPopup */
$(document).ready(function () {
    $('img.help_popup_activate_btn').click(function (e) {
        // Disable event bubbling
        if (!e) var e = window.event;
        e.cancelBubble = true;
        if (e.stopPropagation)
            e.stopPropagation();

        // Show help popup
        var top = GetContentTop();
        if ($('.content:first').length > 0)
            top = $('.content:first').offset().top + 55;
            else
                if ($('.content_admin:first').length > 0)
                    top = $('.content_admin:first').offset().top + 55;

        var dialogContent = $('#' + $(this).attr('HelpPopupId'));
        dialogContent.dialog({
            position: [null, top, null, null],
            width: 250,
            resizable: false,
            draggable: false,
            dialogClass: 'help-popup'
        });
        dialogContent.show();
        return false;
    });
    $('img.help_popup_close_btn').click(function () {
        // Hide help popup
        var dialogContent = $('#' + $(this).attr('HelpPopupId'));
        dialogContent.dialog('close');
        dialogContent.hide();
    });
});

function GetContentTop() {
    var top = 200;
    if ($('.content:first').length > 0)
        top = $('.content:first').offset().top + 55;
    else
        if ($('.content_admin:first').length > 0)
            top = $('.content_admin:first').offset().top + 55;
    return top;
}

/* TopMenu */
$(function () {
    $('.menu li .drop').hide();
    $('.menu li').hover(function () {
        $(this).addClass('active');
        $(this).find('div.drop').css({ zIndex: 90 }).fadeIn(100);
        $(this).hover(function () {
        }, function () {
            $(this).find('div.drop').css({ zIndex: 99 }).fadeOut(100);
        });
    }, function () {
        $(this).removeClass('active');
    });
});

/* CustomerServicePopup */
$(function () {
    var collapsedimg = '/style/icons/arrow_rght.png';
    var expandedimg = '/style/icons/arrow_dwn.png';

    $('#servicegroups h4').click(function () {
        var par = $(this).closest('li');
        var infoblock = $('ul', par);
        var arrow = $('.arr', this);

        var collapsed = arrow.attr('src') == collapsedimg;

        $('#servicegroups li ul').animate({ height: 'hide' }, 0);
        $('#servicegroups li h4 img').attr('src', collapsedimg);

        // reset other categories
        $('#servicegroups .answer_block').hide();
        $('#servicegroups .select1').val('');

        if (collapsed) {
            infoblock.animate({ height: 'show' }, 0); //200
            arrow.attr('src', expandedimg);
        } else {
            infoblock.animate({ height: 'hide' }, 0);
            arrow.attr('src', collapsedimg);
        }
    });

    $('#servicegroups .select1').change(function () {
        var value = $(this).val();

        var par = $(this).closest('ul');
        var pnl = $('.answer_block', par);
        var txt = $('.answer_text', par);

        if (value != '') {
            txt.text(value);
            pnl.show();
        } else {
            pnl.hide();
            txt.text('');
        }
    });
});


/* Centered popups */
$(document).ready(function () {

    MakePopupCentered('div.centered_popup');
    $.each($('div.centered_popup.autopopup'), function () {
        $(this).show();
    });

});

function MakePopupCentered(selector) {
    $.each($(selector), function () {
        // vertical centering
        var width = $(this).width();
        var margLeft = -width / 2;

        $(this).css('top', GetContentTop() + 'px');
        $(this).css('left', '50%');
        $(this).css('margin-left', margLeft + 'px');
    });
}

