$(document).ready(function() {
    acoruja.init();
})

acoruja = {
    init: function() {
        this.openplus();
        this.searchstuff();
        this.plusopt();
        if($('#showplaces').length > 0) { this.showplaces(); }
        if($('#expandlist').length > 0) { this.expandlist(); }
        if($('#flashMessage').length > 0) { this.flashanimate(); }
        if($('#provACajax').length > 0) { this.autocomplete(); }
    },
    
    openplus: function() {
        if($('#SearchCity').val() != "" || $('#SearchStateId').val() != "" || $('#SearchTypeId').val() != "") {
            $('#MaisOpt').toggle();
            setTimeout(function() { $('#MaisOpt').hide('slow'); },5000);
        }
    },
    
    searchstuff: function() {
        if($('#SearchSubject').val() == "") {
            $('#SearchSubject').css('background-image', 'url(\''+my_url+'img/bucarlabel.gif\')').css('background-repeat', 'no-repeat');
            
            $('#SearchSubject').focus(function() {
                $(this).css('background-image','none');
            }).blur(function() {
                if($(this).val() == '') {
                    $(this).css('background-image', 'url(\''+my_url+'img/bucarlabel.gif\')');
                }
            })
        }
    },
    
    plusopt: function() {
        $('#PlusOpt').click(function() {
            $('#MaisOpt').toggle('fast');
            return false;
        })
    },
    
    showplaces: function() {
        $('#showplaces').click(function() {
            $('#places').toggle('slow');
            
            return false;
        })
    },
    
    expandlist: function() {
        $('#expandlist').click(function() {
            $('#filters').toggle('slow');
            
            return false;
        })
    },
    
    flashanimate: function() {
        $('#flashMessage').animate({"opacity": "0.2"}, "fast").animate({"opacity": "1.0"}, "fast").animate({"opacity": "0.2"}, "fast").animate({"opacity": "1.0"}, "fast").animate({"opacity": "0.2"}, "fast").animate({"opacity": "1.0"}, "fast");
    },
    
    autocomplete: function() {
        $('#ProviderName').suggest(my_url+"providers/suggest/");
    }
}



