//	SpriteManager for JavaScript	Release 3	2004/6/4
//			Copyright 2004 Isawo-Kikuchi All rights reserved

var spriteid = 0;
function Sprite( pattern, plane, width, height, position ) {
	this.id = "sp"+spriteid++;
	this.patnum = pattern;
	this.planum = plane;
	this.pat = new Array( pattern );
	for( var i=0; i<pattern; i++ ){
		this.pat[i] = new Image;
		this.pat[i].src = null;
	}
	this.pla = new Array( plane );
	for( var i=0; i<plane; i++ ) this.pla[i] = -1;
	document.write( "<div id=\""+this.id+"\" style=\"position:"+position+";left:0px;top:0px;width:"+width+"px;height:"+height+"px;overflow:hidden;\">" );
	for( var i=plane-1; i>=0; i-- ){
		document.write( "<img id=\""+this.id+"pl"+i+"\" style=\"position:absolute;visibility:hidden;\">" );
	}
	document.write( "</div>" );
	this.moveframe = function( x, y ){
		var node = document.getElementById( this.id ).style;
		node.left = x+"px";
		node.top = y+"px";
	}
	this.define = function( patno, filename ){
		this.pat[patno].src = filename;
		for( var i=0; i<this.planum; i++ ){
			if( this.pla[i]==patno ) document.getElementById( this.id+"pl"+i ).src = this.pat[patno].src;
		}
	}
	this.set = function( plano, patno ){
		var node = document.getElementById( this.id+"pl"+plano );
		node.src = this.pat[patno].src;
		this.pla[plano] = patno;
		if( this.pat[patno].width>0 ){
			node.style.width = this.pat[patno].width+"px";
			node.style.height = this.pat[patno].height+"px";
		}
	}
	this.move = function( plano, x, y ){
		var node = document.getElementById( this.id+"pl"+plano ).style;
		node.left = x+"px";
		node.top = y+"px";
	}
	this.moveset = function( plano, x, y, patno ){
		var node = document.getElementById( this.id+"pl"+plano );
		node.src = this.pat[patno].src;
		node.style.left = x+"px";
		node.style.top = y+"px";
		this.pla[plano] = patno;
		if( this.pat[patno].width>0 ){
			node.style.width = this.pat[patno].width+"px";
			node.style.height = this.pat[patno].height+"px";
		}
	}
	this.show = function( n1, n2 ){
		for( var i=n1; i<=n2; i++ ){
			document.getElementById( this.id+"pl"+i ).style.visibility = "visible";
		}
	}
	this.hide = function( n1, n2 ){
		for( var i=n1; i<=n2; i++ ){
			document.getElementById( this.id+"pl"+i ).style.visibility = "hidden";
		}
	}
	this.resize = function( plano, width, height ){
		var node = document.getElementById( this.id+"pl"+plano ).style;
		node.width = width;
		node.height = height;
	}
	this.offsetx = function(){
		return parseInt(document.getElementById( this.id ).offsetLeft);
	}
	this.offsety = function(){
		return parseInt(document.getElementById( this.id ).offsetTop);
	}
	this.display = function( disp ){
		document.getElementById( this.id ).style.display = disp?"":"none";
	}
	this.backgroundImage = function( filename ){
		document.getElementById( this.id ).style.backgroundImage = "url("+filename+")";
	}
	this.backgroundColor = function( color ){
		document.getElementById( this.id ).style.backgroundColor = color;
	}
	this.isPatternLoadComplete = function(){
		for( var i=0; i<this.patnum; i++ ){
			if( this.pat[i].src!=null && this.pat[i].complete==false ){
				return false;
			}
		}
		return true;
	}
}
