var currentIndex = 0;
var imgs = [];

$(document).ready(function() {

var ajax = $.ajax({
    type: 'GET',
    url: '/js/slideshow.hpg.js2.php',
    dataType: 'json',
    success: function() { },
    data: {},
    async: false
});

imgs = jQuery.parseJSON(ajax.responseText);

	slideShow();

});


function slideShow() {
	$('#gallery').find('img').attr('src', imgs[currentIndex].src);
	$('#gallery .caption .galletyContent').find('a').attr('href', imgs[currentIndex].captionlink);
	$('#gallery .caption .galletyContent').find('a').text(imgs[currentIndex].caption);
	setInterval('gallery()',4500);
}



function gallery() {
	$('#gallery').css({opacity: 0.0})

	currentIndex++;
	if(currentIndex >= imgs.length) currentIndex = 0;
	
	$('#gallery').find('img').attr('src', imgs[currentIndex].src);
	$('#gallery .caption .galleryContent').find('a').attr('href', imgs[currentIndex].captionlink);
	$('#gallery .caption .galleryContent').find('a').html(imgs[currentIndex].caption);
	
	$('#gallery').animate({opacity: 1.0}, 500);
}

