$(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){
		/* Loop through all the slides and store their accumulative widths in totWidth */
		positions[i]= totWidth;
		//totWidth += $(this).width();
		totWidth += 960;

		/* The positions array contains each slide's commulutative offset from the left part of the container */
		/*
		if(!$(this).width())
		{
			alert("Please, fill in width & height for all your images!");
			return false;
		}
		*/
	});

	$('#slides').width(totWidth);

	/* Change the cotnainer div's width to the exact width of all the slides combined */

	$('#slide_menu ul li.menuItem a').click(function(e,keepScroll){

		/* On a thumbnail click */
		$('li.menuItem').removeClass('act').addClass('inact');
		$(this).parent().addClass('act');

		var pos = $(this).parent().prevAll('.menuItem').length;

		$('#slides').stop().animate({marginLeft:-positions[pos]+'px'},450);
		/* 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);
	});

	$('#slide_menu ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	/* On page load, mark the first thumbnail as active */
});

/*****
*
*	Enabling auto-advance.
*
****/
var current=0;
function autoAdvance()
{
	if(current==-1) return false;
	current++;
	$('#slide_menu ul li.menuItem a').eq(current%$('#slide_menu ul li.menuItem a').length).trigger('click',[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
}

if (rotate_banner)
	var title="pause";
else
	var title="play";
var changeEvery = 15;
if (rotate_speed)
	changeEvery = rotate_speed;

var itvl=0;
if (title=="pause")
{
	// The number of seconds that the slider will auto-advance in:
	itvl = setInterval(function(){autoAdvance()},changeEvery*500);
	/* End of customizations */
}

function slideAhead()
{
	var title = gethtml('play_link');
	if (title=="pause")
	{
		autoAdvance();
		clearInterval(itvl);
		itvl = setInterval(function(){autoAdvance()},changeEvery*500);
	} else
	{
		autoAdvance();
	}
}

function slideBack()
{
	current--;
	current--;
	var title = gethtml('play_link');
	if (title=="pause")
	{
		autoAdvance();
		clearInterval(itvl);
		itvl = setInterval(function(){autoAdvance()},changeEvery*500);
	} else
	{
		autoAdvance();
	}
}

function toggleSlide()
{
	var title = gethtml('play_link');
	if (title=="play")
	{
		sethtml('play_link',"pause");
		setsrc('play_button','/images/icon_mm_pause.gif');
		itvl = setInterval(function(){autoAdvance()},changeEvery*500);
		//start playing
	} else
	{
		sethtml('play_link',"play");
		setsrc('play_button','/images/icon_mm_play.gif');
		clearInterval(itvl);
		//stop playing again
	}
}

/*var current=1;
function autoAdvance()
{
	if(current==-1) return false;

	$('#slide_menu ul li.menuItem a').eq(current%$('#slide_menu ul li.menuItem a').length).trigger('click',[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
	current++;
}

if (rotate_banner==1)
{
	// The number of seconds that the slider will auto-advance in:
	var changeEvery = 15;
	if (rotate_speed)
		changeEvery = rotate_speed;
	var itvl = setInterval(function(){autoAdvance()},changeEvery*500);
}*/

