(function( $ ){

  $.fn.tabber = function() {
  var $tabber = $(this).selector;
 
    jQuery($tabber).find('.tabcontent > div').hide();
    jQuery($tabber).find('.tabcontent > div:first').show();
    jQuery($tabber).find('.tabcontent').css({'height':jQuery($tabber).find('.tabcontent > div:first').outerHeight()});
    jQuery($tabber).find('.tabs > li:first').addClass('active');

    jQuery($tabber).find('.tabs > li a').click(function(){
      var current = $(this).attr('href');

      jQuery($tabber).find('.tabs > li').removeClass('active');
      $(this).parent().addClass('active');

      jQuery($tabber).find('.tabcontent > div:visible').fadeOut("fast", function(){
        $(current).fadeIn("fast");
        jQuery($tabber).find('.tabcontent').css({'height':$(current).outerHeight()});
      });

      return false;
    });

  }

})( jQuery );

$(document).ready(function(){


/*  $('#floater').StickySidebar(); */


// Sticky Sidebar
  var $window = $(window);
  var $section = $('#section');
  var $floater = $('#floater');
    
  var $sectionBase = $section.height() + $section.position().top - 36;

  $window.scroll(function() {
      if($floater.height() > $window.height()) {
          $floater.removeClass().addClass('fixedTop')
      }
      else if($sectionBase < ($window.scrollTop() + $floater.height()) ){
          $floater.removeClass().addClass('fixedBottom')
      }
      else if($window.scrollTop() > ($section.offset().top)){
        $floater.removeClass().addClass('float')
      }
      else if($window.scrollTop() < ($section.offset().top)){
        $floater.removeClass().addClass('fixedTop')
      }
  });

//Share
    $('#share').show();
    $('#share>a').click(function(event){
        $('html').click(function() {
            $('#share>a').removeClass().siblings('ul').hide();
        });    
        $(this).toggleClass('active').siblings('ul').toggle();
        event.stopPropagation();
        return false;
    });


// Tabber
  $('.tabber').tabber();


// ColorBox Resource Links
$('a.resource').click(function(event){

    event.preventDefault();

    $.colorbox({
		transition: 'fade',
		initialWidth: 60,
		initialHeight: 10,
		opacity: 0.5,
		title: $(this).attr('title'),
		href: $(this).attr('href')+' div#resourceForm',
		onLoad: function(){ $('#cboxClose').hide(); },
		onComplete: function(){ $('#cboxClose').show(); }
    });
});


// Vertical Tabber
	$(".vtab > .vcontent > div").hide();
	$(".vtab > .vcontent > div:first").show();
	$(".vtab > .vcontent").css({"height":$(".vtab > .vcontent > div:first").outerHeight()});
	$(".vtab > .vtabber > li:first").addClass("active");

	$(".vtab > .vtabber > li a").click(function(){
		var current = $(this).attr("href");

		$('.vtab > .vtabber > li').removeClass("active");
		$(this).parent().addClass("active");

		$(".vtab > .vcontent > div:visible").fadeOut("fast", function(){
			$(current).fadeIn("fast");
			$(".vtab > .vcontent").animate({"height":$(current).outerHeight()});
		});

		return false;
	});

});

