var Gallery = {

	status : 'stop',
	current : 0,
	count : 0,
	timeout : null,
	
	oldImg : null,
	newImg : null,
	newDesc : '',

	init : function()
	{
	   $('PlayActive').style.display = 'inline';
	   $('StopInactive').style.display = 'inline';
	},
	
	play : function(current, count)
	{
	   if(!this.current && !this.count)
	   {
		   this.current = current;
		   this.count = count;
  		}
	   
	   $('PlayActive').style.display = 'none';
	   $('PlayInactive').style.display = 'inline';
	   $('StopActive').style.display = 'inline';
	   $('StopInactive').style.display = 'none';
	   
	   Gallery.getNext();
	},
	
	stop : function()
	{
	   window.clearTimeout(Gallery.timeout);
	   
	   $('PlayActive').style.display = 'inline';
	   $('PlayInactive').style.display = 'none';
	   $('StopActive').style.display = 'none';
	   $('StopInactive').style.display = 'inline';
	},
	
	getNext : function()
	{
	   var url = location.href.replace(/#.*$/, '') + '&action=getNextPhoto&current=' + this.current;
	   Ajax.sendRequest(url);
	},
	
	showPhoto : function(data)
	{
    	if(isIE)
	      this.oldImg = $('PhotoDetail').children[0];
		else
		{
			var i = 0;
			while(!$('PhotoDetail').childNodes[i].tagName)
				i++;

			this.oldImg = $('PhotoDetail').childNodes[i];
		}

		this.oldImg.id = uId(this.oldImg);

 		this.newImg = document.createElement('IMG');
 	   this.newImg.src = data['url'];
		this.newImg.id = uId(this.newImg);
		this.newImg.style.opacity = 0;
	   this.newImg.style.MozOpacity = 0;
		this.newImg.style.filter = 'Alpha(opacity=0)';
		
		this.newDesc = data['description'];

		//$('PhotoDetail').appendChild(this.newImg);
  		//$('PhotoDescription').innerHTML = data['description'];
		
		window.setTimeout('Gallery.display("'+ data['num_order'] +'")', 1000);
	},
	
	display : function(numOrder)
	{
		jsEffects.fadeOut(this.oldImg.id, {inc : 0.1, callback : "Gallery.removeOld()"});

	   this.current = numOrder;
	   $('Count').innerHTML = $('Count').innerHTML.replace(/\d+ \/ /, numOrder + ' / ');

		if(this.current < this.count)
			this.timeout = window.setTimeout('Gallery.getNext()', 3000);
	},
	
	removeOld : function()
	{
		$('PhotoDetail').removeChild(this.oldImg);
		$('PhotoDetail').appendChild(this.newImg);
  		$('PhotoDescription').innerHTML = this.newDesc;
  		
		jsEffects.fadeIn(this.newImg.id, {inc : 0.1});
	}
}

Ajax.init();

if(xmlHttp)
	Gallery.init();


