var photosXML = null;

var photoIndex = 0;
var photoCount;

var path = 'http://escola.saomarcos.br/images/phocagallery/';

function scrollPhoto()
{
	photoIndex++;
	if (photoIndex > (photoCount-1)) photoIndex = 0;
	
	var nextPhoto = path + $(photosXML).find('photo').eq(photoIndex).find('filename').text();
	var desc = $(photosXML).find('photo').eq(photoIndex).find('title').text();
	var $curPhoto = $('div.photo-slider div.photo').first();
	
	$('div.photo-slider').append('<div class="photo"><img src="' + nextPhoto + '" alt="" /><div class="description">' + desc + '</div></div>');
	
	var $newPhoto = $('div.photo-slider').find('div.photo').last();
	
	$curPhoto.addClass('current');
	
	$newPhoto.find('img').load(function(){
		//$('div.photos').stop().scrollTo($newPhoto, 1000, function(){
		$('div.photos').find('div.photo').each(function(){
			$(this).animate({ left: -700 }, 1000, function(){
				$('div.photos').find('div.photo').not('div.photo:last').remove();
				//$('div.photos').stop().scrollTo(0);
				$('div.photos').find('div.photo').stop().css({left: 0 });
				setTimeout(scrollPhoto, 3000);
			});
		});
	});
}

$(document).ready(function(){
	$('div.photos').stop().scrollTo(0);
	
	$.ajax({
		method: 'POST',
		dataType: 'xml',
		url: 'photos.php',
		success: function(xml) {
			photosXML = xml;
			
			$('div.photos img').attr('src', path + $(xml).find('photo').first().find('filename').text());
			$('div.photos div.description').html($(xml).find('photo').first().find('title').text());
			
			photoCount = $(xml).find('photo').length;
			
			setTimeout(scrollPhoto, 3000);
		}
	});
	
	$('a.navEsc').mouseover(function(){
		$('#banner_esc').fadeIn('fast');
	})
	.mouseout(function(){
		$('#banner_esc').fadeOut('fast');
	});
	
	$('a.navFac').mouseover(function(){
		$('#banner_fac').fadeIn('fast');
	})
	.mouseout(function(){
		$('#banner_fac').fadeOut('fast');
	});
	
	$('a.navMant').mouseover(function(){
		$('#banner_mant').fadeIn('fast');
	})
	.mouseout(function(){
		$('#banner_mant').fadeOut('fast');
	});
});
