// JavaScript Document

var iPhotoPlayer = { sec : 2 , playing : false , interval : null , 
	frameWidth : 0 , frameHeight : 0 };

iPhotoPlayer.init = false;
iPhotoPlayer.pointer = 0;



iPhotoPlayer.badgeInit = function()
{
	if ( self.innerWidth )
	{
		this.frameWidth = self.innerWidth;
		this.frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		this.frameWidth = document.documentElement.clientWidth;
		this.frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		this.frameWidth = document.body.clientWidth;
		this.frameHeight = document.body.clientHeight;
	}
	
	idlist = document.getElementById("ImageIDList").innerHTML;
	var string = "this.IDArray = new Array("+idlist+"0);";
	eval(string);
	//alert(this.IDArray.length);

	
}

iPhotoPlayer.badgePlay = function()
{
	if( ! this.init ) this.badgeInit();	

	if( this.playing )
	{
		document.getElementById("btnPLAY").innerHTML = "Play";
		this.playing = false;
		clearTimeout(this.interval);
	}
	else
	{
		//document.getElementById("btnPLAY").innerHTML = "Pause";		
		this.playing = true;
		this.display();
	}
}

iPhotoPlayer.display = function()
{

	document.getElementById("iPHOTO" + this.IDArray[this.pointer]).className = "onShow";	
	this.showImage( this.IDArray[this.pointer] );		
}

iPhotoPlayer.showImage = function( id )
{
	if( ! this.init ) this.badgeInit();	

	var cover = document.getElementById("iPhotoCover");
	if( !cover )
	{
		cover = document.createElement("div");
	
		cover.id = "iPhotoCover";	
		document.body.appendChild(cover);		
	}
	//document.getElementById("Container").style.display = "none";
	//document.body.scrolling="no";
	//alert(document.body.);	

	var scrOfX = 0, scrOfY = 0;

	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}

	cover.style.height = document.body.scrollHeight + "px";
	cover.style.width = (this.frameWidth - 20 ) + "px";
	cover.style.top = "0px"; //scrOfY + "px" ;	
	cover.style.display = "block";	
	
	var block = document.getElementById("iPhotoBlock");
	
	if( !block )
	{
		block = document.createElement("div");	
		block.id = "iPhotoBlock";	
		document.body.appendChild(block);	
	}
	
	block.innerHTML = "<img src='images/ajax/ajax-loader.gif' style='margin-top:200px;' />";
	
	block.style.top = scrOfY + "px" 	
	block.style.display = "block";	
	
	var url = "gallery.php?ajax=image&id="+id+"&cache=" + ( new Date()).getTime();

	Ajax.Request( url , { complete : function( httpObj )
		{
			block.innerHTML = httpObj.responseText;
			if( iPhotoPlayer.playing == true )
			{
				iPhotoPlayer.interval = setTimeout("iPhotoPlayer.badgeNext()", iPhotoPlayer.sec * 1000 );
			}			
		}
	} );
	

}

iPhotoPlayer.badgeNext = function()
{
	if( ! this.init ) this.badgeInit();	

	var id = this.IDArray[this.pointer];
	document.getElementById("iPHOTO" + id).className = "";
	this.pointer++;
	if( this.pointer >= this.IDArray.length -1) 
		this.pointer = 0;

	clearTimeout(this.interval);
	this.display();
}

iPhotoPlayer.badgePrevious = function()
{
	if( ! this.init ) this.badgeInit();	

	var id = this.IDArray[this.pointer];
	document.getElementById("iPHOTO" + id).className = "";	
	this.pointer--;
	if( this.pointer < 0) 
		this.pointer = this.IDArray.length-2 ;	

	clearTimeout(this.interval);
	this.display();
}

iPhotoPlayer.close = function()
{
	var cover = document.getElementById("iPhotoCover");
	var block = document.getElementById("iPhotoBlock");	
	
	cover.style.display = "none";
	block.style.display = "none";
	block.innerHTML = "";
	this.playing = false;
	clearTimeout(this.interval);
}

iPhotoPlayer.setImage = function( url )
{
	document.getElementById("ImageSrc").src = url;		
}