﻿var iTotal = 0;
var images = new Array();
var viewArea = {};
var sDesc = '';
var mooving = false;
function initializeSlideshow() {

	iTotal = 0;
	images = new Array();
	currentImage = 0;
	viewArea = { x: (jQuery("#slideshow-image-container").width() + 20), y: (jQuery("#slideshow-image-container").height() + 20) };
	jQuery("#slideshow-image-container ul li").each(function (ind, elm) {
		jQuery(elm).css('position', 'absolute');
		jQuery(elm).css('left', iTotal * viewArea.x + 'px');
		jQuery(elm).css('height', viewArea.y);
		jQuery(elm).css('width', viewArea.x);
		images.push(jQuery(elm).find("img").attr("title"));
		jQuery(elm).find("img").css('left', 0);
		var url = jQuery(elm).find('img').attr('src');
		jQuery(elm).css('background', 'url(' + url + ') no-repeat 50% 50%');
		jQuery(elm).find("img").remove();
		iTotal++;
	});
	jQuery('.counter').html(trlImage + ' ' + (currentImage + 1) + '/' + images.length);
	jQuery('#slideshow-controls .buttons a.previous').click(function () { moveImages('+'); });
	jQuery('#slideshow-controls .buttons a.next').click(function () { moveImages('-'); });
	//$(function() {
	$('#slideshow-image-container a').lightBox(lbSettings);
	//});
}
function moveImages(dir) {
	var pos = parseInt(jQuery('#imageholderul').css('left'));
	if (!mooving) {
		if (dir == '-') {
			if (pos > (0 - ((iTotal - 1) * viewArea.x))) {
				currentImage++;
				mooving = true;
				jQuery('#imageholderul').animate({ left: '-=' + viewArea.x + '' }, 500, function () { mooving = false; });
			}
		}
		else {
			if (pos < 0) {
				currentImage--;
				mooving = true;
				jQuery('#imageholderul').animate({ left: '+=' + viewArea.x + '' }, 500, function () { mooving = false; });
			}
		}
		jQuery('.counter').html(trlImage + ' ' + (currentImage + 1) + '/' + images.length);
	}
}
jQuery(document).ready(function () {
	initializeSlideshow();
});
