/*												 
-------------------------------------------------------------------------------------------
	Copyright (c) Intersel 2007-2008 - Tous droits réservés 
-------------------------------------------------------------------------------------------
   	INTERSEL - SARL au capital de 12.000 € - RCS PARIS 488 379 660 - NAF 721Z 
	4 Cité d'Hauteville
	75010 PARIS  
-------------------------------------------------------------------------------------------
	File : pictos-viewer
	
	Abstract : 	  shows pictos in sequence
			(used to manage the visualisation of the partner and member pictos in the home page)
	Author : Emmanuel PODVIN - emmanuel.podvin@intersel.org - copyright Intersel 2008
	Modifications :
		- 12/01/08 - EPO - Creation
   ------------------------------------------------------------------------------------------- 
inspired from "visionneuse d'images"
Script :  http://www.jejavascript.net/visionn.php
//PLF-http://www.jejavascript.net/

*/

/*--------------------------------------------------------------------
//	Function name : pictos_viewer
//	Description		: 	Class Object - Object managing the display of picto in an IMG object
//	input 			:					   
//  return value 	: an Object 
//--------------------------------------------------------------------	   
*/	 
								  
var AutoDisplay_Interval=4000; //delay to display the next picto 
var AutoDisplay_StartAutoDisplayDelay=7000; // delay before starting the autodisplay	
var DebugDivId=''; // div where we can put some debug message

// internal variables
var GlobalTimers  = new Array(); // timers set
var GlobalViewers = new Array(); // picto viewers object

function pictos_viewer(aPictoObjectId,aPictoURLObjectId,aFileDir,aPictoFilenamesArray) 
{
	this.directory=aFileDir;
	this.PictoId = 0;	
	this.length = aPictoFilenamesArray.length;
	this.PictoFilenames=aPictoFilenamesArray; 
	this.PictoObjectId=aPictoObjectId;
	this.PictoURLObjectId=aPictoURLObjectId;			//@add by MP
	this.PictoObject=TrouveObjet(aPictoObjectId);
	GlobalViewers[this.PictoObjectId]=this;	

	
	this.InitStartAutoDisplay();
	
	AppendInnerHtml(DebugDivId,this.PictoObjectId+' '+this.length);//debug message
}

// Class Public function definitions
pictos_viewer.prototype.GoNextPicto = function() 
{	 
	this.InitStartAutoDisplay(); 	 
	this.nextPicto(); 	 

	AppendInnerHtml(DebugDivId,'ClickNext');//debug message
	
}	
		
pictos_viewer.prototype.GoPreviousPicto = function() 
{
	this.InitStartAutoDisplay(); 	 
	this.previousPicto(); 	 

	AppendInnerHtml(DebugDivId,'ClickNext');//debug message
	
}
		
// Class private function definitions
pictos_viewer.prototype.nextPicto = function() 
{	 
	this.PictoId += 1;
	if (this.PictoId >= this.length ) this.PictoId = 0;
	this.ShowPicto(); 	 

	AppendInnerHtml(DebugDivId,this.PictoId);//debug message
	
}	
		
pictos_viewer.prototype.previousPicto = function() 
{
	this.PictoId -= 1;
	if (this.PictoId < 0) this.PictoId = this.length-1;
	this.ShowPicto(); 			
	
	AppendInnerHtml(DebugDivId,this.PictoId);//debug message
}
		
pictos_viewer.prototype.ShowPicto = function() 
{

	var anImgObj = $(this.PictoObject);
	var anURLObj = $(this.PictoURLObjectId);								//@add by MP
	var imgEffect = anImgObj.effect('opacity', {duration: 200});  
	var NextPicto = this.directory+'/'+this.PictoFilenames[this.PictoId];
	var urlRE=/^(http:\/\/)([a-zA-Z0-9]+\.?)+\.([-a-zA-Z0-9]+)/;			//@add by MP
	var posExt = (this.PictoFilenames[this.PictoId]).lastIndexOf(".");		//@add by MP
    var url = (this.PictoFilenames[this.PictoId]).substring(0, posExt);		//@add by MP
	
	if (urlRE.test("http://" + url))
		anURLObj.href='http://'+url;										//@add by MP
	else
		anURLObj.href='#';
		
	imgEffect.start(0).chain(function()
								{
								anImgObj.src = NextPicto;
								imgEffect.start(1); 			
								}
							);

function testURL(url){

return urlRE.test(url);
}
							
							
							
//	this.PictoObject.src = this.directory+'/'+this.PictoFilenames[this.PictoId];

	AppendInnerHtml(DebugDivId,this.PictoObject.src);//debug message
}
		
pictos_viewer.prototype.InitStartAutoDisplay = function() 
{
	AppendInnerHtml(DebugDivId,'InitStartAutoDisplay: '+this.PictoObjectId);//debug message

	this.PictoId--;//in order to cancel StartAuto/nextPicto... 
	this.StartAuto(AutoDisplay_StartAutoDisplayDelay);
	
}
		
pictos_viewer.prototype.StartAuto = function(TimeOutDelay) 
{
	AppendInnerHtml(DebugDivId,'StartAuto: '+this.PictoObjectId);//debug message

	this.nextPicto();
	if (GlobalTimers[this.PictoObjectId]!=null) window.clearTimeout(GlobalTimers[this.PictoObjectId]);													   
	GlobalTimers[this.PictoObjectId]=setTimeout("StartAutoDisplayPicto('"+this.PictoObjectId+"')", TimeOutDelay);
	
}
		
function StartAutoDisplayPicto(aPictoId)
{
	AppendInnerHtml(DebugDivId,aPictoId);//debug message
	GlobalViewers[aPictoId].StartAuto(AutoDisplay_Interval);
}
	
//------------- end class pictos_viewer  ------------------

/*
function initPicto()
{
	pictoList = new Array ("logo_caisse_gros.jpg", "logo_total.gif", "orange.gif");	  
	MyViewer = new pictos_viewer('PictoMember','../images/pictos-membres/', pictoList);
	MyViewer2 = new pictos_viewer('PictoMember2','../images/pictos-membres/', pictoList);
}
 */