/*!
   DIV Move Manager : Javascript move objet DIV for the Web
   --------------------------------------------

   Copyright (c) 2008, Jean-Claude Gagnerot. All rights reserved.
   Code licensed under the BSD License:

   Version 1.0.0
*/
function DivMove()
{
	this.ListObjet = new Array();
	this.versionName = 'DIV Move Manager';
	this.versionNumber = 'V1.0.0';
	this.Runig = false;

	this.Timer = function() 
	{ 
		if(this.Runig)
		{
			var index = 0;
			var id = 0;
			
			for (index in this.ListObjet)
			{
				
				if(this.ListObjet[index][5] == 0) // Droite à Gauche
				{
					this.ListObjet[index][4] += 5;
					
					if(this.ListObjet[index][4] > this.ListObjet[index][7])
					{
//						this.ListObjet[index][4] = 0;
						this.ListObjet[index][5] = 1;
					}
					id = document.getElementById("DIV" + this.ListObjet[index][0]);
					id.style.left = this.ListObjet[index][4] + "px";
				}
				
				if(this.ListObjet[index][5] == 1) // Gauche à Droite
				{
					this.ListObjet[index][4] -= 5;
					
					if(this.ListObjet[index][4] < this.ListObjet[index][6])
					{
//						this.ListObjet[index][4] = 80;
						this.ListObjet[index][5] = 0;
					}
					id = document.getElementById("DIV" + this.ListObjet[index][0]);
					id.style.left = this.ListObjet[index][4] + "px";
				}
				
			}
		}
		
	} 
	
	this.Play = function() 
	{     
		this.Runig = true;
	} 
	
	this.Stop = function() 
	{     
		this.Runig = false;
	} 
	
	this.AddOrientation = function(Orientation) 
	{     
	} 
	
	this.GetOrientation = function(Orientation) 
	{     
	} 
	
	this.SetSize = function(name, h, l) 
	{     
		var index = 0;
		for (index in this.ListObjet)
		{
			if(this.ListObjet[index][0] == name)
			{
				id = document.getElementById("DIV" + this.ListObjet[index][0]);
			    id.style.width = l + "px";
			    id.style.height = h + "px";
				
				id = document.getElementById("IMG" + this.ListObjet[index][0]);
			    id.width = l;
			    id.height = h;
			}
		}
	} 
	
	this.SetPosition = function(name, x, y) 
	{     
		var index = 0;
		for (index in this.ListObjet)
		{
			if(this.ListObjet[index][0] == name)
			{
				id = document.getElementById("DIV" + this.ListObjet[index][0]);
			    id.style.left = x + "px";
			    id.style.top = y + "px";
				
				id = document.getElementById("IMG" + this.ListObjet[index][0]);
			    id.left = x;
			    id.top = y;
			}
		}
	} 
	
	this.GetPosition = function(name) 
	{     
		var index = 0;
		for (index in this.ListObjet)
		{
			if(this.ListObjet[index][0] == name)
			{
				id = document.getElementById("DIV" + this.ListObjet[index][0]);
				Pos = new Array();
				Pos[0] = id.style.left;
				Pos[1] = id.style.top;
				return Pos;
			}
		}
	} 
	
	
	this.AddPosition = function(name, x, y, o) 
	{
		Orientation = new Array();
		Orientation[0] = Name;
		Orientation[1] = Name;
		Orientation[2] = Pos;
		
		var index = 0;
		var lo = 0;
		
		for (index in this.ListObjet)
		{
			if(this.ListObjet[index][0] == name)
			{
//				lo = this.ListObjet[index][6]);
//				lo[lo.length] = Orientation;
			}
		}
	} 
	
	this.Show = function(name, show) 
	{
		var index = 0;
		var id = 0;
		
		for (index in this.ListObjet)
		{
			if(this.ListObjet[index][0] == name)
			{
				id = document.getElementById("DIV" + this.ListObjet[index][0]);
				if(show)
					id.style.display = 'block';
				else
					id.style.display = 'none';
			}
		}
	} 
	


	this.Add = function(Name, Timer, UrlImage, TypeMove, Start, Limite) 
	{     
//		Pos = new Array('X','Y');
//		Size = new Array('H','L');
		Size = new Array();
		Size[0] = 10;
		Size[1] = 10;

		ListOrientation = new Array();


//		Array('Name','Id','Image','Timer','Orientation','Cur_Pos','Cur_Orientation' );
		Child = new Array();
		Child[0] = Name;
		Child[1] = UrlImage;
		Child[2] = Timer;
		Child[3] = ListOrientation;
		Child[4] = 0;
		Child[5] = TypeMove;
		Child[6] = Start;
		Child[7] = Limite;

//		Array('Next','Previow','Bas','Haut');

		var str = "<div align='left' style='position:absolute;top:0px;left:0px;' id='DIV" + Name + "'><img id='IMG" + Name + "' src='" + UrlImage + "' /></div>";
		document.open();
		document.write( str );
		document.close();
		
		this.ListObjet[this.ListObjet.length] =  Child;
		return true;
	} 	
}