var f = jQuery.noConflict();
f(document).ready(function(){

	var totWidth=0;
	var positions = new Array();
	
	f('#slides .slide').each(function(i){
		
		positions[i]= totWidth;
		totWidth += f(this).width();
		
		if(!f(this).width())
		{
			alert("Please, fill in width & height for all your images!");
			return false;
		}
		
	});
	
	f('#slides').width(totWidth);

	f('#menu ul li a').click(function(e,keepScroll){

			f('li.menuItem').removeClass('act').addClass('inact');
			f(this).parent().addClass('act');
			
			var pos = f(this).parent().prevAll('.menuItem').length;
			
			f('#slides').stop().animate({marginLeft:-positions[pos]+'px'},450);

			e.preventDefault();

			if(!keepScroll) clearInterval(itvl);
	});
	
	f('#menu ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	 
	var current=1;
	function autoAdvance()
	{
		if(current==-1) return false;
		
		f('#menu ul li a').eq(current%f('#menu ul li a').length).trigger('click',[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
		current++;
	}

	var changeEvery = 4;

	var itvl = setInterval(function(){autoAdvance()},changeEvery*1000);
});
