var position = 0;
var moving = false;
var oldName = false;
var current = 0;

function moveLeft() {
	if (moving == false)
	{
		if ((position + 1) < max_position)
		{
			moving = true;
			
			$('#gallery_images_inner').fadeOut(100, function () {
				
				var left = $(this).css('left');
				left = left.substr(0, left.length - 2);
				
				left -= 600;
				
				$(this).css('left', left + 'px')
				
				$(this).fadeIn(100, function () {
					moving = false;
				});
				
				position++;
				
			});
		}
	}
}

function moveRight() {
	if (moving == false)
	{
		if (position > 0)
		{
			moving = true;
			
			$('#gallery_images_inner').fadeOut(100, function () {
				
				var left = $(this).css('left');
				left = parseInt(left.substr(0, left.length - 2));
				
				left += 600;
				
				$(this).css('left', left + 'px')
				
				$(this).fadeIn(100, function () {
					moving = false;
				});
				
				position--;
				
			});
		}
	}
}

function loadImage(id, title) {
	if (id != current) {
		$('#gallery_infobar_header').text(title)
		oldName = title;
		
		$('#gallery_loader_wrapper').fadeIn('fast', function() {
			$.get(
				'/getImage.php'
				, {'id': id, 'r' : (new Date()).getTime()}
				, function (data) {
				
					var productimage = '';
					var title = '';
					var description = '';
					var product_name = '';
					var page_name = '';
					
					$(data).find('image').each(function () {
						
						productimage = $(this).find('productimg').text();
						title = $(this).find('title').text();
						description = $(this).find('description').text();
						product_name = $(this).find('product_name').text();
						page_name = $(this).find('page_name').text();
					
					});
					
					var main = new Image();
					var prod = new Image();
					
					$(main).load(function() {
						
						$('#gallery_main_image img').attr('src', $(this).attr('src'));
						
						$(prod).load(function () {
					
							$('#gallery_product_image').attr('src', $(this).attr('src'));
							$('#gallery_main_info div').text(description);
							$('#gallery_product_link_text').text(product_name);
							$('#gallery_main_text a').attr('href', '/kids-fancy-dress/' + page_name + '.php');
							
							$('#gallery_loader_wrapper').fadeOut('fast');
						
						
						}).attr('src', '/_images/_images/m/' + productimage + '.jpg?r=' + (new Date()).getTime());
						
					}).attr('src', '/_images/_gallery/l/' + id + '.jpg?r=' + (new Date()).getTime());
				}
				, 'xml'
			);
		});
	current = id;
	}
}

function showName(x) {
	oldName = $('#gallery_infobar_header').text();
	
	$('#gallery_infobar_header').text(x);
}

function revertName() {
	$('#gallery_infobar_header').text(oldName);
}


























