﻿var Gallery = {
    imgScroll : null,
    tnScroll : null,
    maxImg : 0,
    maxThumb : 0,
    curImg : 1,
    curThumb : 1,
    player : null,
    arrTitle : Array(),
    
    init : function() {
        window.addEvent('load',Gallery._init);
    },
    
    _init : function () {
        Gallery.imgScroll = new Fx.Scroll('Img_Display', {
	        wait: false,
	        duration: 1500,
	        transition: Fx.Transitions.Quad.easeInOut
        });

        Gallery.tnScroll = new Fx.Scroll('Thumb_Display', {
	        wait: false,
	        duration: 1500,
	        transition: Fx.Transitions.Quad.easeInOut
        });
        
        var divImg = $('imgContain').getChildren('div');
        $('imgContain').setStyle('width', (divImg.length*(496*12)));
        divImg.each(function(el){
            Gallery.maxImg += el.getChildren('div').length;
        });
        Gallery.maxThumb = $('thumbContain').getChildren('div').length;
        $('thumbContain').setStyle('width', (Gallery.maxThumb*228));
        
        Gallery.gotocurImg();
        Gallery.tnScroll.toElement('divThumb1');
        if(Gallery.maxThumb > 1) {
            $('lnkNext').setStyle('display', 'block');
        }
    },

    gotocurImg : function() {
        Gallery.imgScroll.toElement('img'+Gallery.curImg);
        $('footnote').innerHTML = '<p>'+Gallery.arrTitle[(Gallery.curImg-1)]+'</p>';
    },

    showImg : function(id) {
        Gallery.stopSlide();
        Gallery.curImg = id;
        Gallery.gotocurImg();
    },

    nextThumb : function(){
        if (Gallery.curThumb < Gallery.maxThumb) {
            Gallery.curThumb++;
            Gallery.tnScroll.toElement('divThumb'+Gallery.curThumb);
            if(Gallery.curThumb == Gallery.maxThumb) {
                $('lnkNext').setStyle('display', 'none');
            }
            $('lnkPrev').setStyle('display', 'block');
        }
    },

    prevThumb : function(){
        if (Gallery.curThumb > 1) {
            Gallery.curThumb--;
            Gallery.tnScroll.toElement('divThumb'+Gallery.curThumb);
            if(Gallery.curThumb == 1) {
                $('lnkPrev').setStyle('display', 'none');
            }
            $('lnkNext').setStyle('display', 'block');
        }
    },

    playSlide : function(){
	    if (Gallery.curImg < Gallery.maxImg) {
            Gallery.curImg++;
        } else {
            Gallery.curImg=1;
        }
	    Gallery.gotocurImg();
	    Gallery.player = setTimeout("Gallery.playSlide()",5000);
	    return false;
    },

    stopSlide : function(){
	    clearTimeout(Gallery.player);
	    return false;
    }
}
Gallery.init();