OVERLAY = {
  expose: { 
      color: '#333', 
      loadSpeed: 200, 
      opacity: 0.9 
  },
  closeOnClick: false
}

VIMEO = {
  src: "http://vimeo.com/moogaloop.swf",
  wmode: 'opaque'
}


$(document).ready(function() {
  
  $('.slider').each(function() {
    var slider = this
    $('.tabs', slider).after("<div class='tab-arrow'></div>");
    
    $('.tabs', slider).tabs("> .panes > .pane", {
      onClick: function(event, tabIndex) {
        var tb = $(".tab:eq("+tabIndex+")", slider)
        if (tb.offset() != null) {
          var mid = tb.offset().left + 13;
          $(".tab-arrow", slider).css('left', mid);
        }
        
        var pn = $(".pane:eq("+tabIndex+")", slider)
        var jwplayer = $('.jwplayer', pn)
        var astream = $(".astream", pn).text()
        var thumbnail = $('.thumbnail', pn).text()

		var vimeoplayer = $('.vimeoplayer', pn)
		var vimeoid = $('.vimeoid', pn).text()
		
		if (vimeoplayer && vimeoid) {
			console.log("embeding" + vimeoplayer + ' ' + vimeoid)
			vimeoplayer.flashembed(VIMEO, {clip_id: vimeoid})
		}
		
        
        if (jwplayer && astream && thumbnail) {
          
          $('.jwplayer').not(jwplayer).empty();
          
          jwplayer.flashembed(
              {
                src: "/claf2/js/lib/mediaplayer-licensed-viral/player-licensed-viral.swf",
                wmode: 'opaque'
              }, 
              {
                streamer: 'rtmp://flash.Astream.net/TFA/video/',
                file: astream,
                image: thumbnail,
                autostart: 'false',
                backcolor: '0x003F5F',
                frontcolor: '0xffffff',
                lightcolor: '0xffffff'
              }
            );
        }
        
      },
      onBeforeClick: function(event, tabIndex) {
      }
    });
    
  });
  
  $('.showmore').click(function() {
    var showmore = $(this)
    showmore.siblings(".more").toggle();
    if (showmore.hasClass('open')) {
      showmore.removeClass('open')
      showmore.addClass('closed')
    }
    else {
      showmore.removeClass('closed')
      showmore.addClass('open')
    }
  })
  
  $('.cat-filter').change($.cat_state_filter);
  $('.state-filter').change($.cat_state_filter);

  
  // make sure last p in cab doesn't have any padding
  $(".cabbody > p:last-child").addClass('no-spacing')
  $(".cabbody > ul:last-child").css("margin-bottom", "0")
  
  
  
  
  $('.launch-vimeo').colorbox({
    html: "<div id='vimeo-player'>Vimeo Player</div>",
    onComplete: function() {
      var clip = $(this).attr('rel')
      $("#vimeo-player").flashembed(VIMEO, {clip_id: clip, autoplay: 1});
    }
  })
  
  $('.call_overlay').colorbox({iframe: true, innerWidth:500, innerHeight:500})
  
});







$.cat_state_filter = function() {
  var cat_id = $('.cat-filter').val()
  var state_id = $('.state-filter').val()
  
  console.log("cat_id " + cat_id)
  console.log("state_id " + state_id)
  
  if (cat_id == "false") {
    $(".cat").show()
  }
  if (state_id == 'false') {
    $('.state').show();
  }
  
  var show_string = ""
  
  if (cat_id != undefined && cat_id != 'false'){
    $('.cat').hide();
    show_string += '.cat-' + cat_id;
  }
  
  if (state_id != undefined && state_id != 'false') {
    $('.state').hide();
    
    
    if (document.location.pathname.indexOf('discounts-for-educators') > -1) {
      show_string = show_string + '.state-' + state_id + "," + show_string + '.state-all'
    }
    else {
      show_string += '.state-' + state_id;
    }
  }
  
  console.log(show_string)
  
  $(show_string).show()
  $.zebratable();
}





if(!window.console) {
  window.console = new function() {
    this.log = function(str) {};
    this.dir = function(str) {};
  };
}

