Narrative = {};

Narrative.Common = (function(){
  return{
    addQuotes: function(){
        /* Quotes Animation */
      var quotesDiv = $("#quotes");
      var topquoteDiv = $("#topquote");
      var mainDiv = $("#main");
      var windowObj = $(window);
      // calculate "top" css attribute (depends on quotes size and size of top quote div)
      var topLoc = Math.floor( parseInt(topquoteDiv.css("paddingTop"), 10) + topquoteDiv.height() / 2 ) - ( quotesDiv.height() / 2 );
      quotesDiv.css("top", topLoc);
      var startScroll = topquoteDiv.height() / 2; // where to start 'animating' the scroll
      var headerHeight = $("#header").height(); // since we're positioning from #top of main, need this to calculate offset from window
      $(window).scroll(function() {
          var maxTop; // maximum "top" css position -- measured from top of div#main	
          if (windowObj.scrollTop() > startScroll) {
            maxTop = mainDiv.height() - quotesDiv.height() - 40; // last int is additional margin
            animateTo = Math.floor((windowObj.height() / 2) - (quotesDiv.height() / 2) - headerHeight + windowObj.scrollTop());
            if (animateTo > maxTop) animateTo = maxTop;
            quotesDiv.stop().animate(
              {top: animateTo},
              2500,
              "easeInOutSine",
              function() {
                // callback
                // nothing here...
            });
          } else if ($(window).scrollTop() <= startScroll) {
            // back to original position
            quotesDiv.stop().animate(
              {top: topLoc + 'px'},
              2500,
              "easeInOutSine",
              function() {
                // callback
                // nothing here...
            });
          }
      });
    }
  };
}());
$(document).ready(function() {
	
	/* Cufon font replacement */
	Cufon.replace("#topquote", {fontFamily: "Helvetica Neue 85 Heavy"});
	Cufon.replace("#content h2", {fontFamily: "Helvetica Neue 85 Heavy"});
	Cufon.replace("#content h3", {fontFamily: "Helvetica Neue Bold"});
	Cufon.replace("#content h4, #sidebar h4", {fontFamily: "Helvetica Neue Bold"});
	Cufon.replace("#sidebar h2", {fontFamily: "Helvetica Neue 85 Heavy"});
	Cufon.replace("#footer h2", {fontFamily: "Helvetica Neue 85 Heavy"});
	Cufon.replace("#ourteam #topquote p, #ourteam ul li a", {fontFamily: "Helvetica Neue Bold"});
	
	
	
	

	/* Navigation Tabs Hover */
	$("ul#tabs li:not(.current)").hover(
		// over
		function () {
			$(this).addClass('hover'); 
		},
		// and out!
		function () {
			$(this).removeClass('hover');		
		}
	);
	
	/* Our Team bios "Read More" show/hide */
//	$("#ourteam .team-member-bio .more p").hide();
//	$("#ourteam .team-member-bio p").append('<a href="#">Read More</a></p>');
	
	$("#ourteam .team-member-bio").each(function(){
		var teamBioDiv = $(this);
		if (teamBioDiv.children(".more").size() > 0) {
			teamBioDiv.children(".more").hide();
			//var readMoreLink = '<a href="#" class="readmore read">Read More</a>';
			//var readLessLink = '<a href="#" class="readless read">Read Less</a>';
			//teamBioDiv.children("p:last").append(readMoreLink);
			
			teamBioDiv.find("a.readmore").live("click", function(){
				var $teamBioMore = $(this).parents("div.team-member-bio").find(".more");
				//$teamBioMore.find("p").last().append(readLessLink);
				$teamBioMore.slideDown();
				//$(this).remove();
				$(this).removeClass("readmore").addClass("readless").text("Read Less");
				return false;
			});
			teamBioDiv.find("a.readless").live("click", function(){
				teamBioDiv.children(".more").slideUp(function() {teamBioDiv.find("a.readmore").show();});
				$(this).removeClass("readless").addClass("readmore").text("Read More");
				//$(this).remove();
				//teamBioDiv.children("p:last").append(readMoreLink);
				return false;
			});
		}
	});
	
	// set input class = "clear" to always clear default text on focus
	//  set class = "clear once" to clear only the first time focused ('clear' and 'once' are two separate classes
/*
	$("#searchform input.clear").each(function() {
		// save data
		$(this).data("txt", $.trim($(this).val()))
	}).focus(function() {
		// On focus test for default saved value and if not the same clear it
		if ( $.trim($(this).val()) === $(this).data("txt") ) {
			$(this).val("");
		}
	}).blur(function(){
		// Use blur event to reset default value in field that have class clear
		// but ignore if class once is present
		if ( $.trim($(this).val()) === "" && !$(this).hasClass("once") ) {
			//Restore saved data
			$(this).val( $(this).data("txt") );
		}
	});*/


});

