//Function to add search type selection events
$(document).ready(
    function addSearchTypeListeners(){       
        //hover actions to handle showing and hiding the options
        $("#divSearchDropDown").hover(
            //hover over actions
            function(){
                /* the show_product page screws up the dropdown's top location so we'll fix it here */
                if (location.href.substring(0,50) == 'http://www.crestron.com/products/show_products.asp')
                {
                    $("#listSearchDropDownOptions").css("top",1);
                }
                /* done fixxing the dropdown's top location */            
                if( jQuery.browser.msie && (jQuery.browser.version < 7) )
                {
                    var p = $("#divSearchDropDownHeader");
                    var position = p.offset();
                    $("#listSearchDropDownOptions").css("left",position.left + 5);  //Fix the left position in ie 6
                }
                if( jQuery.browser.msie && (jQuery.browser.version <= 7) ) 
                {
                    $("#divProductJump").hide();                            //Hide the product jump in ie 6 and 7
                }
                $("#listSearchDropDownOptions").slideDown(300);         //Slide the options into view
            },
            //hover out actions
            function(){
                //var t = setTimeout('$("#divSearchDropDownBody").slideUp(300);',2000)               //Slide the options out of view after 2000 ms
                var t = setTimeout('$("#listSearchDropDownOptions").slideUp(300);$("#divProductJump").show();',3000);
            }
        );
        
        //click actions for each option
        $("#listSearchDropDownOptions > li").click(
            function(){
                $("#divSearchDropDownHeader").html($(this).html());     //Make the dropdown header indicate the clicked element
                $("#crestron_search_type").val($(this).attr("id"));     //Set the value of the hidden field to indicate the selected type of search
                //$("#divSearchDropDownBody").slideUp(300);               //Slide the options out of view
                $("#listSearchDropDownOptions").slideUp(300);
                if( jQuery.browser.msie && (jQuery.browser.version <= 7) ) 
                {
                    $("#divProductJump").show();                            //Show the product jump in ie 6
                }
            }
        );
    }
);
