
gallery = function() {

	/* show first image and information */
	showTime=5000;
	APtimer=0;
	absLeft=0;
	picCount=0;
	total = $('.thumb img').length;

	$totalImgs = $('.thumb img');

//	console.log("total: "+total);
//	console.log("total Imgs: "+$totalImgs);

	thumbWidth = 2200;
/*
	thumbWidth = 0;
	for (x=0; x<total; x++) {
		thumbWidth = thumbWidth + $($totalImgs[x]).outerWidth();
		console.log($($totalImgs[x]).outerWidth());
	}
*/

//	console.log("thumb width: "+thumbWidth);

	$('#innerContainer').css({ width: thumbWidth + 'px'});
	$('#innerContainer img').css({ display: 'inline'});

	firstStr = $('.thumb');
	showStr = firstStr.html();
	showDiv(showStr)

	$('#slideLeft').hover(function(e) {
			$('#innerContainer').stop();
			$('#innerContainer').animate({"left": "0px"}, 9000 , "swing")
		}, function() {
			$('#innerContainer').stop();
	});

	$('#slideRight').hover(function(e) {
			posLeft = $('#thumbnails').offset().left;
			absLeft = e.pageX - posLeft;
			hiddenBit = thumbWidth - 800;
			$('#innerContainer').stop();
			$('#innerContainer').animate({"left": -hiddenBit + "px"}, 9000 , "swing")
		}, function() {
			$('#innerContainer').stop();
	});

	/* monitor mouse clicks */
	$('.thumb').click(function() {
			htmlStr = $(this).html();
			currentLarge = $(this).attr('class').split(' ').slice(-1);
			/* swap images and information */
			$('#fullSize').fadeOut(600, function(){showDiv(htmlStr)});
	});

	/* show image and information */
	function showDiv(htmlStr) {
		$('#fullSize').html(htmlStr).fadeIn(600);
		currentLarge = $('#fullSize img').attr('class');
		currentLarge = currentLarge.substr(1,3);
	}

	$('#clickRight').click(function() {
		currentLarge = $('#fullSize img').attr('class');
		if ("p" + total != currentLarge) {
			htmlStr = $('#innerContainer li.'+currentLarge).next('li').html();
			$('#fullSize').fadeOut(600, function(){showDiv(htmlStr)});
		}
	});

	$('#clickLeft').click(function() {
		currentLarge = $('#fullSize img').attr('class');
		if ("p1" != currentLarge) {
			htmlStr = $('#innerContainer li.'+currentLarge).prev('li').html();
			$('#fullSize').fadeOut(600, function(){showDiv(htmlStr)});
		}
	});

	$('#autoPlay').toggle(function() {
		FotosAUTOPLAY = 0;
		clearTimeout(APtimer);
		$('#pausePlay').fadeOut(10, function() {
			$('#startPlay').fadeIn(10);
		});
	}, function() {
		$('#startPlay').fadeOut(10, function() {
			$('#pausePlay').fadeIn(10);
		});
		FotosAUTOPLAY = 1;
		autoPlay();
	});

} // EO gallery()

// ****************************************************************************

function autoPlay() {
	currentLarge = $('#fullSize img').attr('class');

	if (("p" + total) != currentLarge) {
		htmlStr = $('#innerContainer li.'+currentLarge).next('li').html();
	} else {
		htmlStr = $('#innerContainer li.p1').html();
	}

	$('#fullSize').fadeOut(600, function(){ playDiv(htmlStr) });

	APtimer = setTimeout ("autoPlay()", showTime);
}


function playDiv(htmlStr) {
	$('#fullSize').html(htmlStr).fadeIn(600);
	currentLarge = $('#fullSize img').attr('class');
	currentLarge = currentLarge.substr(1,3);
}


