// JavaScript Document
	function setCurrent(N){
        currentImg_photo=N; 
    };
    function nextPhoto(){
        var N = currentImg_photo + 1;
        if (N >= gal_count) {
            N=0;
        }
            slideJump(N);
    };
    function prevPhoto(){
        var N = currentImg_photo - 1;
        if (N < 0) {
            N = gal_count;
        }
            slideJump(N);
    };
	
    function slideJump(N){
        if (N!=currentImg_photo) {
             // if (currentImg_photo<N) {slideLeft(N);} else {slideRight(N);}
			 slideLeft(N);
        }
    }

    function getIMGTag(N){
		var ih=preview_images[N][2];
		var iw=preview_images[N][1]; 
        var ir = iw/ih;
        if (ih>mh || iw>mw) {
            if (ir<1) {
                var ih = mh;
                var iw = Math.ceil(mh * ir);
            } else {
                var ih = Math.ceil(mw / ir);
                var iw = mw;
            }
        }
        return '<img src="'+preview_images[N][0]+'" alt="'+preview_images[N][3]+'" id="obj_img" width="'+iw+'" height="'+ih+'" style="top:50%;left:50%;margin-top:-'+(ih/2)+ 'px;margin-left:-'+(iw/2)+'px;position:absolute;" />';
    }
    
    function slideLeft(N){
                var newImg_container = ((currentImg_container+2)%2)+1;
                var c_from = "#big-img-" + currentImg_container;
                var c_to = "#big-img-" + newImg_container;
                var newIMG = getIMGTag(N);
                jQuery(c_from).animate({left:-mw,top:0}, animTime);
                jQuery(c_to).css({left:mw,top:0});
                jQuery(c_to).html(newIMG);
                jQuery(c_to).animate({left:0,top:0}, animTime, function(){
                    // Animation done
                    currentImg_container = newImg_container;
                    setCurrent(N);
                });
            }
    function slideRight(N){
                var newImg_container = ((currentImg_container+2)%2)+1;
                var c_from = "#big-img-" + currentImg_container;
                var c_to = "#big-img-" + newImg_container;
                var newIMG = getIMGTag(N);
                jQuery(c_from).animate({left:mw,top:0}, animTime);
                jQuery(c_to).css({left:-mw,top:0});
                jQuery(c_to).html(newIMG);
                jQuery(c_to).animate({left:0,top:0}, animTime, function(){
                    // Animation done
                    currentImg_container = newImg_container;
                    setCurrent(N);
                });
            }
			

(function(jQuery) {
	var imgList = [];
	jQuery.extend({
		preload: function(imgArr, option) {
			var setting = $.extend({
				init: function(loaded, total) {},
				loaded: function(img, loaded, total) {},
				loaded_all: function(loaded, total) {}
			}, option);
			var total = imgArr.length;
			var loaded = 0;
			
			setting.init(0, total);
			for(var i in imgArr) {
				imgList.push(jQuery("<img />")
					.attr("src", imgArr[i])
					.load(function() {
						loaded++;
						setting.loaded(this, loaded, total);
						if(loaded == total) {
							setting.loaded_all(loaded, total);
						}
					})
				);
			}
			
		}
	});
})(jQuery);

var usePreload = true;

jQuery(document).ready(function() {
		slideJump(0);
		jQuery(document).everyTime("8s", function(i) { nextPhoto();}, 0);
});

