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