/* Functions */

function init_sidescroll_gallery() {
  $('#sidescroll_gallery').css('overflow','hidden')
    .serialScroll({
    items: 'li',    
    start: 0,
    duration: 500,
    force: true,
    //offset: -100,
    //easing:'easeOutQuart',
    //interval: 4000,
    //

    onBefore:function(e, elem, $pane, $items, pos){
      // probably should handle audio too
      //$('#sidescroll_gallery .video').hide();
    },

    onAfter:function(elem) {
    }

  });

  $('.sidescroll_next').click(function() {
      $('#sidescroll_gallery').trigger('next');
      return false;
  });

  $('.sidescroll_prev').click(function() {
      $('#sidescroll_gallery').trigger('prev');
      return false;
  });

}

function setup_media_form(el) {
  var selects = $('select', el)
  selects.change(function() {
    $('#id_embed_code', el).parents('p').hide();
    $('#id_file', el).parents('p').hide();
    $('#id_link', el).parents('p').hide();
    if ($(this).val() == 'video') {
      $('#id_embed_code', el).parents('p').show();
    } 
    
    if ($(this).val() == 'image' || $(this).val() == 'audio') {
      $('#id_file', el).parents('p').show();
    } 

    if ($(this).val() == 'link') {
      $('#id_link', el).parents('p').show();
    } 
  });

  selects.change();
}

/* Document Ready */

$(document).ready(function() {
  var banner = $('#banner');
  var start_height = banner.css('height');
  banner.mouseout(function() {
    banner.stop()
    .addClass('off')
    .animate({'height':start_height}, 800);
  });
  banner.mouseover(function() {
    banner.stop()
    .removeClass('off');
    setTimeout(function() {
      if (!banner.hasClass('off')) {
        banner.animate({'height':'180px'}, 1000);
      }
    }, 400);
  });

  jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
    return -c * ((t=t/d-1)*t*t*t - 1) + b;
  };

  if ($.browser && $.browser.msie === true) {
    if ($('#sidescroll_gallery').length) {
      $('#sidescroll_gallery').attr('id', '').addClass('vertical_gallery');
      $('#controls').remove();
      $('.sidescroll_next').unbind('click');
      $('.sidescroll_prev').unbind('click');
      $('#page_content')
        .append('<br/><h5 class="pink">(This website feature looks best with Firefox or Safari)</h5>');
    }
  } else {
    init_sidescroll_gallery();
  }

  //Make all external links open in a new window
  $("a[href^='http://']").each(function() {
      if ($(this).attr('href').indexOf(window.location.host) < 0) {
        $(this).attr('target', '_blank');
      }
  });

  setup_media_form('#notes #new_note form');
});
