$(document).ready(function() {
    function OnResize() {
        var width = $(window).width();
        if(width < 1070) {
            $('body').addClass('small');
        }
        else {
            $('body').removeClass('small');
        }
    }


    OnResize();
    $(window).bind("resize", OnResize);


    $(".menu ul li a").live('click', function (e) {
        $(e.target).closest("li").addClass("actual").siblings('.actual').removeClass('actual');
    });
    $('table tbody tr:odd').addClass('odd');
    $('table tbody tr:even').addClass('even');
    $('table.homelisting tbody tr').hover(function() {
        $(this).addClass('hover');
    }, function() {
        $(this).removeClass('hover');
    });
    $( '#leftAd' ).scrollFollow();
    $(".smartform input:text, .smartform  input:password, .smartform select, .smartform input:file, .smartform textarea").bind("focus blur",function(f) {
        var t = f.type == "focus" ? "add" : "remove";
        $(this).prevAll("label:first").andSelf()[t+"Class"]("focus");
    });
            
            
    var cache = {},
    lastXhr;
    $( ".searchfield" ).autocomplete({
        minLength: 2,
        delay: 500,
        source: function( request, response ) {
            var term = request.term;
            if ( term in cache ) {
                response( cache[ term ] );
                return;
            }

            lastXhr = $.getJSON( "libs/autocomplete.php", request, function( data, status, xhr ) {
                cache[ term ] = data;
                if ( xhr === lastXhr ) {
                    response( data );
                }
            });
        },
        select: function( event, ui ) { 
            window.location.href = "http://www.smartorrent.com/?page=torrentinfo&tid="+ui.item.value;
        }
    });
    
    // Panneau d'administration
    $("strong.adminpanel").click(function () {
        $("#modcp").toggleClass("invisible");
    });

    // Bouton de commentaires
    $("#post_comment .submit").click(function(){
        $("#comjs").css("display","none");
    });  

});

