$(document).ready(function() {
  $('#user_login').parent().css('border-top','1px solid #ddd');

  $("form#UserLoginForm").jqTransform();

  if($('.snippet_full_link').length != 0){
    $('.snippet_full_link').toggle(function() {
      var rel = $(this).attr('rel');
      $('div#desc_'+rel).slideDown('slow');
      $(this).text('< Hide full description');
    }, function() {
      var rel = $(this).attr('rel');
      $('div#desc_'+rel).slideUp('slow');
      $(this).text('Read full description >');
    });
  }
  
  if($('select#clippings_year').length > 0) {
    $('select#clippings_year').change(function() {
      var selected = $(this).find(':selected').val();
      var redirect_to = '';
      var current_url = document.URL;
      var last_char = current_url.charAt(current_url.length-1);
      if( selected != 'ALL') {
        if(current_url.match(/year:/)) {
          redirect_to = current_url.replace(/year:([0-9]*)/, 'year:'+selected);
        }else {
          redirect_to = current_url;
          if(last_char == '/') {
            redirect_to = redirect_to+'year:'+selected;
          }else {
            redirect_to = redirect_to+'/year:'+selected;
          }
        }
      }else {
        redirect_to = current_url.replace(/year:([0-9]*)/, '');
      }
      window.location = redirect_to;
    });
  }
  $('a.video-embed').click(function() {
    var href = $(this).attr('href');
    var video_content = $(href).html();
    $.fancybox({
  			'overlayOpacity': 0.8,
  			'autoScale'		: false,
  			'transitionIn'	: 'none',
  			'transitionOut'	: 'none',
  			'title'			: this.title,
  			'width'		: 680,
  			'height'		: 495,
  			'type' : 'inline',
  			'href' : href,
  			onClosed: function() { $("#fancy_content").empty(); $(href).html(video_content);}
  		});
    return false;
  });
  $('a.embed').fancybox({
  			'overlayOpacity': 0.8,
  			'autoScale'		: false,
  			'transitionIn'	: 'none',
  			'transitionOut'	: 'none',
  			'type' : 'iframe'
  });
});

