// JavaScript Document

function Gallery(id,name){
	this.name = name;
	this.id = document.getElementById(id);
	this.elem = this.id.getElementsByTagName('div');//new Array();
	this.current = 0;
	this.last = 0;
	
	this.auto;
	
	this.alpha = 0;
	
	this.menu = '<div class="controls"><a href="javascript:void(0);" onclick="'+this.name+'.prev();" style="text-decoration:none;">&nbsp;&laquo;&nbsp;</a>&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" onclick="'+this.name+'.next();" style="text-decoration:none;">&nbsp;&raquo;&nbsp;</a></div>';
	
	this.init = function(){
		//alert(this.name);
		if(this.elem.length > 0)
		for(var i=0; i<this.elem.length;i++)
		{
			if(i == 0){
				this.elem[i].style.display='block';
			}else{
				this.elem[i].style.display='none';
			}
		}
		this.id.innerHTML += this.menu;
		//this.transit(0);
	},
	
	this.play = function(){
		if(this.elem.length > 0)
		this.auto = setInterval(this.name+'.next()', 5000);
	},
	
	this.mstop = function(){
		clearInterval(this.auto);
	},
	
	this.transit = function(number1){
		for(var i=0; i<this.elem.length-1;i++)
		{
			if(i == number1){
				this.elem[i].style.display='block';
			}else{
				this.elem[i].style.display='none';
			}
		}
	},
	
	this.next = function(){ 
		this.mstop();
		this.play();
		this.current++;
		if(this.current == this.elem.length-1)
			this.current = 0;
			
		this.transit(this.current);
	},
	
	this.prev = function(){
		this.mstop();
		this.play();
		this.current--;
		if(this.current < 0)
			this.current = this.elem.length-2;
			
		this.transit(this.current);
	}
	
}
