var Gallery = {
	imgScroll : null,
	maxImg : 0,
	curImg : 1,
	player : null,
	
	init : function() {
		window.addEvent('load',Gallery._init);
	},
	
	_init : function () {
		Gallery.imgScroll = new Fx.Scroll('showIMG', {
			wait: false,
			duration: 1500,
			transition: Fx.Transitions.Quad.easeInOut
		});
	
		Gallery.maxImg = $('imgContain').getChildren('div').length;
		$('imgContain').setStyle('width', (Gallery.maxImg*448));
		
		Gallery.gotocurImg();
		/*
		if(Gallery.maxImg > 1) {
			$('nextNews').setStyle('display', 'block');
		}
		*/
	},
	
	nextImg: function(){
		if (Gallery.curImg < Gallery.maxImg) {
			Gallery.stopSlide();
			Gallery.curImg++;
			Gallery.gotocurImg();
		}
	},
	
	prevImg : function(){
		if (Gallery.curImg > 1) {
			Gallery.stopSlide();
			Gallery.curImg--;
			Gallery.gotocurImg();
		}
	},
	
	gotocurImg : function() {
		//Gallery.imgScroll.toElement('img'+Gallery.curImg);
		Gallery.imgScroll.start((Gallery.curImg - 1) * 448, 0);
		//Gallery.linkEnlarge();
		/*
		if (Gallery.maxImg > 1) {
			if(Gallery.curImg == Gallery.maxImg) {
				$('nextNews').setStyle('display', 'none');
				$('prevNews').setStyle('display', 'block');
			} else if(Gallery.curImg == 1) {
				$('prevNews').setStyle('display', 'none');
				$('nextNews').setStyle('display', 'block');
			} else {
				$('prevNews').setStyle('display', 'block');
				$('nextNews').setStyle('display', 'block');
			}
		}
		*/
	},
	
	showImg : function(id) {
		Gallery.stopSlide();
		Gallery.curImg = id;
		Gallery.gotocurImg();
	},
	
	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;
	}

	/*
	linkEnlarge : function() {
		if ($('lnkEnlarge')) {
			//$('lnkEnlarge').set('href', $('img'+Gallery.curImg).getFirst('a').get('href'));
			//$('lnkEnlarge').set('href', $('img'+Gallery.curImg).getFirst('img').get('src').replace(/\/big\//i,"/enlarge/"));
			//$('lnkEnlarge').set('href', "enlarge.php?id="+$('img'+Gallery.curImg).getFirst('img').get('id'));
		}
	}
	*/
}
Gallery.init();

var Gallery2 = {
	imgScroll : null,
	maxImg : 0,
	curImg : 1,
	player : null,

	init : function() {
		window.addEvent('load',Gallery2._init);
	},

	_init : function () {
		Gallery2.imgScroll = new Fx.Scroll('showIMG2', {
			wait: false,
			duration: 1500,
			transition: Fx.Transitions.Quad.easeInOut
		});

		Gallery2.maxImg = $('imgContain2').getChildren('a').length;
		$('imgContain2').setStyle('width', (Gallery2.maxImg*85) + 25);
		Gallery2.maxImg -= 4;
		//$('lipaPrev').setStyle('display', 'none');

		Gallery2.gotocurImg();
	},

	nextImg: function(){
		if (Gallery2.curImg < Gallery2.maxImg) {
			Gallery2.stopSlide();
			Gallery2.curImg++;
			Gallery2.gotocurImg();
		}
		$('lipaPrev').setStyle('visibility', 'visible');
		if (Gallery2.curImg == Gallery2.maxImg) {
			$('lipaNext').setStyle('visibility', 'hidden');
		}
	},

	prevImg : function(){
		if (Gallery2.curImg > 1) {
			Gallery2.stopSlide();
			Gallery2.curImg--;
			Gallery2.gotocurImg();
		}
		$('lipaNext').setStyle('visibility', 'visible');
		if (Gallery2.curImg == 1) {
			$('lipaPrev').setStyle('visibility', 'hidden');
		}
	},

	gotocurImg : function() {
		Gallery2.imgScroll.start((Gallery2.curImg - 1) * 85, 0);
	},

	showImg : function(id) {
		Gallery2.stopSlide();
		Gallery2.curImg = id;
		Gallery2.gotocurImg();
	},

	playSlide : function(){
		if (Gallery2.curImg < Gallery2.maxImg) {
			Gallery2.curImg++;
		} else {
			Gallery2.curImg=1;
		}
		Gallery2.gotocurImg();
		Gallery2.player = setTimeout("Gallery2.playSlide()",5000);
		return false;
	},

	stopSlide : function(){
		clearTimeout(Gallery2.player);
		return false;
	}

}
Gallery2.init();
