$(document).ready(function(){
	/* This code is executed after the DOM has been completely loaded */
	
	var totWidth=0;
	var positions = new Array();
	
	$('#slides .slide').each(function(i){
		
		/* Traverse through all the slides and store their accumulative widths in totWidth */
		
		positions[i]= totWidth;
		totWidth += $(this).height();
		
		/* The positions array contains each slide's commulutative offset from the left part of the container */
		
		if(!$(this).height())
		{
			alert("Please, fill in width & height for all your images!");
			return false;
		}
		
	});
	
	$('#slides').height(totWidth);

	/* Change the cotnainer div's width to the exact width of all the slides combined */

	$('#jqmenu ul li a').mouseover(function(e,keepScroll){

			/* On a thumbnail click */
            /*$('li.menuItem').removeClass('act').addClass('inact');*/
			var i=0;
			$('#jqmenu ul li').each(function(){
				i++;
				$(this).removeClass('act'+i).addClass('nonact'+i);  
									})
			
			var cunt=$(this).parent().prevAll('.menuItem').length;
			
		    $(this).parent().removeClass('nonact'+(cunt+1)).addClass('act'+(cunt+1));
			
			var pos = $(this).parent().prevAll('.menuItem').length;
			$('#slides').stop().animate({marginTop:-positions[pos]+'px'},"slow","swing");
			/* Start the sliding animation */
			
			e.preventDefault();
			/* Prevent the default action of the link */
			
			// Stopping the auto-advance if an icon has been clicked:
			/*if(!keepScroll) clearInterval(itvl);*/
	});

	var k=1;
	$('#jqmenu ul li.menuItem:first').addClass('act1').siblings().each(function(){
				          k++;
			$(this).addClass('nonact'+k).attr("class");
				       
									})
	
	/*$('#jqmenu ul li.menuItem:first').addClass('act').siblings().addClass('inact');*/

	/* On page load, mark the first thumbnail as active */
	
	
	
	/*****
	 *
	 *	Enabling auto-advance.
	 *
	 ****/
	 
	var current=1;
	function autoAdvance()
	{
		if(current==-1) return false;
		
		$('#jqmenu ul li a').eq(current%$('#jqmenu ul li a').length).trigger('mouseover',[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
		current++;
	}

	// The number of seconds that the slider will auto-advance in:
	
	var changeEvery =7;

	var itvl = setInterval(function(){autoAdvance()},changeEvery*1000);

	/* End of customizations */
});
