/*
function elementInViewport2(el) {
	
	  alert(el);
	  var top = el.offsetTop;
	  var left = el.offsetLeft;
	  var width = el.offsetWidth;
	  var height = el.offsetHeight;

	  while(el.offsetParent) {
    	el = el.offsetParent;
	    top += el.offsetTop;
	    left += el.offsetLeft;
	  }

	  return (
    	top < (window.pageYOffset + window.innerHeight) &&
	    left < (window.pageXOffset + window.innerWidth) &&
    	(top + height) > window.pageYOffset &&
	    (left + width) > window.pageXOffset
	  );
}
*/


$(document).ready(function() {	

//	$('#content > h1').width(50);

	$(window).scroll(function() {
	
	$("h1:above-the-top").each(function() {
          $('.debug').html($(this).html());	
	});
	 $("h1:in-viewport").each(function() {
//	 	alert("add");
//          $('.debug').html($(this).html());
     });
				
//	$("#sub1 h1:in-viewport").width(50);

	});


	
	/* smooth scrolling to anchors */
	$('a[href*=#]').click(function() {			
	/* href*=# finds internal nachor # links ! */


		$('a[href*=#]').removeClass('current');		 			
		$(this).addClass('current');		 
		       	
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			/* why check the url? */
		      var $target = $(this.hash);

		      $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
		      if ($target.length) {
		        	var targetOffset = $target.offset().top;
//		        	$('html,body').animate({scrollTop: targetOffset}, 500, 'swing');

		        	$('html,body').animate({scrollTop: targetOffset}, 500, 'swing', function() { 
			        	// animation complete - mark link in menu.

		        	} );
		       		return false;
		      }
		 }
	});


	

});

	
