$(document).ready(function() {
    var gallery = $('.coffitoElement.listHS.compPageBinder .inner .items');
    var children = null;
    for (var i = 0; i < gallery.length; i++) {
        children = $(gallery[i]).children('.item');
        $(gallery[i]).height($(children).height());
        $(children).css('position', 'absolute').css('top', '0').css('left', '0');
        $(gallery[i]).css('overflow', 'hidden').css('position', 'relative');
        $(gallery[i]).data('sliderItem', 0);
        $(gallery[i]).data('sliderPlay', true);
        $(gallery[i]).hover(
            function() {$(this).data('sliderPlay', false)},
            function() {$(this).data('sliderPlay', true)}
        );
        if (children.length > 1) {
            for (var j = 1; j < children.length; j++) {
                $(children[j]).hide();
            }
        }
    }
    //change image
    setInterval(function() {
       var gallery = $('.coffitoElement.listHS.compPageBinder .inner .items');
       var children = null;
       var current = null;
       for (var i = 0; i < gallery.length; i++) {
         children = $(gallery[i]).children('.item');
         if (children.length > 1 && $(gallery[i]).data('sliderPlay')) {
             current = $(gallery[i]).data('sliderItem');
             if(current < children.length - 1) {
               $(gallery[i]).data('sliderItem', current+1);
               $(children[current]).css('z-index', 20);
               $(children[current+1]).css('z-index', 10).show();
               $(children[current]).stop(true, true).fadeOut(500);
             } else {
               $(gallery[i]).data('sliderItem', 0);
               $(children[current]).css('z-index', 20);
               $(children[0]).css('z-index', 10).show();
               $(children[current]).stop(true, true).fadeOut(500);
             }
         }
       }
    }, 5000);
});


