$(document).ready(function() {
    $('.jobMatch, .jobMatchLargePullDownR').click(function() {

        $('.dropDownMatch').hide();

        $('.dropDownMatch').css('left', '-10px');

        $('.dropDownMatch').toggle(130);

        return false;

    });

    /*added focus and blur event handlers to display drop down when

    using tab to jump between links */

    $('.dropDownMatch a').focus(function() {

        $('.dropDownMatch').css('left', '-10px');

        return false;

    });

    $('.dropDownMatch a').blur(function() {

        $('.dropDownMatch').css('left', '');

        return false;

    });

    $('.dropDownClose').click(function() {

        $('.dropDownMatch').hide(130, function() {

            ;

            $('.dropDownMatch').css('left', '-10000px');

            $('.dropDownMatch').css('display', 'block');

        })

        return false;

    });

    $('.dropDownMatch').css('left', '-10000px');

    $('.dropDownMatch').css('display', 'block');


    // For the spanish translation drop down

    // Attach a click event to the body to hide the dropdown spanish, when clicked outside. 

    $('body').click(function() {
      
        //Hide the dropdown when clicked on page
        $('.dropDownTransMatch').css('right', '10000px');
        $('.dropDownDistMatch').css('right', '10000px');
        $("#dropDownViewMatch").css("left", "-10000px");
        $("#dropDownLightboxIndustryMatch").css("left", "-10000px");
        $("#dropDownWithinMatch").css("left", "-10000px");
        $("#dropDownSizeMatch").css("left", "-10000px");
        //$('.dropDownTransMatch1').css('right', '10000px');

        $('.toggles').show();
    });


    $('.translate, .translatePullDownR').click(function(event) {
 
        // event.stopPropagation();
        $('.dropDownTransMatch').hide();
        $.cookie('provider', 'google');
        // this is an ugly fix for ie6. need to find a better solution
        if (jQuery.browser.version.substr(0, 1) == "6") {
            $('.dropDownTransMatch').css('right', '15px');
        }
        else {
            if ($.browser.msie) {
                $('.dropDownTransMatch').css('top', '151px');
            } else if ($.browser.mozilla) {
                $('.dropDownTransMatch').css('top', '138px');
            }
            $('.dropDownTransMatch').css('right', '370px');
        }
        $('.dropDownTransMatch').toggle(30);

        return false;

    });

    /*added focus and blur event handlers to display drop down when

    using tab to jump between links */

    $('.dropDownTransMatch a').focus(function() {

        // this is an ugly fix for ie6. need to find a better solution
        if (jQuery.browser.version.substr(0, 1) == "6") {
            $('.dropDownTransMatch').css('right', '15px');
        }
        else {
            $('.dropDownTransMatch').css('right', '370px');
        }

        return false;

    });

    $('.dropDownTransMatch a').blur(function() {

        $('.dropDownTransMatch').css('right', '10000px');

        return false;

    });

    $('.dropDownTransMatch').css('right', '10000px');
    $('.dropDownTransMatch').css('display', 'block');

    // Code for div mouse overs
    $('#divSelLangen,#divSelLanges').mouseleave(function() {
        $(this).css('background-color', '').css('color', '#000000');
        return false;
    });

    $('#divSelLangen,#divSelLanges').mouseenter(function() {
        // first remove all the background colors
        $('#divSelLangen').css('background-color', '').css('color', '#000000');
        $('#divSelLanges').css('background-color', '').css('color', '#000000');
        // set the backgroun color of mouse over element
        $(this).css('background-color', '#0099dc').css('color', 'white');

        return false;
    });

    //new code for keyboard
    $('#aSelLangen,#aSelLanges').focus(function() {
        // first remove all the background colors
        $('#divSelLangen').css('background-color', '').css('color', '#000000');
        $('#divSelLanges').css('background-color', '').css('color', '#000000');
        // set the backgroun color of mouse over element
        $(this).parent().css('background-color', '#0099dc').css('color', 'white');

        return false;
    });
    $('#aSelLangen,#aSelLanges').blur(function() {
        $(this).parent().css('background-color', '').css('color', '#000000');
        return false;
    });

    /*---------------For distance drop down-----------------------------*/

    $('.distance, .distancePullDownR').click(function(event) {
        $('.dropDownDistMatch').hide();
        $('.toggles').hide();
        // this is an ugly fix for ie6. need to find a better solution
        if (jQuery.browser.version.substr(0, 1) == "6") {
            $('.dropDownDistMatch').css('right', '12px');
        }
        else {
            $('.dropDownDistMatch').css('right', '5px');
        }
        //  $('.toggles').show();
        $('.dropDownDistMatch').toggle(130);
        return false;

    });

    /*added focus and blur event handlers to display drop down when
    using tab to jump between links */

    $('.dropDownDistMatch a').focus(function() {
        // this is an ugly fix for ie6. need to find a better solution
        if (jQuery.browser.version.substr(0, 1) == "6") {
            $('.dropDownDistMatch').css('right', '12px');
        }
        else {
            $('.dropDownDistMatch').css('right', '5px');
        }
        return false;
    });

    $('.dropDownDistMatch a').blur(function() {
        $('.dropDownDistMatch').css('right', '10000px');
        return false;
    });

    $('.dropDownDistMatch').css('right', '10000px');
    $('.dropDownDistMatch').css('display', 'block');


    // set the distance value
    var urlParams = decodeURI(window.location.search.substring(1));
    if (urlParams == false | urlParams == '') { }
    else {
        var qRadius = $.getParam("radius");
        if (qRadius == 0) {
            if ($.cookie('lang') == 'es') {
                $(".distance").html("Distancia");
            }
            else {
                $(".distance").html("Distance");
            }
        }
        else {
            if ($.cookie('lang') == 'es') {
                $(".distance").html(qRadius + " millas");
            }
            else {
                $(".distance").html(qRadius + " miles");
            }
        }
    }
    // mouse over and mouse leave events for the dropdown items 
    $('.dropDownDistMid').children().each(function(index) {
        $(this).css('background-color', '').css('color', '#000000');
        // Preselect and set background color for the selected distance
        var vardis = $(this).text().replace('miles', '').replace('millas', '');
        if (qRadius.replace(' ', '') == vardis.replace(' ', '')) {
            $(this).css('background-color', '#0099dc').css('color', 'white');
        }
        $(this).bind("click", function() {
            $(".distance").html($(this).text());
            selectOption("ctl00_ContentPlaceHolder1_UCFilterZipControl_ddlistDistance", vardis);
            selectOption("ctl06_UCFilterZipControl_ddlistDistance", vardis);
        });

        $(this).bind("mouseleave", function() {
            $(this).css('background-color', '').css('color', '#000000');
        });

        $(this).bind("mouseenter", function() {
            $(this).css('background-color', '#0099dc').css('color', 'white');
        });

    });

    // set the selected value for the drop down to pass to code behind
    function selectOption(selectId, optionVal) {
        $('#' + selectId + ' option:selected').removeAttr('selected');
        $('#' + selectId + ' option[value=' + optionVal + ']').attr('selected', 'selected');
    }



    /*---------------For view per page drop down-----------------------------*/

    $("#dropDownViewValue").html($(".dropDownPages").val());


    $("#dropDownViewPullDownR").click(function(event) {
        var dropDownPosition = $("#dropDownViewPullDownL").position();
        $("#dropDownViewMatch").hide();

        // this is an ugly fix for ie6. need to find a better solution
        if (jQuery.browser.version.substr(0, 1) == "6") {
            $("#dropDownViewMatch").css("top", dropDownPosition.top + 22).css("left", dropDownPosition.left); ;
        }
        else {
            $("#dropDownViewMatch").css("top", dropDownPosition.top + 22).css("left", dropDownPosition.left); ;
        }
        //  $('.toggles').show();
        $('#dropDownViewMatch').toggle(130);
        return false;

    });

    /*added focus and blur event handlers to display drop down when
    using tab to jump between links */

    $("#dropDownViewMatch a").focus(function() {
        var dropDownPosition = $("#dropDownViewPullDownL").position();
        // this is an ugly fix for ie6. need to find a better solution
        if (jQuery.browser.version.substr(0, 1) == "6") {
            $("#dropDownViewMatch").css("top", dropDownPosition.top + 22).css("left", dropDownPosition.left);
        }
        else {
            $("#dropDownViewMatch").css("top", dropDownPosition.top + 22).css("left", dropDownPosition.left);
        }
        $(this).parent().css('background-color', '#0099dc').css('color', 'white');

        //}
        return false;
    });

    $('#dropDownViewMatch a').blur(function() {
        $('#dropDownViewMatch').css('left', '-10000px')
        $(this).parent().css('background-color', '').css('color', '#000000');
        return false;
    });

    $('#dropDownViewMatch').css('left', '-10000px');
    $('#dropDownViewMatch').css('display', 'block');


    // set the distance value
    //    var urlParams = decodeURI(window.location.search.substring(1));
    //    if (urlParams == false | urlParams == '') { }
    //    else {
    //        var qRadius = $.getParam("radius");
    //        if (qRadius == 0) {
    //            if ($.cookie('lang') == 'es') {
    //                $(".distance").html("Distancia");
    //            }
    //            else {
    //                $(".distance").html("Distance");
    //            }
    //        }
    //        else {
    //            if ($.cookie('lang') == 'es') {
    //                $(".distance").html(qRadius + " millas");
    //            }
    //            else {
    //                $(".distance").html(qRadius + " miles");
    //            }
    //        }
    //    }
    // mouse over and mouse leave events for the dropdown items 
    $('#dropDownViewMid').children().each(function(index) {
        $(this).css('background-color', '').css('color', '#000000');
        // Preselect and set background color for the selected distance

        $(this).bind("click", function() {
            $("#dropDownViewValue").html($(this).text());
            $(".dropDownPages").val($(this).text());
            $('#aspnetForm').submit();
            $('#Form1').submit();
        });

        $(this).bind("mouseleave", function() {
            $(this).css('background-color', '').css('color', '#000000');
        });

        $(this).bind("mouseenter", function() {
            $(this).css('background-color', '#0099dc').css('color', 'white');
        });

    });

    // mouse over and mouse leave events for the dropdown items
    $('#EmpdropDownViewMid').children().each(function(index) {
        $(this).css('background-color', '').css('color', '#000000');
        // Preselect and set background color for the selected distance

        $(this).bind("click", function() {
            $("#dropDownViewValue").html($(this).text());
            $(".dropDownPages").val($(this).text());
            $('#aspnetForm').submit();
            $('#Form1').submit();
        });

        $(this).bind("mouseleave", function() {
            $(this).css('background-color', '').css('color', '#000000');
        });

        $(this).bind("mouseenter", function() {
            $(this).css('background-color', '#0099dc').css('color', 'white');
        });

    });

    /*---------------For Location per page drop down-----------------------------*/


    $("#dropDownLightboxIndustryValue").html($(".LightboxIndustrydropDownPages :selected").text());

    $("#dropDownLightboxIndustryValue, #dropDownLightboxIndustryPullDownR").click(function(event) {
        var dropDownPosition = $("#dropDownLightboxIndustryPullDownL").position();
        $("#dropDownLightboxIndustryMatch").hide();
        $("#dropDownWithinMatch").hide();
        $("#dropDownSizeMatch").hide();

        // this is an ugly fix for ie6. need to find a better solution
        if (jQuery.browser.version.substr(0, 1) == "6") {
            $("#dropDownLightboxIndustryMatch").css("top", dropDownPosition.top + 22).css("left", dropDownPosition.left); ;
        }
        else {
            $("#dropDownLightboxIndustryMatch").css("top", dropDownPosition.top + 26).css("left", dropDownPosition.left); ;
        }
        $('.toggles').show();
        $('#dropDownLightboxIndustryMatch').toggle(130);
        return false;

    });

    $('#dropDownLightboxIndustryMatch a').blur(function() {
        $('#dropDownLightboxIndustryMatch').css('left', '-10000px')
        $(this).parent().css('background-color', '').css('color', '#000000');
        return false;
    });

    $('#dropDownLightboxIndustryMatch').css('left', '-10000px');
    $('#dropDownLightboxIndustryMatch').css('display', 'block');

    // mouse over and mouse leave events for the dropdown items
    $('#dropDownLightboxIndustryMid').children().each(function(index) {
        $(this).css('background-color', '').css('color', '#000000');
        // Preselect and set background color for the selected distance
        var vardis = $(this).text()
        $(this).bind("click", function() {
            $("#dropDownLightboxIndustryValue").html($(this).text());
            // $(".LightboxIndustrydropDownPages").val($(this).text());


            selectOption("ctl00_ContentPlaceHolder1_ddlLightboxIndustry", $(this).id());
            //  selectOption("ctl06_UCFilterZipControl_ddlistDistance", $(this).text());

            // $('#aspnetForm').submit();
            //  $('#Form1').submit();
        });

        $(this).bind("mouseleave", function() {
            $(this).css('background-color', '').css('color', '#000000');
        });

        $(this).bind("mouseenter", function() {
            $(this).css('background-color', '#0099dc').css('color', 'white');
            $(this).css('width', '95%').css('margin-left', '2px');
        });
    });


    /*---------------For With in per page drop down-----------------------------*/


    $("#dropDownWithinValue").html($(".WithindropDownPages :selected").text());

    $("#dropDownWithinValue, #dropDownWithinPullDownR").click(function(event) {
        var dropDownPosition = $("#dropDownWithinPullDownL").position();
        $("#dropDownWithinMatch").hide();

        $("#dropDownSizeMatch").hide();
        $("#dropDownLightboxIndustryMatch").hide();

        // this is an ugly fix for ie6. need to find a better solution
        if (jQuery.browser.version.substr(0, 1) == "6") {
            $("#dropDownWithinMatch").css("top", dropDownPosition.top + 250).css("left", dropDownPosition.left); ;
        }
        else {
            $("#dropDownWithinMatch").css("top", dropDownPosition.top + 250).css("left", dropDownPosition.left); ;
        }
        //  $('.toggles').show();
        $('#dropDownWithinMatch').toggle(130);
        return false;

    });

    $('#dropDownWithinMatch a').blur(function() {
        $('#dropDownWithinMatch').css('left', '-10000px')
        $(this).parent().css('background-color', '').css('color', '#000000');
        return false;
    });

    $('#dropDownWithinMatch').css('left', '-10000px');
    $('#dropDownWithinMatch').css('display', 'block');

    // mouse over and mouse leave events for the dropdown items
    $('#dropDownWithinMid').children().each(function(index) {
        $(this).css('background-color', '').css('color', '#000000');
        // Preselect and set background color for the selected distance

        $(this).bind("click", function() {
            $("#dropDownWithinValue").html($(this).text());
            //$(".WithindropDownPages").val($(this).text());
            selectOption("ctl00_ContentPlaceHolder1_ddlWithin", $(this).id());

            //$('#aspnetForm').submit();
            //$('#Form1').submit();
        });

        $(this).bind("mouseleave", function() {
            $(this).css('background-color', '').css('color', '#000000');
        });

        $(this).bind("mouseenter", function() {
            $(this).css('background-color', '#0099dc').css('color', 'white');
            $(this).css('width', '90%').css('margin-left', '2px');
        });
    });
    /*---------------For Size per page drop down-----------------------------*/


    $("#dropDownSizeValue").html($(".SizedropDownPages :selected").text());

    $("#dropDownSizeValue, #dropDownSizePullDownR").click(function(event) {
        var dropDownPosition = $("#dropDownSizePullDownL").position();
        $("#dropDownSizeMatch").hide();
        $("#dropDownLightboxIndustryMatch").hide();
        $("#dropDownWithinMatch").hide();

        // this is an ugly fix for ie6. need to find a better solution
        if (jQuery.browser.version.substr(0, 1) == "6") {
            $("#dropDownSizeMatch").css("top", dropDownPosition.top + 250).css("left", dropDownPosition.left + 210); ;
        }
        else {
            $("#dropDownSizeMatch").css("top", dropDownPosition.top + 250).css("left", dropDownPosition.left + 210); ;
        }
        //  $('.toggles').show();
        $('#dropDownSizeMatch').toggle(130);
        return false;

    });

    $('#dropDownSizeMatch a').blur(function() {
        $('#dropDownSizeMatch').css('left', '-10000px')
        $(this).parent().css('background-color', '').css('color', '#000000');
        return false;
    });

    $('#dropDownSizeMatch').css('left', '-10000px');
    $('#dropDownSizeMatch').css('display', 'block');

    // mouse over and mouse leave events for the dropdown items
    $('#dropDownSizeMid').children().each(function(index) {
        $(this).css('background-color', '').css('color', '#000000');
        // Preselect and set background color for the selected distance

        $(this).bind("click", function() {
            $("#dropDownSizeValue").html($(this).text());
            //$(".SizedropDownPages").val($(this).text());
            selectOption("ctl00_ContentPlaceHolder1_ddlLigthBoxSize", $(this).id());
            //$('#aspnetForm').submit();
            //$('#Form1').submit();
        });

        $(this).bind("mouseleave", function() {
            $(this).css('background-color', '').css('color', '#000000');
        });

        $(this).bind("mouseenter", function() {
            $(this).css('background-color', '#0099dc').css('color', 'white');
            $(this).css('width', '90%').css('margin-left', '2px');
        });
    });




    //-----------
    //    $('.translate1, .translatePullDownR1').click(function(event) {

    //        // event.stopPropagation();
    //        $('.dropDownTransMatch1').hide();
    //        $.cookie('provider', 'beglobal');
    //        // this is an ugly fix for ie6. need to find a better solution
    //        if (jQuery.browser.version.substr(0, 1) == "6") {
    //            $('.dropDownTransMatch1').css('right', '15px');
    //        }
    //        else {
    //            $('.dropDownTransMatch1').css('right', '45px');
    //        }

    //        $('.dropDownTransMatch1').toggle(130);

    //        return false;

    //    });

    //   /*added focus and blur event handlers to display drop down when

    //using tab to jump between links */

    //    $('.dropDownTransMatch1 a').focus(function() {

    //        // this is an ugly fix for ie6. need to find a better solution
    //        if (jQuery.browser.version.substr(0, 1) == "6") {
    //            $('.dropDownTransMatch1').css('right', '15px');
    //        }
    //        else {
    //            $('.dropDownTransMatch1').css('right', '45px');
    //        }

    //        return false;

    //    });

    //    $('.dropDownTransMatch1 a').blur(function() {

    //        $('.dropDownTransMatch1').css('right', '10000px');

    //        return false;

    //    });

    //    $('.dropDownTransMatch1').css('right', '10000px');
    //    $('.dropDownTransMatch1').css('display', 'block');

    //    // Code for div mouse overs
    //    $('#divSelLangen1,#divSelLanges1').mouseleave(function() {
    //        $(this).css('background-color', '').css('color', '#000000');
    //        return false;
    //    });

    //    $('#divSelLangen1,#divSelLanges1').mouseenter(function() {
    //        // first remove all the background colors
    //        $('#divSelLangen1').css('background-color', '').css('color', '#000000');
    //        $('#divSelLanges1').css('background-color', '').css('color', '#000000');
    //        // set the backgroun color of mouse over element
    //        $(this).css('background-color', '#0099dc').css('color', 'white');

    //        return false;
    //    });

    //    //new code for keyboard
    //    $('#aSelLangen1,#aSelLanges1').focus(function() {
    //        // first remove all the background colors
    //        $('#divSelLangen1').css('background-color', '').css('color', '#000000');
    //        $('#divSelLanges1').css('background-color', '').css('color', '#000000');
    //        // set the backgroun color of mouse over element
    //        $(this).parent().css('background-color', '#0099dc').css('color', 'white');

    //        return false;
    //    });
    //    $('#aSelLangen1,#aSelLanges1').blur(function() {
    //        $(this).parent().css('background-color', '').css('color', '#000000');
    //        return false;
    //    });

    //---------------------------

});


