$(document).ready(function(){
     var next=0;
     var limit=0;
     var wait=0;
     
     $('.tab>ul>li').click(function(){ //Переход на другую закладку
     if (wait) return false;
     curr_tab=$(this);
     tabs=$(this).parent();
     $('#search_tab'+tabs.attr("id")).remove();
        tabs.children('li').each(function(i){
           if ($(this).hasClass('active')) {
           $(this).toggleClass('active');
           }
        });
        curr_tab.toggleClass('active');
        if (next!=1) limit=0;
        tabs.parent().next().html('<div class="wait"></div>');
        wait=1;
        $.post("../showhome.php",{type:tabs.attr('id'),currtab:curr_tab.attr('id'),next:next,limit:limit},
            function (result) {
                if (result) {
                     tabs.parent().next().html(result);
                     wait=0;
                }
            }
        );
        next=0;
     return false;
     });
     
     
     
     $('#search_pp').live('click', function(){ //Поиск
        type=$(this).attr('type_');
        tabs=$(this).parent().next();
        tabs.children().children('li').each(function(i){;
        if ($(this).hasClass('active')) {
           $(this).toggleClass('active');
        }
        });
        
        if (!$('#search_tab'+type).length) {
              tabs.children().prepend('<li class="active" id="search_tab'+type+'"><a href="#"><span>Поиск</span></a></li>');
        }
        else {
              $('#search_tab'+type).toggleClass('active');
        }
        tabs.next().html('<div class="wait"></div>');
        $.post("../ajax/search_pp.php",{type:type,text:$(this).prev().val()},
        function (result) {
                if (result) {
                     tabs.next().html(result);   
                }
                else {
                     $('#search_tab'+type).remove();
                }
        }
        );
        return false;
     });
     
     
     $('.next').live('click',function(){
          next=1;
          limit=$(this).attr('value_');
          tabs=$(this).parent().parent().parent().parent().parent().parent().parent().find('ul').attr('id');
          $('#'+tabs).children('#'+$(this).attr('id')).click();
          return false;
     });
     
     $('div[help]').hover(
     function(){
                coords=$(this).offset();
                $('#help').fadeIn(0).offset({top: (coords.top-2),left: coords.left-2}).html($(this).attr('help'));
                
     },
     function(){
                coords=$(this).offset();
                $('#help').fadeOut(10);                
     });   
     
     
});
