// @name: isObject
// @desc: to test if object is an object or not
// @exception: none
// @param: object - object to test
// @depending: none 
function isObject(o) {
  return (typeof(o)=="object");
}

// @name: isArray
// @desc: to test if object is an array or not
// @exception: none
// @param: object - object to test
// @depending: none 
function isArray(o) {
  return (isObject(o) && (o.length) &&(!isString(o)));
}

// @name: isFunction
// @desc: to test if object is a function or not
// @exception: none
// @param: object - object to test
// @depending: none 
function isFunction(o) {
  return (typeof(o)=="function");
}

// @name: isString
// @desc: to test if object is a string or not
// @exception: none
// @param: object - object to test
// @depending: none 
function isString(o) {
  return (typeof(o)=="string");
}


// @name: arrayToUrlString
// @desc: to transform an array to url form with differents parameters of the array
// @exception: if the parameter object isn't an array
// @param: array - array to transform to url form
// @depending: none 
// @example: var tab = new Array(3); |tab['param1']='val1';|tab['param2']='val2';|tab['param3']='val3';|<a href='' onClick='var tab = new Array(3);tab[\'param1\']=\'val1\';tab[\'param2\']=\'val2\';tab[\'param3\']=\'val3\';alert(arrayToUrlString(tab));return false;'>alert(arrayToUrlString(tab));</a>
// @version: 1.0
// @author: E.Qu&eacute;sada
function arrayToUrlString(o){
  if (isArray(o)) {
	var paramStr;
	isFirst = true;
	for (var x in o)
		if (o[x] != null)
		{
			if (isFirst)
			{						
				isFirst = false;
				paramStr=x+'='+o[x];
			} else
				paramStr+='&'+x+'='+o[x];
		}
	return paramStr;
  } else 
	throw 'easyTools.js:function arrayToUrlString() - The object is not an Array';
}

var heightImgCurrent = 200;
var widthImgCurrent = 200;
var heightImgReal = 0;
var widthImgReal = 0;

var toDoWidth = true;
var toDoHeight = true;
var orderWidth  = 1; // -1 pour reduire
var orderHeight = 1; // -1 pour reduire
var urlGlobal = null;
var addVal = 40;
var cur = null;
var bodyHalfWidth ;
var bodyHalfHeight ;
var time = 5;

// @name: visible
// @desc: to display a picture
// @exception: none
// @param: string - picture url , string - div id that will be created 
// @depending: none 
// @version: 1.0
// @author: E.Qu&eacute;sada
function visible(url,id,width,height){
	if (document.getElementById) {
		// on met la div a l'echelle
		if (urlGlobal == url) {			
			
			if (toDoWidth) { // on s'occupe de la largeur
				if  ( ( widthImgReal    <= widthImgCurrent ) &&
					  ( widthImgCurrent <= (widthImgReal + 2 * addVal) ) )
					toDoWidth = false;
				else {
					widthImgCurrent+= orderWidth * addVal;
					cur.style.left = bodyHalfWidth - widthImgCurrent/2;
					cur.style.width = widthImgCurrent ;	
					setTimeout("visible('"+url+"','"+id+"',0,0)",time);
					return;
				}
			} 
			
			if (toDoHeight) { // on s'occupe de la hauteur
				if  ( ( heightImgReal    <= heightImgCurrent ) &&
					  ( heightImgCurrent <= (heightImgReal + 2 * addVal) ) )
					toDoHeight = false;
				else {
					heightImgCurrent+= orderHeight * addVal;
					cur.style.top  = 400 - heightImgCurrent/2;
					cur.style.height = heightImgCurrent ;	
					setTimeout("visible('"+url+"','"+id+"',0,0)",time);
					return;
				}
			} 		

			if ( (!toDoWidth) && (!toDoHeight)) {
				toDoWidth = true;
				toDoHeight = true;
				cur.innerHTML = '<img id="'+id+'IMG" style="filter:alpha(opacity=100);opacity:1;" onClick="invisible('+"'"+id+"'"+');" src="'+url+'"/>';
				return;
			}
			
		} else {
			
			if (cur == null) {	// premier lancement		
				bodyHalfWidth  = document.body.offsetWidth / 2;
				bodyHalfHeight = document.body.offsetHeight / 2;
			
				masque = document.createElement('div');
				masque.id = "masque";
				document.body.appendChild(masque);
			
				heightImgReal = height;
				widthImgReal = width;		

				if (heightImgReal >  heightImgCurrent)
					orderHeight = 1; 
				else if (heightImgReal < heightImgCurrent)
					orderHeight = -1; 
				else
					toDoHeight = false;

				if (widthImgReal >  widthImgCurrent)
					orderWidth = 1; 
				else if (widthImgReal <  widthImgCurrent)
					orderWidth = -1; 
				else
					toDoWidth = false;

				element = document.createElement('div');
				element.id = id;
				element.style.height = heightImgCurrent ;
				element.style.width = widthImgCurrent ;				
				element.style.top  = 400 - heightImgCurrent/2;
				element.style.left = bodyHalfWidth - widthImgCurrent/2;				
				document.body.appendChild(element);
				cur = document.getElementById(id);
				urlGlobal = url;
				setTimeout("visible('"+url+"','"+id+"',0,0)",time);
				return;
			} else { // on veut changer d'image
				//todo
			}
		}
	
	}
 }
 
 function centerElem(element) {
	var height=document.getElementById(element).offsetHeight;//hauteur de l'élément à positionner
	var width=document.getElementById(element).offsetWidth;//largeur de l'élément à positionner
	myParent=document.getElementById(element).parentNode;
	var pHeight=myParent.offsetHeight;//Hauteur de l'élément parent
	var pWidth=myParent.offsetWidth;//Largeur de l'élément parent
	var sTop=myParent.scrollTop;//Hauteur de défilement de l'élément parent
	var sLeft=myParent.scrollLeft;//Longueur de défilement de l'élément parent
	var posY=(pHeight/2)-(height/2)+sTop;//Calcul de la position en Y
	var posX=(pWidth/2)-(width/2)+sLeft;//Calcul de la position en X
	document.getElementById(element).style.top=posY+"px";
	document.getElementById(element).style.left=posX+"px";
}
 
// @name: invisible
// @desc: to hide  a picture
// @exception: none
// @param:  string - div id that will be hidden 
// @depending: none 
// @version: 1.0
// @author: E.Qu&eacute;sada
function invisible(id){
	vitesseIE=1;
	vitesseFF=10;
	if(document.getElementById) {
		img=document.getElementById(id+'IMG');
		if (document.all) {
			img.filters.alpha.opacity = img.filters.alpha.opacity - 3;
			if (img.filters.alpha.opacity==0) {
				cur = null;
				urlGlobal = null;
				masque=document.getElementById('masque');
				document.body.removeChild(masque);
				img=document.getElementById(id);
				document.body.removeChild(img);
				return;
			} else
				setTimeout("invisible('"+id+"')",vitesseIE);
		} else {
			i=parseFloat(img.style.opacity );
			i-=parseFloat(0.3);
			img.style.opacity = i;
			if (i<=0)
			{
				cur = null;
				urlGlobal = null;
				masque=document.getElementById('masque');
				document.body.removeChild(masque);
				img=document.getElementById(id);
				document.body.removeChild(img);
				return;
			}
			else
				setTimeout("invisible('"+id+"')",vitesseFF);
		}
	}
}

