var slideShow =
{
	init: function ()
	{
		this.setList();
		
		if (this.countList > '0')
		{
			this.actualIndex = '0';
			this.showItem(this.actualIndex, true);
			
			if (this.countList > '1')
			{
				this.setTimer();
			}
		}
	},
	setList: function ()
	{
		this.list = new Array();
		
		$('#gallery .thumbs a').each
		(
			function (index)
			{
				slideShow.list[index] = $(this).attr('rel');
				
				$(this).bind
				(
					'click',
					function()
					{
						slideShow.showItem(index);
					}
				);
			}
		);
		
		this.countList = this.list.length;
	},
	showItem: function (index, start)
	{
		if (this.actualIndex != index || start == true)
		{
			$.ajax
			(
				{
					type: 'GET',
					url: '/editor/scripts/custom_scripts/ajax/gallery/medium.ajax.php',
					data: 'image_id=' + slideShow.list[index],
					success: function(req)
					{
						var image_url = req.getElementsByTagName('image_url')[0].childNodes[0].nodeValue;
						var medium_url = req.getElementsByTagName('medium_url')[0].childNodes[0].nodeValue;
						var img_width = req.getElementsByTagName('width')[0].childNodes[0].nodeValue;
						var img_height = req.getElementsByTagName('height')[0].childNodes[0].nodeValue;
						
						$('#gallery_image').attr('href', medium_url);
						$('#gallery_image img').attr
						(
							{
								src: medium_url,
								width: img_width,
								height: img_height
							}
						);
					}
				}
			);
			
			$('#gallery_image .thumbs a[rel="' + slideShow.list[index] + '"]').focus();
			
			this.actualIndex = index;
		}
	},
	showNextItem: function ()
	{
		var index = this.actualIndex * 1 + 1 * 1;
		if (index == this.countList)
		{
			index = '0';
		}
		
		this.showItem(index, true);
		
		this.timer = setTimeout('slideShow.showNextItem();', '3000');
	},
	setTimer: function ()
	{
		this.timer = setTimeout('slideShow.showNextItem();', '3000');
	}
}

$(document).ready
(
	function()
	{
		$('#gallery_image').lightBox
		(
			{
				imageLoading: '/editor/images/design/lightbox/lightbox-ico-loading.gif',
				imageBtnClose: '/editor/images/design/lightbox/lightbox-btn-close.gif',
				imageBtnPrev: '/editor/images/design/lightbox/lightbox-btn-prev.gif',
				imageBtnNext: '/editor/images/design/lightbox/lightbox-btn-next.gif',
				txtImage: 'Image',
				txtOf: 'of'
			}
		);
		
		slideShow.init();
	}
);
