$(document).ready(function(){
  $('#error_message').fadeIn("slow");
  $('#info_message').fadeIn("slow");
  $('a[rel="traffic_left"]').click(function() {
     var dblock = $('div#traffic_left_more').css('display');
      if(dblock == 'none') {
      
            $('div#traffic_left_more').fadeIn("slow");
      
      } else {
      
          $('div#traffic_left_more').fadeOut("slow");
      
      }
      return false;
   });
   
   $('input#payonline').click(function() {
    
      var package_type = $('select[name="package"]').val();
      var control = $('input[name="control"]').val();
      
      $.post(root+"pl/payment/savedetails?preventcache="+Math.random(), { package_id: package_type, payment_control_sum: control }, function(data) {
        $('input#kwota').attr('value', data.ammount_with_vat);
        $('form#PaymentSubmit').submit();
      }, 'json');
      
      return false;
   });
   
  $.each($('td.in_progress'), function(i, v)
  {
    var progress = $(this);
    var start = 0;
    
    // Start timers :-)
    $(document).everyTime(3000, 'file_'+progress.attr('fileid'), function() {
        $.ajax({
          url: root+'pl/user/ajax/status/'+progress.attr('fileid'),
          dataType: 'json',
          cache: false,
          success: function(data)
          {
            var start =  parseInt(data.procent);
            
            if(data.procent !== undefined)
            {
              $('#file_progress_'+progress.attr('fileid')).progression({ Current: parseInt(data.procent) });
            }
            if(start >= 100)
            {
              $(document).stopTime('file_'+progress.attr('fileid'));
            }
          }
        });
    });
  });
  
});
