
/*
var path = '/gallery/image/galleryshow/';
var galleryshowimages = [
    path + 'DSC04132web1.jpg',
    path + 'DSC04133web2.jpg',
    path + 'DSC04135web3.jpg',
    path + 'u.jpg',
    path + 'uzlet_web2.jpg',
    path + 'uzlet_web3.jpg',
    path + 'uzlet_web4.jpg',
    path + 'uzlet_web5.jpg',
    path + 'uzlet_web6.jpg'
];
*/

var slide = 0;//tracks which slide is showing
var slidePause = 2000; //length of time to keep a slide at 1 opacity

var progress, bar, galleryImgs, loadedImages, gallery;

function $E(A,B){
    return($(B)||document).getElement(A);
}

window.addEvent('domready', function() {

    function loadImages( images ){

        progress = $('progress');
        bar = $E('#progress .bar');
        galleryImgs = $$('#gallery img');
        loadedImages = [];
        gallery = $('gallery');

        gallery.setStyles({'opacity': 0, 'display': 'none'});

        progress.setStyle('visibility', 'hidden');

        if (galleryImgs.length > 0)
            galleryImgs.each(function(image) {	image.remove();	});

        progress.setStyle('visibility', 'visible');
        gallery.setStyle('display', 'block');

        new Asset.images( images, {
            onProgress: function(i) {
                this.setStyles({
                    'position': 'absolute',
                    'opacity': 0,
                    'left': (gallery.getCoordinates().width / 2) - (this.width / 2),
                    'top': (gallery.getCoordinates().height / 2) - (this.height / 2)
                });
                loadedImages[i] = this;
                var percent = ((i + 1) * progress.getStyle('width').toInt()) / images.length;
                if( i < images.length )
                    bar.setStyle('width', percent.toInt() ).setHTML(i + 1 + ' / ' + images.length);
            },
            onComplete: function() {
                var fx = gallery.effect('opacity').start(1).chain(function(){
                    progress.setStyle('display', 'none');
                    nextImg(-1);
                });
            }
        });

    }

    loadImages( galleryshowimages );

});

function nextImg(){
    slide = (slide == loadedImages.length-1)?0: slide+1;
    if($E('img', gallery)){
        $E('img', gallery).effect('opacity', {duration: 2000, onComplete: function(){
            $E('img',gallery).remove();
        }
        }).start(0);
        showImg(loadedImages[slide] );
    } else
        showImg(loadedImages[slide] );
}

function showImg( img ){
    img.inject(gallery);
    img.effect('opacity', {duration: 2000, onComplete: function(){
            setTimeout('nextImg()',slidePause);
        }
    }).start(1);
}




var slide2 = 0;//tracks which slide is showing
var slidePause2 = 2000; //length of time to keep a slide at 1 opacity

var progress2, bar2, galleryImgs2, loadedImages2, gallery2;

function $E(A,B){
    return($(B)||document).getElement(A);
}
/*
window.addEvent('domready', function() {

    function loadImages2( images2 ){

        progress2 = $('progress2');
        bar2 = $E('#progress2 .bar2');
        galleryImgs2 = $$('#gallery2 img2');
        loadedImages2 = [];
        gallery2 = $('gallery2');

        gallery2.setStyles({'opacity': 0, 'display': 'none'});

        progress2.setStyle('visibility', 'hidden');

        if (galleryImgs2.length > 0)
            galleryImgs2.each(function(image2) {	image2.remove();	});

        progress2.setStyle('visibility', 'visible');
        gallery2.setStyle('display', 'block');

        new Asset.images( images2, {
            onProgress: function(i) {
                this.setStyles({
                    'position': 'absolute',
                    'opacity': 0,
                    'left': (gallery2.getCoordinates().width / 2) - (this.width / 2),
                    'top': (gallery2.getCoordinates().height / 2) - (this.height / 2)
                });
                loadedImages2[i] = this;
                var percent2 = ((i + 1) * progress2.getStyle('width').toInt()) / images2.length;
                if( i < images2.length )
                    bar2.setStyle('width', percent2.toInt() ).setHTML(i + 1 + ' / ' + images2.length);
            },
            onComplete: function() {
                var fx = gallery2.effect('opacity').start(1).chain(function(){
                    progress2.setStyle('display', 'none');
                    nextImg2(-1);
                });
            }
        });



    }

    loadImages2( newproducts_images );


});
*/

function nextImg2(){
    slide2 = ( slide2 == loadedImages2.length-1 )? 0 : slide2+1 ;
    if($E('img', gallery2)){
        $E('img', gallery2).effect('opacity', {duration: 2000, onComplete: function(){
            $E('img',gallery2).remove();
        }
        }).start(0);
        showImg2(loadedImages2[slide2] );
    } else
        showImg2(loadedImages2[slide2] );
}

function showImg2( img2 ){
    img2.inject(gallery2);
    img2.effect('opacity', {duration: 2000, onComplete: function(){
            setTimeout('nextImg2()',slidePause2);
        }
    }).start(1);
}


