(function( $ ){

  $.fn.tabber = function() {
  var $tabber = $(this).selector;

    var hash = window.location.hash;
    var hrefs = new Array();
    var first = ':first';

    jQuery($tabber).find('.tabs li').each(function(){
      hrefs.push($(this).find('a').attr('href'));
    })

    if(hash) {
      jQuery.each(hrefs, function() {
        if (this == hash) {
          first = hash;
          setTimeout(function() {
              window.scrollTo(0, 0);
          }, 1);
          return false;
        }
      });

      if (first == hash) {
        jQuery($tabber).find('.tabs > li > a[href="'+first+'"]').parent('li').addClass('active');
      } else {
        jQuery($tabber).find('.tabs > li:first').addClass('active');
      }
    } else {
        jQuery($tabber).find('.tabs > li:first').addClass('active');
    }
 
    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 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()});
      });

      location.hash = $(this).attr('href');
      return false;
    });

  }

})( jQuery );

$(document).ready(function(){

/*$('#floater').stickyfloat({duration: 500, delay: 200, parent: '#section'});*/

// Sticky Sidebar
  var $window = $(window);
  var winHeight = $window.height();
  var $section = $('#section');
  var $floater = $('#floater');
  var floatHeight = $floater.height() + parseInt($floater.css('padding-bottom'));
  var sectionBase = $section.height() + $section.position().top;

  // Set Floater Class
  function floaterClass() {
      if(floatHeight > winHeight) {
          $floater.removeClass().addClass('fixedTop')
      }
      else if(sectionBase < ($window.scrollTop() + floatHeight) ){
          $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')
      }
  }

  $window.scroll(function() {
      floaterClass();
  });

  $window.resize(function() {
      winHeight = $window.height();
      floaterClass();
  });


//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;
	});

});

