//___________________________//
//       JS developer        //
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯//
//            ·^·            //
//         /7\øñø©ë®ø        //
//     · Leonardo Alia ·     //
//  .: ©å§7ø®ø £åßø®ïø§ø :.  //
//___________________________//
//                           //
/************************************************************************************
COSTRUZIONE OGGETTO
************************************************************************************/

function objmove(obj_n,div_n)
{
	/* Proprietà */
	this.obj_n = obj_n; //nome oggetto
	this.div_n = div_n; //nome div
	this.ie = document.all?1:0;
	this.ns6 = document.getElementById&&!document.all?1:0;
	
	this.htmlcode = ""; //codice html da scrivere per creare il div
	this.cont = ""; //contenuto del div
	
	this.mvobj= ""; //id prelevato
	this.postop=1;//numero di pixel per unità di tempo
	this.posleft=1;//numero di pixel per unità di tempo
	
	this.finalxpos=0;//posizione di arrivo
	this.finalypos=0;//posizione di arrivo
	
	this.set_style = set_style; //imposta
	this.move = m_move; //funzione di movimento
	this.ymove = m_ymove; //funzione di movimento Y
	this.xmove = m_xmove; //funzione di movimento X

	this.set_postop = set_postop; //funzione per modificare la velocità verticale
	this.set_posleft = set_posleft; //funzione per modificare la velocità orizzontale
}
/************************************************************************************
METODI
************************************************************************************/

function set_postop(speed){this.postop=speed;}
function set_posleft(speed){this.posleft=speed;}
function set_style(left,top){
        if (this.ie) {
        this.mvobj=eval("document.all."+this.div_n);
        }
        if (this.ns6) {
	this.mvobj=document.getElementById(this.div_n);
        }
        this.mvobj.style.position="absolute";
	this.mvobj.style.left=left+"px";
	this.mvobj.style.top=top+"px";
}
/************************************************************************************
Funzione di Spostamento
************************************************************************************/

function m_move(x,y) {
        if (this.ie) {
        this.mvobj=eval("document.all."+this.div_n);
        }
        if (this.ns6) {
	this.mvobj=document.getElementById(this.div_n);
        }
	var xpos=parseInt(this.mvobj.style.left);
	var ypos=parseInt(this.mvobj.style.top);

	if (xpos<x){this.finalxpos=x;if (this.posleft<0){this.posleft*=-1};this.xmove(0)}
	if (xpos>x){this.finalxpos=x;if (this.posleft>0){this.posleft*=-1};this.xmove(1)}
	if (ypos<y){this.finalypos=y;if (this.postop<0){this.postop*=-1};this.ymove(0)}
	if (ypos>y){this.finalypos=y;if (this.postop>0){this.postop*=-1};this.ymove(1)}

}
function m_xmove(n) {
	var newxpos=parseInt(this.mvobj.style.left)+this.posleft;
	this.mvobj.style.left=newxpos+"px";

	if (n==0){if (newxpos<this.finalxpos){var xtimer=setTimeout(this.obj_n+".xmove(0)",2)}}
	if (n==1){if (newxpos>this.finalxpos){var xtimer=setTimeout(this.obj_n+".xmove(1)",2)}} 
}
function m_ymove(n) {
    	var newypos=parseInt(this.mvobj.style.top)+this.postop;
	this.mvobj.style.top=newypos+"px";

	if (n==0){if (newypos<this.finalypos){var ytimer=setTimeout(this.obj_n+".ymove(0)",2)}}
	if (n==1){if (newypos>this.finalypos){var ytimer=setTimeout(this.obj_n+".ymove(1)",2)}} 
}
