function goToFirstTitle(){
	$.scrollTo($('div.modulebox:eq(0) h4'), {
		duration:'4',
		offset: {left: 0, top:-200 }
	});				
}


$(document).ready(function() {
    $(window).bind("scroll", function(event) {
        $("div.modulebox:in-viewport").each(function() {
          	visibleModule = $(this).attr("id");
			$("ul.subheader li a[rel='#"+ visibleModule +"']").addClass('inview');
 		});
        $("div.modulebox:below-the-fold").each(function() {
          	visibleModule = $(this).attr("id");
			$("ul.subheader li a[rel='#"+ visibleModule +"']").removeClass('inview');
 		});
        $("div.modulebox:above-the-top").each(function() {
          	visibleModule = $(this).attr("id");
			$("ul.subheader li a[rel='#"+ visibleModule +"']").removeClass('inview');
 		});
    });

    $(window).bind("resize", function(event) {
        $("div.modulebox:in-viewport").each(function() {
          	visibleModule = $(this).attr("id");
			$("ul.subheader li a[rel='#"+ visibleModule +"']").addClass('inview');
 		});
        $("div.modulebox:below-the-fold").each(function() {
          	visibleModule = $(this).attr("id");
			$("ul.subheader li a[rel='#"+ visibleModule +"']").removeClass('inview');
 		});
        $("div.modulebox:above-the-top").each(function() {
          	visibleModule = $(this).attr("id");
			$("ul.subheader li a[rel='#"+ visibleModule +"']").removeClass('inview');
 		});
    });
	

	// http://flesler.blogspot.com/2007/10/jqueryscrollto.html
	$('ul.subheader li a').click(function(e) {
		thisScrollID = $(this).attr('rel');
		$.scrollTo(thisScrollID, {
			duration:'5',
			offset: {left: 0, top:-120 }
		});
		return false;
	});

	// If the h4 of the first box is not in the viewport we will scroll the viewport to reveal it.
	var defaultscroll = true;
	var inquestion = "";

	thefirstid = $('div.modulebox:eq(0)').attr('id');

	switch(thefirstid){
	case 'module-76':
		//('using scrolling scenario for module-76');
		inquestion = $('div.modulebox:eq(0) h4:below-the-fold');		
		break;
	case 'module-73':
		//('using scrolling scenario for module-76');
		inquestion = $('div.modulebox:eq(0) h4:below-the-fold');		
		break;
	case 'module-2':
		//('using scrolling scenario for module-2');
		inquestion = $('div.modulebox:eq(1):below-the-fold');
		break;
	default:
		defaultscroll = true;
	}

	if (inquestion.length > 0) { defaultscroll = false; };
	
	if (defaultscroll != true) {
	   $('p:eq(0)').animate({opacity: 1}, 800, function() {
	   	$.scrollTo(inquestion, {
	   		duration:'5',
	   		offset: {left: 0, top:-240 }
	   	});
	})
	}

	if (defaultscroll) {
		$(window).scroll();	
	}
	

});
