/*
(c) 2010 Fork Ltd - by Tomas Pollak
based on http://tutorialzine.com/2009/11/beautiful-apple-gallery-slideshow/
*/

var positions = new Array();
var delay = 500;

var Slider = {

	initialize: function(){

		var totWidth=0;

		$('#slides .slide').each(function(i){

			/* Loop through all the slides and store their accumulative widths in totWidth */
			positions[i]= totWidth;
			totWidth += $(this).width();

		});

		// $('#slides').width(totWidth);

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

		$('.slider.menu a').click(function(e){
			Slider.moveTo(this, e);
		});


		$('.switch-slide').click(function(e){
			a = $('#menuitem-' + $(this).attr('href').replace('#', '') + ' a');
			Slider.moveTo(a, e);
		})

	},

	moveTo: function(a, e){

			$(a).parent().addClass('selected').siblings('li').removeClass('selected');
			var pos = $(a).parent().prevAll('li').length;

			$('#slides').stop().animate({marginLeft:-positions[pos]+'px'},delay);

			e.preventDefault();

	}

}

