var hoverClass = 'hover';
var deltaY = 440;//280;

var iC = null;
var currentRow = null;

function ImageInfo(iiK)
{
	if(testTypeOfObject(iiK,'string'))
	{
		this._key = iiK;
	}
	this._uri = '';
	this._contact = '';
	this._image = new Image();
	
	this.setUri = function(u)
	{
		if(testTypeOfObject(u,'string'))
		{
			this._uri = u;
		}
	}
	
	this.loadImage = function()
	{	
		if(this._uri != '')
		{
			this._image.src = this.getUri();
		}
	}
	
	this.setContact = function(c)
	{
		if(testTypeOfObject(c,'string'))
		{
			this._contact = c;
		}
	}
	
	this.getKey = function()
	{
		return this._key;
	}
	
	this.getUri = function()
	{
		return this._uri;
	}
	
	this.getContact = function()
	{
		return this._contact;
	}
	
	this.getImageSrc = function()
	{
		return this._image.src;
	}
}

function ImageCollection()
{
	this._collection = new Array();
	
	this.appendImage = function(img)
	{
		if(testTypeOfObject(img,ImageInfo))
		{
			this._collection[this._collection.length] = img;
		}
	}
	
	this.getImageByKey = function(k)
	{
		var rtO = null;
		
		for(var i=0; i<this._collection.length; i++)
		{
			if(this._collection[i].getKey() == k)
			{
				rtO = this._collection[i];
				break;
			}
		}
		
		return rtO;
	}
	
	this.getImageCollection = function()
	{
		return this._collection;
	}
}

function addImage(iObj)
{
	if(iC == null)
	{
		iC = new ImageCollection();
	}
	
	iC.appendImage(iObj);
}

function displayInfo()
{
	var cObj = getObjectFromEvent(arguments[0]);
	
	if(isInitialized(cObj))
	{
		var ln = getAncestorElement(cObj,'tr');
		
		if(isInitialized(ln))
		{
			addClassName(ln,hoverClass);
			
			if(currentRow != null)
			{
				removeClassName(currentRow,hoverClass);
			}
			
			currentRow = ln;
			
			if(iC != null)
			{
				var coord = getCursorDocumentCoordinate(arguments[0]);
				
				var dispZone = document.getElementById('data-info');
				
				if(isInitialized(dispZone))
				{
					var dataId = ln.id;
					
					var imgData = iC.getImageByKey(dataId);
					//alert(imgData);
					if(imgData != null)
					{
						removeAllNode(dispZone);
						
						if(imgData.getImageSrc() != '')
						{
							var pVis = document.createElement('p');
							addClassName(pVis,'visuel-info');
							
							var imgVis = document.createElement('img');
							imgVis.src = imgData.getImageSrc();
							imgVis.alt = '';
							
							pVis.appendChild(imgVis);
							dispZone.appendChild(pVis);
						}
						
						var pC = document.createElement('p');
						pC.appendChild(document.createTextNode('Contact : '+imgData.getContact()));
						dispZone.appendChild(pC);
						
						setObjectCoordinateY(dispZone,coord.getCoordinateY()-deltaY);
					}
				}
			}
		}
	}
}

function initInfo()
{
	if(dhtmlLoad && document.getElementById)
	{
		var dC = document.getElementById('data-calendrier');
		
		if(isInitialized(dC))
		{
			var ligne = dC.getElementsByTagName('tr');
			
			var lnCount = ligne.length;
			
			for(var i=0; i<lnCount; i++)
			{
				addEvent(ligne[i],'mouseover',displayInfo);
			}
			
			if(iC != null)
			{
				var iList = iC.getImageCollection();
				
				for(var i=0; i<iList.length; i++)
				{
					iList[i].loadImage();
				}
			}
		}
		var cnt = document.getElementById('corps-page');
		var h = getObjectDimension(cnt);
		//alert(h.getDimensionY());
	}
}

if(window.addOnloadFunction)
{
	addOnloadFunction(initInfo);
}
/*
if(window.Prototype)
{
	//document.observe('dom:loaded',initInfo);
	Element.observe(document,'dom:loaded',initInfo);
}*/
