$(document).ready(function() {	

	//Get the height of the first item
	$('#mask2').css({'height':$('#section-1').height()});	
	
	//Calculate the total width - sum of all sub-sections width
	//Width is generated according to the width of #mask * total of sub-sections
	$('#section').width(parseInt($('#mask2').width() * $('#section div').length));
	
	//Set the sub-section width according to the #mask width (width of #mask and sub-section must be same)
	$('#section div').width($('#mask2').width());
	
	//Get all the links with rel as section
	$('a[rel=section]').click(function () {
	
		//Get the height of the sub-section
		var sectionheight = $($(this).attr('href')).height();
		
		//Set class for the selected item
		$('a[rel=section]').removeClass('selected2');
		$(this).addClass('selected2');
		
		//Resize the height
		$('#mask2').animate({'height':sectionheight},{queue:false, duration:500});			
		
		//Scroll to the correct section, the section id is grabbed from the href attribute of the anchor
		$('#mask2').scrollTo($(this).attr('href'), 800);		
		
		//Discard the link default behavior
		return false;
	});
	
});