var $j = jQuery.noConflict();
$j(document).ready(function() {	

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

