/*****************************************************/
/**						BANNER						**/
/*****************************************************/
function Banner(name,w,h){
	this.alive=true;
	this.sleep=20;
	this.w=w;
	this.h=h;
	this.dx=25;
	this.dy=25;
	this.immagineDaMuovere=-1;
	
	this.name=name;
	this.images=new Array();
	this.addImg=addImg;
	this.print=printBanner;
	this.run=runBanner;
}

function addImg(path,xFrom,yFrom,xTo,yTo){
	var i = new Immagine(path,xFrom,yFrom,xTo,yTo);
	this.images.push(i);
}
function printBanner(){
	document.write("<iframe name=\"myIframe\" style=\"width: "+this.w+"px;height: "+this.h+"px;\"  frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" scrolling=\"no\"></iframe>");
	var result = "<html>\n<head></head>\n<body>\n";
	for(var i=0;i<this.images.length;i++){//
		result+="<img src=\""+this.images[i].path+"\" style=\"position: absolute;left: "+this.images[i].x+"px; top: "+this.images[i].y+"px;\" id=\"i"+i+"\">\n";
	}
	result+="</body>\n</html>";
	myIframe.document.write(result);
	for(var i=0;i<this.images.length;i++){
		this.images[i].img=myIframe.document.getElementById("i"+i);
	}
	myIframe.document.close();
}
function runBanner(){
	if(this.immagineDaMuovere==-1){
		this.immagineDaMuovere++;
		this.images[this.immagineDaMuovere].img.style.visibility="visible";
	}
	if(!this.images[this.immagineDaMuovere].arrivato()){
		this.images[this.immagineDaMuovere].moveImmagine(this.dx,this.dy);
	}else if(this.immagineDaMuovere<this.images.length-1){
		this.immagineDaMuovere++;
		this.images[this.immagineDaMuovere].img.style.visibility="visible";
		this.images[this.immagineDaMuovere].moveImmagine(this.dx,this.dy);
	}else{
		this.alive=false;
	}
}
/*****************************************************/
/**						IMMAGINE					**/
/*****************************************************/
function Immagine(path,xFrom,yFrom,xTo,yTo){
	this.path=path;
	this.img;
	this.x=xFrom;
	this.y=yFrom;
	this.xTo=xTo;
	this.yTo=yTo;
	this.moveImmagine=moveImmagine;
	this.arrivato=arrivatoImmagine;
}
function moveImmagine(dx,dy){
	if(this.x>this.xTo){dx=-Math.abs(dx);}else{dx=Math.abs(dx);}
	if(this.y>this.yTo){dy=-Math.abs(dy);}else{dy=Math.abs(dy);}	
	this.x+=dx;
	this.y+=dy;
	if(dx<0&&this.x<this.xTo){this.x=this.xTo;}
	if(dx>0&&this.x>this.xTo){this.x=this.xTo;}
	if(dy<0&&this.y<this.yTo){this.y=this.yTo;}
	if(dy>0&&this.y>this.yTo){this.y=this.yTo;}
	this.img.style.left=this.x+"px";
	this.img.style.top=this.y+"px";
}
function arrivatoImmagine(){
	return this.x==this.xTo && this.y==this.yTo;
}
