// Init ticketing system
$(function() {  
  Tickets.initSearch();
  var $no_ticket_message = $('.GC_vip_no_ticket').hide();
  $('form').submit(function(e) {
   var self    = $(this),
     message = self.find(".GC_vip_no_ticket");
   if(self.hasClass('no_ticket')) {
     e.preventDefault();
     message.show();
   }
   self.find('.confirm').click(function(e){
     e.preventDefault();
     message.fadeOut(function(){
       self.unbind('submit');
       self.submit();
     });
   });
  });
  
  // Fancy Effects For Event Details
  $('input[type="radio"]')
    .each(function() {
      var $line = $(this).closest('li');
      
      this.checked ? $line.addClass('checked') : $line.removeClass('checked');
    })
    .live('change', function() {
      // Add class of checked to container li remove class from li siblings.
      $(this).parents('li').addClass("checked")
             .siblings().removeClass("checked");
  });
  
  // Options
  $('select[name="option"]')
    .bind('change', function(e){
      var $this = $(this),
        $option = $('option:selected', $this),
        $form = $this.closest('form'),
      
        sku = $(this).val(),
        currency = $form.find('option:selected').attr('data-currency'),
        price = $form.find('option:selected').attr('data-price'),
        qty = $form.find('option:selected').attr('data-quantity');
    
      console.log($this);
    
      $('.price', $form).html(currency!=='POINTS'?('$'+price):(price+' pts'));
      $('#sku', $form).val(sku);
    
      if(!isNaN(qty) && parseInt(qty, 10) > 0) {
        $('#currency:first', $form).attr('checked', true);
        $('#currency', $form).attr('disabled', false);
        $('.sold_out', $form).hide();
        $('#seatsearch', $form).show(); // Needs its own indicator besides quantity (i.e. if variation of ticket is seated and GA)
      }
      else {
        $('#currency', $form).attr('checked', false);
        $('#currency', $form).attr('disabled', true);
        $('.sold_out', $form).show();
        $('#seatsearch', $form).hide(); // Needs its own indicator besides quantity (i.e. if variation of ticket is seated and GA)
      }
    
    })
    .trigger('change');
});
