jQuery(function($) {

// =========================== REGISTRATION ===========================
if($('body').hasClass('page-id-142') || $('body').hasClass('page-id-514')) {

  var total     = $('.gfield.payment-total input').before('$').attr("readonly", true),
      deposit   = $('.gfield.payment-deposit input').before('$').attr("readonly", true),
      remainder = $('.gfield.payment-remainder input').before('$').attr("readonly", true);

  var exhibitorType = $('.gfield.exhibitorType select');

  function updatePrices() {
    var sum = 0;

    $('.gfield.booth').each(function() {
      var self = $(this),
          input = self.find('input'),
          quantity = parseInt(input.val(), 10) || 0,
          price = self.find('label').text().match(/\$(.*)/)[1];

      price = parseFloat(price.replace(',', ''));

      //if the value is non-numeric, make it 0
      if(quantity != input.val()) input.val('0');

      sum += quantity * price;
    });
    
    var depositFraction = exhibitorType.val() == "[SOLO] Studio" ? 0.5 : 0.3;

    total.val(sum.toFixed(2));
    deposit.val((sum * depositFraction).toFixed(2));
    remainder.val((sum - deposit.val()).toFixed(2));
  }

  $('.gfield.booth input').keyup(updatePrices);
  $('.gfield.booth input').change(updatePrices);
  updatePrices();

  //reset booth quantities to 0 when exhibitor type is changed
  $('.gfield.exhibitorType select').change(function() {
    $('.gfield.booth input').val('0');
    updatePrices();
  });

// =========================== PRESS & LOGOS ===========================
} else if($('body').hasClass('page-id-23')) {
  
  $('body').append('<div id="banner-dialog" style="display:none"><textarea rows="4" cols="61"></textarea><br /><br /><h2>Preview:</h2><div id="banner-preview"></div></div>');
  
  $('#logos img').addClass('clickable').click(function() {
    var img = $('<div>').append($(this).clone().removeAttr('class')).html();
    var html = '<a href="http://artexponewyork.com/">' + img + '</a>';
    
    $('#banner-preview').html(img);
    $('#banner-dialog textarea').text(html);
    tb_show("Use this HTML code to add the banner to your website:", "#TB_inline?height="+(140+$(this).height())+"&width=500&inlineId=banner-dialog", false);
  });
}

// =========================== TRANSLATION ===========================
if(window.location.href.indexOf("translate.google.com") == -1) {
  $('#headerLinks ul').before("<div id='translateLinks'><a href='javascript:;' class='fakeLink'>Translate this Page</a> <ul></ul></div>");
  var container = $('#translateLinks ul');
  var languages = {"ar": "Arabic", "zh-CN": "Chinese (Simplified)", "zh-TW": "Chinese (Traditional)", "fr": "French", "de": "German", "hi": "Hindi", "it": "Italian", "ja": "Japanese", "ko": "Korean", "pt": "Portuguese", "ru": "Russian", "es": "Spanish"};

  for(var code in languages) {
    var language = languages[code];
    var url = encodeURIComponent(window.location.href);
    url = "http://translate.google.com/translate?sl=en&hl="+code+"&tl="+code+"&u=" + url;
  
    container.append("<li><a href='"+url+"'>"+language+"</a>");
  }

  if ($.browser.msie && $.browser.version < 7) {
    $("#translateLinks").hover(function(){
      $(this).addClass("hover");
    },function(){
      $(this).removeClass("hover");
    });
  }
}

});