// JavaScript Document
/**********
* Copyright 2007 Gregg B Larson
* All Rights reserved
***********/
function Chords(tctrl){
		this.tabcreator = tctrl;
		
		//btnMute
		this.btnMute = document.createElement('input');
		this.btnMute.type = "button";
		this.btnMute.id = "btnMute";
		this.btnMute.value = "Mute Strings";
		this.btnMute.title = "Click here to mute a string.";
		this.btnMute.name = "btnMute";
		
		//btnNextChord
		this.btnNextChord = document.createElement('input');
		this.btnNextChord.type = "button";
		this.btnNextChord.id = "btnMutliNote1";
		this.btnNextChord.value = "Next Chord";
		this.btnNextChord.title = "add another chord to the tab";
		this.btnNextChord.name = "btnNextChord";
		
						//button next image
		this.btnnext = new Image();	
		this.btnnext.src = "images/btnnext.gif";
		this.btnnext.id = "btnv";
		this.btnnext.title = "Add another chord to the tab";
		this.btnnext.alt = "next";
		this.btnnext.width = "125";
		this.btnnext.height = "25";
		
				
				//button start chord image
		this.btnrecord = new Image();	
		this.btnrecord.src = "images/btnrecord.gif";
		this.btnrecord.id = "btnnc";
		this.btnrecord.title = "Start a New Chord";
		this.btnrecord.alt = "New Chord";
		this.btnrecord.width = "125";
		this.btnrecord.height = "25";
		
						//button end chord image
		this.btnendchrd = new Image();	
		this.btnendchrd.src = "images/btnstoprecording.gif";
		this.btnendchrd.id = "btnec";
		this.btnendchrd.title = "End Making a Chord";
		this.btnendchrd.alt = "End Chord";
		this.btnendchrd.width = "125";
		this.btnendchrd.height = "25";
		
		//button return image
		this.btnreturn = new Image();	
		this.btnreturn.src = "images/button.gif";
		//this.btnv.id = "btnv";
		//this.btnv.title = "Vibrato'";
		this.btnreturn.alt = "return";
		this.btnreturn.width = "10";
		this.btnreturn.height = "10";
		
		this.table = document.createElement('table');
		this.table.border = "1";
		this.table.width = "150px";
		this.table.style.backgroundColor = "#999999";
		
		this.tr1 = document.createElement('tr');

		this.td1 = document.createElement('td');
		this.td1.style.backgroundColor = "#003366";
		this.td1.style.fontSize = "10px";
		this.td1.style.color = "#FFFFFF";
		this.td1.height="10";
		this.td1.align="left";
		
			this.helplink = document.createElement('a');
		this.helplink.setAttribute('class', 'tiny_help');
		this.helplink.setAttribute('target', 'help');
		this.helplink.setAttribute('href', 'http://blog.guitartabcreator.com/2008/04/creating-chords-on-guitar-tab-creator.html');
		this.helplink.innerHTML = "help";
		
		this.spanlabel = document.createElement('span');
	//	this.spanlabel.class="style7";
		this.spanlabel.id="lblcontrols";
		this.spanlabel.innerHTML = "Create Chords";
		this.spanlabel.appendChild(this.helplink);
		
		this.td1.appendChild(this.btnreturn);
		this.td1.appendChild(this.spanlabel);
		this.tr1.appendChild(this.td1);
	//	this.table.appendChild(this.tr1);
		
		this.tr2 = document.createElement('tr');
		this.td2 = document.createElement('td');
		this.td2.style.backgroundColor = "#999999";
		this.td2div = document.createElement('div');
		this.td2div.id="muteon";
		this.td2div.align="center";
		this.td2.appendChild(this.td2div);
		this.tr2.appendChild(this.td2);
		this.tbody = document.createElement('tbody');
		this.tbody.appendChild(this.tr1);
		this.tbody.appendChild(this.tr2);
		this.table.appendChild(this.tbody);
		
		
		//table to format button positions
		this.tableFormat = document.createElement('table');
		this.tableFormat.border = "0";
		//this.tableFormat.width = "130px";
		//this.tableFormat.style.backgroundColor = "#999999";
		this.tableFormat.cellPadding = "0";
		this.tableFormat.cellSpacing = "0";
		this.tableFormat_tr1 = document.createElement('tr');

		this.tableFormat_td1 = document.createElement('td');
		//this.td1.style.backgroundColor = "#003366";
		this.tableFormat_td1.align="center";
		this.tableFormat_td1.style.backgroundColor = "#999999";
	//	this.tableFormat_td1.appendChild(this.btnstart);
		this.tableFormat_tr1.appendChild(this.tableFormat_td1);
		this.tableFormat_tr2 = document.createElement('tr');
		this.tableFormat_td3 = document.createElement('td');
		this.tableFormat_td3.style.backgroundColor = "#999999";
		this.tableFormat_td3.align="center";
		this.tableFormat_td3.appendChild(this.btnnext);
		this.tableFormat_tr2.appendChild(this.tableFormat_td3);
		
		this.tableFormat_tr3 = document.createElement('tr');
		this.tableFormat_td4 = document.createElement('td');
		this.tableFormat_td4.style.backgroundColor = "#999999";
		this.tableFormat_td4.align="center";
		this.tableFormat_td4.appendChild(this.btnrecord);
		this.tableFormat_tr3.appendChild(this.tableFormat_td4);
		
		this.tableFormat_tbody = document.createElement('tbody');
		this.tableFormat_tbody.appendChild(this.tableFormat_tr3);
		//this.tableFormat_tbody.appendChild(this.tableFormat_tr1);
		this.tableFormat_tbody.appendChild(this.tableFormat_tr2);
		this.tableFormat.appendChild(this.tableFormat_tbody);
		//just keep the thing open
		this.td2div.appendChild(this.tableFormat);
		//end table to format button positions
		//show chords
		Event.observe($(this.td1), 'click', function(event){
			// this.ChngChord();
		}.bindAsEventListener(this));
	

		//record
		Event.observe($(this.btnrecord), 'click', function(event){
				this.tabcreator.chord =1;
				this.tableFormat_td4.innerHTML = "";
				this.tableFormat_td4.appendChild(this.btnendchrd);		 
		}.bindAsEventListener(this));
	
			//end record
		Event.observe($(this.btnendchrd), 'click', function(event){
				this.StopRecording();
				this.tableFormat_td4.innerHTML = "";
				this.tableFormat_td4.appendChild(this.btnrecord);		 
		}.bindAsEventListener(this));
		
	//next
		Event.observe($(this.btnnext), 'click', function(event){
			 this.NextChord();
		}.bindAsEventListener(this));
	
		this.NextChord = function (){
		if(this.tabcreator.ischord(this.tabcreator.tabcounter)){
			this.tabcreator.tabcounter += 1; 
		} else {
			alert("you have not created a chord yet");
		}
	}
	
	this.showControl= function(div){
		this.div = div;
		this.div.appendChild(this.table);
	}
	
	this.StopRecording =  function(){
		//need to backfill the unused fret positions
			for(i=5;i>=0;i--){
				if( this.tabcreator.strings[i][this.tabcreator.tabcounter] == null){
							this.tabcreator.strings[i][this.tabcreator.tabcounter] = ".";
					}
			}
		
			this.tabcreator.chord =0;
			this.tabcreator.mute=0;

			if(this.tabcreator.ischord(this.tabcreator.tabcounter)){
				this.tabcreator.tabcounter += 1; //Spacing + tabcounter;
			}
}
	
	this.ChngChord = function ()
	{
		if(this.tabcreator.mute == 1){
		  new Effect.Highlight('muteon');
		  return;
		}
		if(this.spanlabel.innerHTML == "Click to open chord tool"){
			this.td2div.appendChild(this.tableFormat);
			this.spanlabel.innerHTML = "Click to close chord tool";	
		}else{
			//need to backfill the unused fret positions
		//	Effect.BlindUp('muteon');
		this.StopRecording();
			$('muteon').innerHTML  = "";
		//	document.getElementById("muteoff").style.visibility = 'visible';
			//make sure to add on the extra
			this.spanlabel.innerHTML = "Click to open chord tool";
		}
		
	}
		

}