function runSearch(){
    var searchString = $('#keywords').val();
    var string = searchString.toLowerCase();
    string = string.replace(/[^a-zA-Z0-9_]/g,'+');
    document.location="/images/tags/"+string;
}
$(function () {
    $('#keywords').autocomplete({
        source: siteroot+"/bin/views/autocomplete.view.php",
        //start looking at 3 characters because mysql's limit is 4
        minLength: 3,
        //when you have selected something
        select: function(event, ui) {
            //close the drop down
            this.close
            runSearch();
        },
        //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");
        }
    });
});

function searchBox(){
    if($('#searchBoxWidget').length != 0){
        $('#searchBoxWidget').remove();
    }
    if($('#dialog').length == 0){
        $('body').append("<div id='dialog'></div>");
    }
    $.ajax({
        type:"GET",
        url: siteroot+'/bin/views/search.view.widget.php',
        async:true,
        success: function(content){
            $("#dialog").attr('title', "Find an image");
            $("#dialog").show();
            $("#dialog").html(content);
            $("#dialog").dialog({
                bgiframe: true,
                height: 150,
                width:350,
                modal: true,
                draggable: true
            });
        }
    });
    
}
