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*312));
		
		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.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').setStyles({'display' : 'block'});
			//$('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();
