$(function() {
  $(".content_nav li a, .iban_thumbs .thumb a").hover(function() { $(this).trigger("click"); }, function() {});

  $("a[rel$=external]").click(function() {
    this.target = "_blank";
  });

  if($("a[rel$=fbox]").length) {
    $("a[rel$=fbox]").fancybox({
      'transitionIn'  : 'elastic',
      'transitionOut' : 'elastic',
      'speedIn'       : 500,
      'speedOut'      : 500,
      'overlayShow'   : true,
      'titlePosition' : 'over',
      'hideOnContentClick': true,
      'centerOnScroll': true,
      'onComplete'    : function() {
        $("#fancybox-wrap").hover(function() {
          $("#fancybox-title").fadeIn();
        }, function() {
          $("#fancybox-title").fadeOut();
        });
      }
    });
  }

  if($('.ln_title').length) {
    $('.ln_title').toggle(
      function(){
        $(this).addClass('on');
        $(this).next().slideDown();
      },
      function(){
        $(this).removeClass('on');
        $(this).next().slideUp();
      }
    );
  }

  if($(".ibanner").not("[class~='noCarousel']").length) {
    $(".ibanner").not("[class~='noCarousel']").jCarouselLite({
      btnGo: ['#s1','#s2','#s3','#s4','#s5'],
      speed: 500,
      //speed: 0,
      scroll: 1,
      visible:1,
      auto:11000,
      vertical: true,
      easing: 'easeInOutQuart',
      circular: true,
      btnNext: "#iban_thumbs_next",
      btnPrev: "#iban_thumbs_prev",
      /*beforeStart: function(a) {
        $(a).parent().fadeTo(400, 0.5);
        var bg = $(a).find('.iban_img img').attr('src');
        $('.iban_img').parent().css({
          backgroundImage: "url("+bg+")"
        }, 100);
      },*/
      afterEnd: function(a) {
        var order;
        order = $('.ibanner li').index( a );
        //alert(order);
        if(order==6) order =1;
        $('#s1,#s2,#s3,#s4,#s5').removeClass('on');
        $('#s' + order).addClass('on');
        //$(a).parent().fadeTo(400, 1);
      }
    });
  }

  if($(".tweet").length) {
    var un = $(".tweet").attr('rel');
    $(".tweet").tweet({
      username: [un],
      join_text: "auto",
      count: 1,
      auto_join_text_default: "we said,",
      auto_join_text_ed: "we",
      auto_join_text_ing: "we were",
      auto_join_text_reply: "we replied to",
      auto_join_text_url: "we were checking out",
      loading_text: "loading tweets..."
    });
    $("#twitter-link").attr('href', 'http://www.twitter.com/' + un);
  }

  $(".newsletter_form").attr("target", "_blank");

  $("#announcement a.close").live("click", function(e) {
    e.preventDefault();
    $("#announcement").animate({
      height: 0,
      opacity: 0,
      margin: 0
    }, 1000, function() { $("#announcement").remove(); });
  });

  if($('.chamber_event_box').length) {
    var maxHeight = 0;
    $('.chamber_event_box').each(function() { maxHeight = Math.max(maxHeight, $(this).height()); }).height(maxHeight);
  }
  /*
  $(".newsletter_form").submit(function() {
    var self  = $(this);
    var email = $(this).find("input[name=email]").val();
    if(email != 'Enter email address') {
      $.post("newsletter.php", $(this).serialize(), function(data) {
        if(!data.error) {
          self.hide().html('<span>'+data.message+'</span>').fadeIn('slow');
        } else {
          alert(data.message);
          self.find("input[name=email]").val('').focus();
        }
      });
    } else {
      alert('Please enter your email address');
      $(this).find("input[name=email]").val('').focus();
    }
    return false;
  }, "json");
  */

  /*
  if($(".single_ln2 ul li a").length) {
    $(".single_ln2 ul li a").colorbox({
      "width": "80%",
      "height": "80%",
      "iframe": true
    });
  }
  */
});
