$(function(){
var cornerlist = [
                  'input', 
                  'form fieldset legend', 
                  'ul.controls', 
                  'ul.controls li a'
                 ];
//no ie for now                 
if(!$.browser.msie){ $(cornerlist.join(", ")).corner(); }

$(".service").hover(
    function() { $(this).toggleClass('hover'); }, 
    function() { $(this).toggleClass('hover'); }
);

$("#title").click(function() {
        window.location = config.fqurl;
});

$("#topnav-hide").click(function(){
    $('#topnav').hide('slide', { direction: 'right' }, 1000);return false;
});

$("#search-services-input").focus(function(){
        $(this).val('');
});
$("#search-services-input").blur(function(){
        $('#search-popup').stop().fadeOut(200);
});

var search_timeout_lock;
$("#search-services-input").keyup(function(e){
        //if (e.which == 32 || (65 <= e.which && e.which <= 65 + 25)
        //                || (97 <= e.which && e.which <= 97 + 25)) {
            var v = $(this).val();
            
            if(v.length < 1) {
                clearTimeout(search_timeout_lock);
                $('#search-popup').remove();
                $('#services .service').show();
            } else {
                if($('#search-popup').html()){
                    clearTimeout(search_timeout_lock);
                    var pt = $('#search-popup-text');
                    var p = $('#search-popup');
                    //p.stop();
                    pt.html(v);
                    p.fadeIn(10, function(){search_timeout_lock=setTimeout("$('#search-popup').fadeOut(1000)", 2000)});
                    
                } else {
                    pop = $(document.createElement('div'));
                    pop.attr("id","search-popup");
                    popt = $(document.createElement('div'));
                    popt.attr('id','search-popup-text');
                    popt.html(v);
                    popt.corner();
                    pop.append(popt);
                    pop.hide();
                    $('body').append(pop);
                    
                    pop.fadeIn(500, function(){search_timeout_lock=setTimeout("$('#search-popup').fadeOut(1000);", 2000)});
                    
                }
            
            //remove any with a class 'service' which have an id beginning with $(this.val())
                $('.service[id^='+v+']').show();
                $('.service:not([id^='+v+'])').hide();
            }
            
            //if there's only one service left in the list, highlight it so the
            //user can press enter to open it
      /*} else if (e.which == 8) {
          
      }*/
        
    
});

});
