﻿$(function () {
        window.fix = {
            browser: $.client.browser,
            os: $.client.os
        }
 
        // Internet explorer cursor color fix
        if (fix.browser == 'Explorer') {
            $('#corp-global-search-box').css('background', '#919191');
        }
        // header anchor titles
        $('#global-nav .right a').each(function () {
            var anchorTitle = $(this).text();
            $(this).attr('title', anchorTitle);
        });
 
 
     // Tabs
       try {

            var num1 = corpHomeLeftTabbedContent;
            if (num1 != null && num1 != 0) {
                $('#corp-home-left-tabbed-content > li').eq(num1 - 1).show();
                $('#corp-home-left-tabs > li').eq(num1 - 1).addClass('selected');
            }
            else {
                $('#corp-home-left-tabbed-content > lifirst').show();
                $('#corp-home-left-tabs > li:first').addClass('selected');
            }
        }
        catch (err) {
            $('#corp-home-left-tabbed-content > li:first').show();
            $('#corp-home-left-tabs > li:first').addClass('selected');
        }





        $('#corp-home-left-tabs li a').click(function (e) {
            e.preventDefault();
            $('#corp-home-left-tabbed-content > li:visible').hide();
            $('#corp-home-left-tabs > li:visible').removeClass('selected');
            $('#corp-home-left-tabbed-content > li').eq($(this).closest('li').index()).show();
            $(this).closest('li').addClass('selected');
        });







    try {



        var num = corpHomeRightTabbedContent;
        if (num != null && num != 0) {
            $('#corp-home-right-tabbed-content > li').eq(num - 1).show();
            $('#corp-home-right-tabs > li').eq(num - 1).addClass('selected');
        }
        else {
            $('#corp-home-right-tabbed-content > li:first').show();
            $('#corp-home-right-tabs > li:first').addClass('selected');
        }
    }
    catch (err) {
        $('#corp-home-right-tabbed-content > li:first').show();
        $('#corp-home-right-tabs > li:first').addClass('selected');
    }

    $('#corp-home-right-tabs li a').click(function (e) {
        e.preventDefault();
        $('#corp-home-right-tabbed-content > li:visible').hide();
        $('#corp-home-right-tabs > li:visible').removeClass('selected');
        $('#corp-home-right-tabbed-content > li').eq($(this).closest('li').index()).show();
        $(this).closest('li').addClass('selected');
    });


    //navigation
    $('.nav-hover').hover(
        function () {
            var that = $(this);
            var divWidth = $(this).children('div').width();

            if ($(that).hasClass('next-to-last') || $(that).hasClass('last')) {
                $(this).children('div').css('left', -divWidth + 5 + $(that).width()).show();
            } else {
                $(this).children('div').css('right', divWidth + $(that).width()).show();
            }
        },
        function () {
            $(this).children('div').hide();
        });




    // language options
    $('#current-lang-item, #lang-item-list').click(function () {
        $('#lang-item-list').toggle();

        if ($('#current-lang-item').is('.on')) {
            $(this).removeClass('on');
        } else {
            $(this).addClass('on');
            $('#lang-item-list').click(function () {
                $('#current-lang-item').removeClass('on');
            });
        }
        $('#lang-item-list img').each(function () {
            var altText = $(this).attr('alt');

            $(this).closest('a').attr('title', altText);

        });

    }); // end click func


    $('p').filter(function () {
        return $.trim($(this).text()) === ''
    }).remove();

    //navigation active state.
    try {
        var topnav = $('#top-nav .lev1');

        for (i = 0; i < topnav.length; i++) {
            if (window.location.pathname.toLowerCase().search($(topnav[i]).attr('id')) != -1) {
                $(topnav[i]).parent().addClass('active');
                break;
            }
        }
    }
    catch (err) {
    }

    //nav fix
    $('#top-nav li:last').css('margin-left', '2px;');

    $('#corp-global-search-box').keydown(function (e) {

        if (e.keyCode == 13) //enter
        {
            e.preventDefault();
            $('#corp-global-search-go').click();
            console.log('enter button pressed');
        }
    });


});
