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,3000);


});
function showNextImage()
{
    var currentNode = $('#galleryUl').children('div:visible');
    var targetNode = currentNode.nextAll('div').length?currentNode.next('div'):$('#galleryUl').children('div:first');
    var _zIndex = 100;

    currentNode.css({
        opacity:1,
        zIndex:_zIndex
    }).show();
    targetNode.css({
        opacity:1,
        zIndex:_zIndex-1
    }).show();
    currentNode.animate({
        opacity:0
    },500,function(){
        currentNode.hide();
//        if(targetNode.prev('div').length==0)
//        {
//            clearInterval(handle);
//            targetNode.css({opacity:1}).show();
//        }
    });
}

