new function(){

    $(document).ready(function(){
        $("#contact-filters ul>li>a").click(function(){
            $("ul, form",this.parentNode).slideToggle("normal");
           this.parentNode.parentNode.className = (this.parentNode.parentNode.className=="open") ? "closed":"open";
        });
       
       $("input[value='Keyword']").bind("focus",function(){
            if(this.value=="Keyword"){
                this.value="";
            }
       }); 
       
       $("#contact-filters ul.open>li").each(function(){
            var theList = this;
            $("ul li:gt(2)",this).hide();
            if($("ul li",this).length>3){
                $(this).append("<ul style='margin-top:-10px;'><li class='toggle' style='cursor:pointer;font-weight:bold;color:black'>more...</li></ul>");
                $("li.toggle:last",this).bind("click",function(){
                    $("ul:first",theList).find("li:gt(2)").slideToggle();
                    $(this).text(($(this).text()=="more...") ? "...less" : "more...");
                });
            };
       });
       
       var results = $(".aircraft.contact-search-result"); 
       if(results.length>1){
           $("div.result-count").html("Search returned <strong>"+results.length+"</strong> total results")
           .css({"text-align":"right"});
           
           var linkcss = {"text-decoration":"underline","font-weight":"normal"};
           var linkcssLive = {"text-decoration":"none","font-weight":"bold"};
           
           if(results.length>5){
                $("div.result-count").append(" (<a href='#'>Show all</a>)")
                .find("a:last").bind("click",function(){
                    var me = this;
                    if($(".aircraft.contact-search-result:hidden").length>0){
                        $(".aircraft.contact-search-result").fadeIn();
                        $(me).text("Paginate");
                        $("div.paginate").hide();
                    }else{
                        wrapSelect(0,1)();
                        $(me).text("Show all");
                        $("div.paginate").show();
                    }
                });
                
                function wrapSelect(x,y){
                    return function(){
                         //results.fadeOut();
                         $(".aircraft.contact-search-result:eq("+x+")").fadeIn();
                         $(".aircraft.contact-search-result:gt("+x+")").fadeIn();
                         $(".aircraft.contact-search-result:gt("+(x+4)+")").fadeOut();
                         $(".aircraft.contact-search-result:lt("+(x)+")").fadeOut();
                         $("div.paginate a").css(linkcss);
                         $("div.paginate").find("a:eq("+(y-1)+")").css(linkcssLive);
                    }
                };
                $(".aircraft.contact-search-result:gt(4)").hide();
                $("div.paginate").css({"text-align":"right"})
                .each(function(){
                    var y = 0;
                    for(var x=0; x<results.length; x+=5){
                        y++;
                        var a = document.createElement("a");
                        a.appendChild(document.createTextNode(y));
                        with(a.style){
                            marginLeft="5px";
                            marginRight="5px";
                        }
                        a.href = "#";
                        this.appendChild(a);
                        $(a).bind("click",wrapSelect(x,y));
                        if(x==0){
                            $(a).css(linkcssLive);
                        }
                    }
                });
           }
       }else{
            var vlink = $(".aircraft.contact-search-result a.view");
            /*
            if(vlink.length==1){
                document.location.replace(vlink.get(0).href);
            }
            */
       }
    });
    
};
