function ChordPrinter( instrumentTop )
{
	this.instrumentTop = instrumentTop;

	this.notesImages = [];
	for( var noteImage = 0; noteImage < 12; noteImage++ )
	{
		this.notesImages[ noteImage ] = new Image( 14, 14 );
		this.notesImages[ noteImage ].src = "images/top_" + noteImage + ".gif";
	}
	
	this.fretBall = [ 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 2, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 2 ]
	
	this.fretImage = [];
	this.fretImage[ 0 ] = new Image( 14, 17 );
	this.fretImage[ 0 ].src = "images/fret_filled.gif";
	this.fretImage[ 1 ] = new Image( 14, 17 );
	this.fretImage[ 1 ].src = "images/fret_1.gif";
	this.fretImage[ 3 ] = new Image( 14, 17 );
	this.fretImage[ 3 ].src = "images/fret_3.gif";
	this.fretImage[ 5 ] = new Image( 14, 17 );
	this.fretImage[ 5 ].src = "images/fret_5.gif";
	this.fretImage[ 7 ] = new Image( 14, 17 );
	this.fretImage[ 7 ].src = "images/fret_7.gif";
	this.fretImage[ 9 ] = new Image( 14, 17 );
	this.fretImage[ 9 ].src = "images/fret_9.gif";
	
	this.fretImage[ 2 ] = this.fretImage[ 0 ];
	this.fretImage[ 4 ] = this.fretImage[ 0 ];
	this.fretImage[ 6 ] = this.fretImage[ 0 ];
	this.fretImage[ 8 ] = this.fretImage[ 0 ];
	this.fretImage[ 8 ] = this.fretImage[ 0 ];
	this.fretImage[ 10 ] = this.fretImage[ 0 ];
	this.fretImage[ 11 ] = this.fretImage[ 0 ];
	this.fretImage[ 12 ] = this.fretImage[ 0 ];
	this.fretImage[ 13 ] = this.fretImage[ 0 ];
				
	this.topFretImage = [];
	this.topFretImage[ 0 ] = new Image( 14, 17 );
	this.topFretImage[ 0 ].src = "images/fret_filled_top.gif";
	this.topFretImage[ 1 ] = new Image( 14, 17 );
	this.topFretImage[ 1 ].src = "images/fret_1_top.gif";
	this.topFretImage[ 3 ] = new Image( 14, 17 );
	this.topFretImage[ 3 ].src = "images/fret_3_top.gif";
	this.topFretImage[ 5 ] = new Image( 14, 17 );
	this.topFretImage[ 5 ].src = "images/fret_5_top.gif";
	this.topFretImage[ 7 ] = new Image( 14, 17 );
	this.topFretImage[ 7 ].src = "images/fret_7_top.gif";
	this.topFretImage[ 9 ] = new Image( 14, 17 );
	this.topFretImage[ 9 ].src = "images/fret_9_top.gif";
	
	this.topFretImage[ 2 ] = this.topFretImage[ 0 ];
	this.topFretImage[ 4 ] = this.topFretImage[ 0 ];
	this.topFretImage[ 6 ] = this.topFretImage[ 0 ];
	this.topFretImage[ 8 ] = this.topFretImage[ 0 ];
	this.topFretImage[ 10 ] = this.topFretImage[ 0 ];
	this.topFretImage[ 11 ] = this.topFretImage[ 0 ];
	this.topFretImage[ 12 ] = this.topFretImage[ 0 ];
	this.topFretImage[ 13 ] = this.topFretImage[ 0 ];
	
	this.fretDisabledImage = new Image( 14, 17 );
	this.fretDisabledImage.src = "images/fret_disabled.gif";
	
	this.fretDisabledTopImage = new Image( 14, 17 );
	this.fretDisabledTopImage.src = "images/fret_disabled_top.gif";
	
	this.fretPlainImage = new Image( 14, 17 );
	this.fretPlainImage.src = "images/fret_plain.gif";
	
	this.fretPlainTopImage = new Image( 14, 17 );
	this.fretPlainTopImage.src = "images/fret_plain_top.gif";
	
	this.transparentImage = new Image( 1, 1 );
	this.transparentImage.src = "images/transparent.gif";
	
	this.leftTopImage = new Image( 3, 17 );
	this.leftTopImage.src = "images/left_top.gif";
	
	this.leftImage = new Image( 3, 17 );
	this.leftImage.src = "images/left.gif";
	
	this.rightTopImage = new Image( 7, 17 );
	this.rightTopImage.src = "images/right_top.gif";
	
	this.rightImage = [];
	this.rightImage[ 0 ] = new Image( 7, 17 );
	this.rightImage[ 0 ].src = "images/right_0.gif";
	this.rightImage[ 1 ] = new Image( 7, 17 );
	this.rightImage[ 1 ].src = "images/right_1.gif";
	this.rightImage[ 2 ] = new Image( 7, 17 );
	this.rightImage[ 2 ].src = "images/right_2.gif";
}
	
ChordPrinter.prototype.WriteTop = function( )
{	
	var s = "";
	for( var stringNum = 0; stringNum < this.instrumentTop.length; stringNum++ )
	{
		s = s + "<img src=\"" + this.notesImages[ this.instrumentTop[ stringNum ] ].src + "\" width=14 height=14>";
	}
	document.write( s );
}

ChordPrinter.prototype.DrawChord = function( startFret, endFret, positionArray, noteArray )
{
	s = "";

	if ( startFret != 0 )
	{
		var spacerWidth = ( positionArray.length * 14 ) + 10;
		s = s + "<img src=\"" + this.transparentImage.src + "\" width=" + spacerWidth + " height=7><br>";
	}

	for( fret = startFret; fret <= endFret; fret++ )
	{
		if ( fret == 0 )
			s = s + "<img src=\"" + this.leftTopImage.src + "\" width=3 height=17>";
		else
			s = s + "<img src=\"" + this.leftImage.src + "\" width=3 height=17>";

		for( stringNum = 0; stringNum < positionArray.length; stringNum++ )
		{
			var image = "";
			if ( positionArray[ stringNum ] == -1 || noteArray[ stringNum ] == -1 )
			{
				if ( fret == 0 )
					image = this.fretDisabledTopImage.src;
				else
					image = this.fretDisabledImage.src;
			}
			else
			{
				if ( positionArray[ stringNum ] == fret )
				{
					if ( fret == 0 )
						image = this.topFretImage[ noteArray[ stringNum ] ].src;
					else
						image = this.fretImage[ noteArray[ stringNum ] ].src;
				}
				else
				{
					if ( fret == 0 )
						image = this.fretPlainTopImage.src;
					else
						image = this.fretPlainImage.src;
				}
			}

			s = s + "<img src=\"" + image + "\" width=14 height=17>";
		}

		if ( fret == 0 )
			s = s + "<img src=\"" + this.rightTopImage.src + "\" width=7 height=17>";
		else
			s = s + "<img src=\"" + this.rightImage[ this.fretBall[ fret ] ].src + "\" width=7 height=17>";

		s = s + "<BR>"
	}

	document.write(s);
}

