var playtimer;
var id=0;
var timeInterval = 7000; 
var bPlay = true;
var iMax = $(".sshead > img").size();;
controllerNav();
showImage(Math.floor(Math.random()*iMax) + 1 );
function controllerNav()
{
	for (var i=2; i <= iMax; i++)
	{
			var numId = "num" + i;
			$("#num1").clone().attr({id: numId}).appendTo("#controller");
	}
	
	$("#controller").fadeIn(800);
	var count = 1;
	$("#controller .number").each(function(){ 
		$(this).append(count);
		$(this).fadeIn(500*count);
		$(this).click(function(){showImage($(this).text());});
		count++;
	});
	
	$("#play").click(function(){
		if (bPlay)
			stopGallery();
		else
			playGallery();
	});
}

function showImage(idSlide)
{
	clearTimeout(playtimer);
	$("#img_" + id).fadeOut(800);

	if (idSlide != undefined)
		id=idSlide;
	else
		id++;
	
	if (id > iMax)
		id = 1;
	//Controller selection of number
	$(".number").removeClass("colorSSSel");
	$("#num" + id).addClass("colorSSSel");
	$("#img_" + id).fadeIn(800);
	if (bPlay)
		playtimer = setTimeout('showImage()',timeInterval);
}


function stopGallery()
{
	clearTimeout(playtimer);
	$("#play").addClass("pause");
	bPlay = !bPlay;
}

function playGallery()
{
	playtimer = setTimeout('showImage()',200);
	$("#play").removeClass("pause");
	bPlay = !bPlay;
}

