﻿//var iTotal = 0;
var images = new Array();
//var sDesc = '';
//var mooving = false;
function initializeSlideshow() {



	var viewArea = { x: $("#slideshow-image-container").width(), y: $("#slideshow-image-container").height()-20 };
	$("#slideshow-image-container ul li").each(function (ind, elm) {
		$(elm).css('left', ind * viewArea.x + 'px');
		$(elm).css('height', viewArea.y);
		$(elm).css('width', viewArea.x);
		images.push($(elm).find("img").attr("title"));
		$(elm).find("img").css('left', 0);
		var url = $(elm).find('img').attr('src');
		$(elm).css('background', 'url(' + url + ') no-repeat 50% 50%');
		$(elm).find("img").remove();
		
		//		iTotal++;
	});
	//$('#DetailMenuAreaInfo').html(trlImage + ' ' + (currentImage + 1) + '/' + images.length + ': ' + images[0]);
	//$('#imgnavitems-right').click(function() { scrollContainer('-', viewArea.x, 1, $('#imageholderul')); });
	//$('#imgnavitems-left').click(function() { scrollContainer('+', viewArea.x, 1, $('#imageholderul')); });
}

function isScrolling(container) {
	return container.data("isMooving") === true;
}

function scrollContainer(dir, nImages, container) {
	if (isScrolling(container))
		return false;

	var result = false;
	var pixelsPerImage = container.parent().width();
	var pos = parseInt(container.css('left'));
	var iTotal = container.children().length;
	//alert("iTotal:" + iTotal + ", pos:" + pos + ", mooving:" + mooving);
	if (dir == '-') {
		if (pos > (0 - ((iTotal - 1) * pixelsPerImage))) {
			//currentImage++;
			container.data("isMooving", true);
			container.animate({ left: '-=' + pixelsPerImage * nImages + '' }, 500, function() { container.removeData("isMooving"); });
			result = true;
		}
	}
	else {
		if (pos < 0) {
			//currentImage--;
			container.data("isMooving", true);
			container.animate({ left: '+=' + pixelsPerImage * nImages + '' }, 500, function() { container.removeData("isMooving"); });
			result = true;
		}
	}
	//sDesc = images[currentImage];
	//$('#DetailMenuAreaInfo').html(trlImage + ' ' + (currentImage + 1) + '/' + images.length + ': ' + sDesc);
	return result;
}

$(document).ready(function() {
	initializeSlideshow();
});
