$(document).ready( function(){
   // show logon popup
   $("a#logon").fancybox({
      'frameHeight': 270,
      'frameWidth': 314,
      'hideOnContentClick': false,
      'callbackOnShow': function() {
         // init submit button
         $("form.logon").submit( function( event ) {
            $("input.btn").attr('disabled', 'disabled');
            $("img.loader").attr('src', '/i/loader.gif');
            $.post( 
               '/logon.php', 
               { 'login': $("input.field-login").val(), 'password': $("input.field-password").val() } ,
               function( data ) {
                  $("input.btn").attr('disabled', '');
                  switch( data.code ) {
                     case 'EMPTY_PASSWORD':
                        $("img.loader").attr('src', '/i/p.gif');
                        $('#pswd-error').html('Введите пароль!');
                        break;
                        
                     case 'EMPTY_LOGIN':
                        $("img.loader").attr('src', '/i/p.gif');
                        $('#login-error').html('Введите логин!')
                        break;
                        
                     case 'SUCCESS':
                        location.reload();
                        
                  } // switch

               },
               'json'
            );
            
            return false;
            
         }); // submit

      } // 'callbackOnShow'
      
   }); // fancybox


   $("a#reg").fancybox({
      'frameHeight': 270,
      'frameWidth': 314,
      'hideOnContentClick': false
   }); // fancybox


   $("a#prices").fancybox({
      'frameHeight': 600,
      'frameWidth': 550,
      'hideOnContentClick': false
   }); // fancybox


   $("a#logout").click( function( event ) {
      $.post( 
         '/logout.php', 
         {} ,
         function( data ) {
            switch( data.code ) {
               case 'SUCCESS':
                  location.reload();
                  
            } // switch

         },
         'json'
      ); 
      return false; 
   });

   $('.srch-exmp').click( function( event ) { 
      $('#q').val( $(this).html() ); 
   });
   
   $('a.dir-name').click( function() {
      $('div.num').removeClass( 'sel' );
      
      if( $(this).parent().hasClass('active') ) {
         $(this).parent().removeClass( 'active' );
      } else {
         $('div.dir').removeClass( 'active' );
         $('div.' + $(this).attr('id')).addClass( 'sel' );
         $(this).parent().addClass('active');
      } // if
      return false;
      
   });
   
});


