$(function() {
  
  $('#comment-form form').each(function() {
    
    var form = this;
    
    // $(form).validate();
    
    $(this).ajaxForm({
      beforeSubmit: function() {
        $('#comments-error').hide();
      },
      success: function() {
        $('#comments-thanks').show();
        $('#comment-form').hide();
      },
      error: function(request, status, error) {
        $('#comments-error').show();
      }
    });
    
    $('a.submit', this).click(function(e) {
      e.preventDefault();
      $(form).submit();
    });
  })
  
	$('.entry-content blockquote').before("<div class=\"bq-top\"></div>"); 
	$('.entry-content blockquote').after("<div class=\"bq-bottom\"></div>");
  $('.entry-content blockquote').find("p:last").css('margin-bottom', '0px'); 
	$('.entry-content .pagination a').each(function() {this.href = this.href + "&skip_cache=true"});
	
  $('#made-by').pngFix();
	
	$('#tabs ul.tabs').tabs();
	
	$('#subnav > li').wrapInner("<span><\/span>");

	$('#subnav > li > span').each(function(){ 
		$(this).addClass($(this).parent().attr("class"));
	});
	
	$("#subnav").find("li").hover(
		function() {
			$(this).addClass("sfhover");
		},
		function() {
			$(this).removeClass("sfhover");
	});
	
	$("#global-navigation").find("li").hover(
		function() {
			$(this).addClass("sfhover");
		},
		function() {
			$(this).removeClass("sfhover");
	});

	$('.ui-tabs-panel').each(function(i){
	  $(this).before("<h2 class='print_tab_header'>" + $("a[@href=#tab-" + $(this).attr("id").slice(4,$(this).attr("id").length) + "]").text() + "<//h2>");
	});
	
	$('#participants-table tr:odd').addClass('alt');
	
	$('#participants-table a').click(function(e) {
	  e.preventDefault();
    $('#participants-overview').load('/credit_unions/participants/' + $(this).attr('href').split('#')[1]).show();
	  $("#participants-map").hide();
	});
	
	$('#leagues-table a').click(function(e) {
	  e.preventDefault();
    $('#participants-overview').load('/leagues/' + $(this).attr('href').split('#')[1]).show();
	  $("#participants-map").hide();
	});
	
	$('#categories li p').truncate({
	  max_length: 105,
	  more: '...',
	  expandable: false});
	 
	
	  $('#vote-page .video-wrapper').livequery(function() {
      $(this).hover(function() {
        $(this).addClass('hover');
      }, function() {
        $(this).removeClass('hover');
      });
    });

    $('#vote-options').column_list();

    $('#vote-page .video').each(function(index, link) {

      link = $(link);

    	var video_id = jQuery.uri.setUri($(link).attr('href')).param("v");

      link.html('<img src="http://i2.ytimg.com/vi/' + video_id + '/default.jpg" />');

      var trigger = link.siblings('.trigger');

      var href = trigger.attr('href') + "?height=375&width=762";

      link.attr('href', href);
      trigger.attr('href', href);

      tb_init(link);
      tb_init(trigger);

    });

    $('#vote-page .description label').hover(function() {
      $(this).siblings('input').hover();
    });
  
});