   
jQuery.noConflict();

/*
jQuery(document).ready(function($) {
   $('.bid_button, #form_place_bid').click(function() {
      var auction_id = $(this).closest('table').find('[name=auction_id]').val();
      var quantity = 1;			

      $.post(
         'ajax_files/place_bid.php', 
         {
            auction_id: auction_id,
            quantity: quantity
         },
         function(data) {
            $('.current_bid_' + auction_id).html(data.max_bid);	
            $('.your_bid_' + auction_id).html(data.your_bid);	
            $('.nb_bids_' + auction_id).html(data.nb_bids);	
            $('.next_bid_' + auctionId).html(data.next_bid);					
					
            alert(data.display);
					
         }, 
         'json'
      );		

   });   
});
*/

function highlightLast5(periods) {
   if (jQuery.countdown.periodsToSeconds(periods) < 60) {
      jQuery(this).css('color', '#f00');
   }
   else
   {
      jQuery(this).css('color', '#000');
   }
}
	
function calcEndTime(counter)
{
   jQuery.ajax({
      url: "ajax_files/refresh_countdown.php",
      data: ({
         auction_ids: jQuery('#auctionIds').val()
      }),
      dataType: 'json', 
      async: true, 
      timeout: 3000, 			
      success: function(data)
      {				
         if (data)
         {
            jQuery.each(data, function(i, row) {
               auctionId = row['auction_id'];						
				
               if (counter == 0 || row['update_time'] == 'true')
               {
                  jQuery('.time_left_' + auctionId).countdown('destroy');
                  jQuery('.time_left_' + auctionId).countdown({
                     until: row['response'],
                     serverSync: serverTime, 
                     expiryText: '<span class="redfont">Closed</span>', 
                     onTick: highlightLast5, 
                     layout:'{d<}{dn} {dl},{d>} ' + '{hn}h {mn}m {sn}s'
                  });
               }
						
               jQuery('.current_bid_' + auctionId).html(row['bidder_username']);	
               jQuery('.nb_bids_' + auctionId).html(row['nb_bids']);		
									
               jQuery('.your_bid_' + auctionId).html(row['your_bid']);					
               jQuery('.next_bid_' + auctionId).html(row['next_bid']);					
               jQuery('.status_' + auctionId).html(row['status']);					
               jQuery('.end_time_' + auctionId).html(row['end_time']);							
               jQuery('.high_bid_' + auctionId).html(row['high_bidders']);					
               jQuery('.winner_' + auctionId).html(row['winners']);					
												
            });
					
            counter ++;					
         }				
      }
   });
		
   setTimeout(function() {
      calcEndTime(counter)
      }, 5000);		
}	

function serverTime() 
{
   var time = null;
			
   jQuery.ajax({
      url: 'ajax_files/server_time.php',
      async: false, 
      dataType: 'text',
      success: function(text) 
      {
         time = new Date(text);
      }, 
      error: function(http, message, exc) 
      {
         time = new Date();
      }
   });
   return time;
}   
