/*
############################################################
##
##	VAR
##
############################################################
*/

var xmlPPDiaporama = new Array();
var postionPPDiaporama = 1;

/*
############################################################
##
##	SHOW POPUP DIAPORAMA
##
############################################################
*/

function creatPPDiaporama(CFG_SERVEUR_FILE_THEME, CFG_DESCRIPTION)
{
	var html = '';
		html += '<img id="ppdiaporama_picture" src="" width="800" height="534" />';
		html += '<div id="ppdiaporama_preview"><a href="javascript:previewPPDiaporama();"><img src="' + CFG_SERVEUR_FILE_THEME + 'picture/ppdiaporama/preview.png" width="80" height="29" /></a></div>';
		html += '<div id="ppdiaporama_next"><a href="javascript:nextPPDiaporama();"><img src="' + CFG_SERVEUR_FILE_THEME + 'picture/ppdiaporama/next.png" width="80" height="29" /></a></div>';
		html += '<div id="ppdiaporama_counter"></div>';
		html += '<div id="ppdiaporama_close"><a href="javascript:displayPPDiaporama(\'hidden\');"><img src="' + CFG_SERVEUR_FILE_THEME + 'picture/ppdiaporama/close.jpg" width="70" height="20" /></a></div>';
	
	if(CFG_DESCRIPTION == true)
	{
		if(CFG_NAME == true)
		{
			html += '<div id="ppdiaporama_description"><h1></h1><p></p></div>';
		}
		else
		{
			html += '<div id="ppdiaporama_description"></div>';
		}
	}	
	
	document.getElementById('ppdiaporama').innerHTML = html;
}

function movePPDiaporama()
{
	Width = document.body.clientWidth;
	Height = document.body.clientHeight;
	X = document.documentElement.scrollLeft;
  	Y = document.documentElement.scrollTop;
	document.getElementById("mask").style.height = "100%";
	document.getElementById("mask").style.top = (Y)+"px";
	document.getElementById("ppdiaporama").style.top = "10%";
	
	setTimeout("movePPDiaporama()",1);
}

function displayPPDiaporama(visibility)
{
	if(visibility == 'visible')
	{
		document.getElementById("mask").style.visibility = "visible";
		document.getElementById("ppdiaporama").style.visibility = "visible";
		movePPDiaporama();
	}
	else
	{
		document.getElementById("ppdiaporama").innerHTML = "";
		document.getElementById("ppdiaporama").style.visibility = "hidden";
		document.getElementById("mask").style.visibility = "hidden";
	}
}

function showPPDiaporama()
{
	displayPPDiaporama('visible');
	document.getElementById('ppdiaporama_picture').src = xmlPPDiaporama[postionPPDiaporama]['picture'];
	document.getElementById("ppdiaporama_counter").innerHTML = postionPPDiaporama + ' / ' + (xmlPPDiaporama.length-1);
	/*
	document.getElementById("teste").innerHTML += xmlPPDiaporama.length + '<br/>';
	*/
}

function previewPPDiaporama()
{
	newPosition = (postionPPDiaporama - 1);
	
	if(newPosition > 0)
	{
		postionPPDiaporama = (postionPPDiaporama - 1);
		document.getElementById("ppdiaporama_counter").innerHTML = newPosition + ' / ' + (xmlPPDiaporama.length-1);
		document.getElementById('ppdiaporama_picture').src = xmlPPDiaporama[newPosition]['picture'];
	}
}

function nextPPDiaporama()
{
	newPosition = (postionPPDiaporama + 1);
	
	if(newPosition <= (xmlPPDiaporama.length-1))
	{
		postionPPDiaporama = (postionPPDiaporama + 1);
		document.getElementById("ppdiaporama_counter").innerHTML = newPosition + ' / ' + (xmlPPDiaporama.length-1);
		document.getElementById('ppdiaporama_picture').src = xmlPPDiaporama[newPosition]['picture'];
	}
}

/*
############################################################
##
##	LOAD FILE XML FOR DIAPORAMA
##
############################################################
*/

function loadPPDiaporama(xmlFile, picturePosition, CFG_SERVEUR_FILE_THEME, CFG_NAME, CFG_DESCRIPTION)
{
	postionPPDiaporama = picturePosition;
	creatPPDiaporama(CFG_SERVEUR_FILE_THEME, CFG_NAME, CFG_DESCRIPTION);
	
	if(xmlPPDiaporama.length <= 0)
	{
		http[2] = httpRequest();
		http[2].open("GET", xmlFile, true);
		http[2].onreadystatechange = loadXmlPPDiaporama;
		http[2].send(null);
	}
	else
	{
		showPPDiaporama();
	}
}

function loadXmlPPDiaporama()
{
	if (http[2].readyState == 4)
	{
		
		try
		{
			xml = http[2].responseXML;
			
			if (http[2].responseText == "")
			{
				return false;
			}
			else
			{
				var xmlName = xml.getElementsByTagName('Name');
				var xmlPicture = xml.getElementsByTagName('Picture');
				var xmlDescription = xml.getElementsByTagName('Description');
			}
			
		}
		catch(e)
		{
			
			return false;		
		}
		
		var name;
		var picture;
		var description;
		
		for (var i=1; i<=xmlName.length; i++)
		{
			try
			{	
				name = xmlName[(i-1)].firstChild.data;
				picture = xmlPicture[(i-1)].firstChild.data;
				description = xmlDescription[(i-1)].firstChild.data;
				
				xmlPPDiaporama[i] = new Array();
				xmlPPDiaporama[i]['name'] = name;
				xmlPPDiaporama[i]['picture'] = picture;
				xmlPPDiaporama[i]['description'] = description;
								
			}
			catch(e)
			{
			
			}
		}
		
		showPPDiaporama();
	}
}

/*
############################################################
##
##	HTML,CSS
##
############################################################
*/

/*
#mask{ position: absolute;top: 0px;left: 0px;height: 100%;width: 100%;background:url(../picture/mask/background.png) repeat top left;visibility: hidden; }

#ppdiaporama{ position: absolute;top: 10%;left: 22%;width: 800px;height: 564px;visibility: hidden;border-top: 1px solid #c4c4c4;border-left: 1px solid #c4c4c4;border-right: 1px solid #c4c4c4;border-bottom: 1px solid #c4c4c4;background: #ffffff;padding: 10px 10px 10px 10px; }
#ppdiaporama_counter{ float: left;width: 400px;height: 20px;margin-top: 5px;line-height: 20px; }
#ppdiaporama_preview{ position: absolute;top: 50px;left: 10px;}
#ppdiaporama_next{ position: absolute;top: 50px;right: 10px; }
#ppdiaporama_close{ float: right;width: 70px;height: 20px;margin-top: 5px; }
*/

/*
<div id="mask"></div>
<div id="ppdiaporama">
	<img id="ppdiaporama_picture" src="" width="800" height="534" />
	<div id="ppdiaporama_preview"><a href="javascript:previewPPDiaporama();"><img src="<?PHP echo CFG_SERVEUR_FILE_THEME.'picture/ppdiaporama/preview.png'; ?>" width="80" height="29" /></a></div>
	<div id="ppdiaporama_next"><a href="javascript:nextPPDiaporama();"><img src="<?PHP echo CFG_SERVEUR_FILE_THEME.'picture/ppdiaporama/next.png'; ?>" width="80" height="29" /></a></div>
	<div id="ppdiaporama_counter"></div>
	<div id="ppdiaporama_close"><a href="javascript:displayPPDiaporama('hidden');"><img src="<?PHP echo CFG_SERVEUR_FILE_THEME.'picture/ppdiaporama/close.jpg'; ?>" width="70" height="20" /></a></div>
</div>
*/
