function runSearch(searchString){
    if(searchString == undefined){
        searchString = $('#searchbox').val();
    }
    var string = searchString.toLowerCase();
    string = string.replace(/[^a-zA-Z0-9_]/g,'+');
    document.location='/search/tags/'+string;
}

function checkSearchValue(){
    if($('#searchbox').val() == "Search..."){
        $('#searchbox').val('');
        //$('#searchbox').css('background', 'no-repeat scroll 180px 50% transparent');
        $('#searchbox').removeClass('globalsearch');
    }
}

$(function () {
    $('#searchbox').catcomplete({
        source: "/search/autocomplete",
        //start looking at 3 characters because mysql's limit is 4
        minLength: 3,
        // add zero delay
        delay: 0,
        //set z-index
        zIndex: 10,
        // mazimum height for this autocomplete
        maxHeight:400,
        //when you have selected something
        select: function(event, ui) {
            //close the drop down
            this.close;
            runSearch(ui.item.value);
        },
        //show the drop down
        open: function() {
            $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
        },
        //close the drop down
        close: function() {
            $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
        }
    });
});
