var cycles = 0;
var handle;
var _zIndex = 1000;
$(document).ready(function(){
$('#galleryUl').children('div').each(function(){
if($(this).prevAll('div').length>0)
$(this).hide();
 $(this).css({
zIndex:--_zIndex
});
});
if($('#galleryUl').length)
handle = setInterval(showNextImage,5000);


});
function showNextImage()
{
var currentNode = $('#galleryUl').children('div:visible');
var targetNode = currentNode.nextAll('div').length?currentNode.next('div'):$('#galleryUl').children('div:first');

currentNode.css({
opacity:1
}).show();
targetNode.css({
opacity:1
}).show();
currentNode.animate({
opacity:0
},500,function(){
currentNode.hide();
if(targetNode.prev('div').length==0)
{
clearInterval(handle);
targetNode.css({opacity:1}).show();
 }
});
} 