var TOPMENU_TIMER;
var TOPMENU_TIMER_MS = 2000;

function topmenuHide()
{
    $('#topmenu > ul > li > ul').hide();
}


$(document).ready(function () {
    $('#topmenu > ul > li > div').hide();
    $('#topmenu > ul > li').each(function () {
        $(this).css('width', parseInt($(this).width()*1.07)+'px');
    });
    $('#topmenu > ul > li > div').show();
});

/*
function topmenuBottomsSetup()
{
    var bottom;
    var active;
    var offsetLeft;
    var topbarOffsetLeft = parseInt($('#topbar').offset().left);
    $('#topmenu > ul > li').each(function (i) {
       $(this).attr('index', i);

       offsetLeft = parseInt($(this).offset().left) + parseInt(parseInt($(this).width())/2 - 22) - topbarOffsetLeft;
       if ($(this).find('> a').hasClass('active'))
           active = 'active'; else
           active = '';
       bottom = '<span class="topmenu-bottom '+active+'" style="left: '+offsetLeft+'px">&nbsp;</span>';
       $("#topmenu-bottoms").append(bottom);
    });
}

function topmenuBottoms()
{
    $(window).load(function() {
        topmenuBottomsSetup()
    });
}

$(document).ready(function () {

    $(document).click(function () {
        topmenuHide();
    });

    $(window).resize(function () {
        topmenuHide();
    });

    // find active menu link and mark it
    $('#topmenu > ul > li > a').each(function () {
        if ($(this).hasClass('active'))
            $(this).addClass('this-is-active');
    });

    $('#topmenu > ul > li').mousemove(function () {
        clearTimeout(TOPMENU_TIMER);
    });

    // menu
    $('#topmenu > ul > li').hover(
        function () {
            clearTimeout(TOPMENU_TIMER);
            $('#topmenu > ul > li > ul').hide();
            $(this).find('> ul').show();
            
            // for active link do nothing
            if ($(this).find('> a').hasClass('this-is-active'))
                return;

            $(this).find('> a').addClass('active');
            var index = parseInt($(this).attr('index'))+1;
            $("#topmenu-bottoms > span:nth-child("+index+")").addClass('active');
        },
        function () {
            // if not active link remove hover effect
            if ( ! $(this).find('> a').hasClass('this-is-active')) {
                $(this).find('> a').removeClass('active');
                var index = parseInt($(this).attr('index'))+1;
                $("#topmenu-bottoms > span:nth-child("+index+")").removeClass('active');
            }
        }
    );

       
    $('#topmenu > ul > li > ul').hover(
        function () {
            clearTimeout(TOPMENU_TIMER);
        },
        function () {
            TOPMENU_TIMER = setTimeout('topmenuHide()', TOPMENU_TIMER_MS);
        }
    );
        
});
*/

function goTop()
{
    $('html, body').animate({scrollTop: $("#top-bar").offset().top}, 1000);
}


function isValidEmailAddress(emailAddress)
{
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}

