jQuery(function($) {

  swfobject.embedSWF("/globe/bin-release/app.swf", "swf", "960", "265", "9.0.0", null, {}, {wmode: 'transparent'});  

  $('a[rel*=lightbox]').lightBox({
    imageLoading: '/carmela-themes/tecnofreight.net/js/jquery-lightbox-0.5/images/lightbox-ico-loading.gif',
    imageBtnClose: '/carmela-themes/tecnofreight.net/js/jquery-lightbox-0.5/images/lightbox-btn-close.gif',
    imageBtnPrev: '/carmela-themes/tecnofreight.net/js/jquery-lightbox-0.5/images/lightbox-btn-prev.gif',
    imageBtnNext: '/carmela-themes/tecnofreight.net/js/jquery-lightbox-0.5/images/lightbox-btn-next.gif',
    imageBlank: '/carmela-themes/tecnofreight.net/js/jquery-lightbox-0.5/images/lightbox-blank.gif' 
  });

  $('form.quote input[name="ok"]').change(function() {
    $('form.quote .success').attr('disabled', !this.checked)
  })

  $('form.quote').submit(function() {
    var form = $(this);
    $(this).find('has-error').removeClass('has-error');
    $.post($(this).attr('action'), $(this).serialize(), function(r) {
      $('.actions .form-errors, .actions .form-success').remove();
      $('.actions').prepend(r);
      $('.form-errors li').each(function() {
        $(this).css({cursor: 'pointer'});
        var f = $(this).attr('data-field');
        var selector = 'input[name="' + f + '"], textarea[name="' + f + '"]';
        form.find(selector).addClass('has-error');
        $(this).click(function() {
          form.find(selector).focus();
        });
      });
    });
    return false;
  });

  $('.home-box .description').click(function() {
    var box = $(this).parent('.home-box');
    var headers = box.find('h1 a, h2 a, h3 a, h4 a, h5 a, h6 a');
    if (headers.length == 0) {
      return;
    }
    location.href = headers.first().attr('href');
    return false;
  });

  $('html.home .news').click(function(e) {
    if ($(e.target).is('a')) {
      return;
    }

    location.href = $(this).find('a').attr('href');
  })

})

