$(document).ready(function() {
  (function() {
    //settings
    var fadeSpeed = 200, fadeTo = 0.6, topDistance = 10;
    var topbarME = function() { $('#titlebar').fadeTo(fadeSpeed,1); }, topbarML = function() { $('#titlebar').fadeTo(fadeSpeed,fadeTo); };
    var inside = false;
    //do
    $(window).scroll(function() {
      position = $(window).scrollTop();
      if(position > topDistance && !inside) {
        //add events
        topbarML();
        $('#titlebar').bind('mouseenter',topbarME);
        $('#titlebar').bind('mouseleave',topbarML);
        inside = true;
      }
      else if (position < topDistance){
        topbarME();
        $('#titlebar').unbind('mouseenter',topbarME);
        $('#titlebar').unbind('mouseleave',topbarML);
        inside = false;
      }
    });
  })();

	// Social +Button
	var open = false;
	$("#showSocial").click(function() {
		if (open === false)
		{
			open = true;
			$(this).addClass("open");
			$("#shareButtons ul").slideDown("fast");
		}
		else
		{
			open = false;
			$(this).removeClass("open");
			$("#shareButtons ul").slideUp("fast");
		}
	});	

});

