<!--

// =================================== //
// Guitar Chord Finder                 //
// v1.0 - Apr 17, 2006                 //
// ----------------------------------- //
// Created by Lloyd Hassell            //
// Website: lloydhassell.brinkster.net //
// Email: lloydhassell@hotmail.com     //
// =================================== //

// CONFIG:

var keyList = new Array('C','C#','D','Db','D#','E','Eb','F','F#','G','Gb','G#','A','Ab','A#','B','Bb');

var guitarWidth = 750;
var guitarHeight = 170;

var fretCoordsX = new Array();
fretCoordsX[0] = new Array(453,420,363,308,258,210,166,123,84,45);
fretCoordsX[1] = new Array(297,330,387,442,492,540,584,627,666,705);
fretCoordsX[2] = new Array(297,330,387,442,492,540,584,627,666,705);
fretCoordsX[3] = new Array(453,420,363,308,258,210,166,123,84,45);

var fretCoordsY = new Array();
fretCoordsY[0] = new Array(47,59,71,83,95,107);
fretCoordsY[1] = new Array(123,111,99,87,75,63);
fretCoordsY[2] = new Array(47,59,71,83,95,107);
fretCoordsY[3] = new Array(123,111,99,87,75,63);

var fretMarkerSrc = 'guitarchordfinder/fretmarker.gif';
var fretMarkerWidth = 9;
var fretMarkerHeight = 9;

// MAIN:

var guitarPosX ;
var guitarPosY = 113; // set by table padding
var fretMarkers = new Array();
var currentChordStructure = 'XXXXXX';
var currentView = 0;

function loadGuitarChordFinder() {
   guitarPosX = Math.round((getWinWidth() - guitarWidth) / 2);
   if (guitarPosX < ) guitarPosX = 0;
   for (var x = 0; x < 6; x++) {
      fretMarkers[x] = addLayer('fretMarkerLyr' + x);
      setLayerSize(fretMarkers[x],fretMarkerWidth,fretMarkerHeight);
      setLayerClip(fretMarkers[x],0,fretMarkerWidth,fretMarkerHeight,0);
      setLayerHTML(fretMarkers[x],getImgTag('fretMarker' + x,fretMarkerSrc,fretMarkerWidth,fretMarkerHeight,0));
      var newPosX = Math.floor(guitarPosX + fretCoordsX[0][0] - (fretMarkerWidth / 2));
      var newPosY = Math.floor(guitarPosY + fretCoordsY[0][x] - (fretMarkerHeight / 2));
      moveLayerTo(fretMarkers[x],newPosX,newPosY);
      }
   }

function showChord(KEY,STRUCTURE) {
   if (STRUCTURE != '') {
      resetDropBoxes(KEY);
      currentChordStructure = STRUCTURE;
      for (var stringLoop = 0; stringLoop < 6; stringLoop++) {
         var newFretMarking = STRUCTURE.charAt(stringLoop);
         if (newFretMarking == 'X') {
            var newPosX = Math.floor(guitarPosX + fretCoordsX[currentView][0] - (fretMarkerWidth / 2));
            var newPosY = Math.floor(guitarPosY + fretCoordsY[currentView][stringLoop] - (fretMarkerHeight / 2));
            slideLayerTo(fretMarkers[stringLoop],newPosX,newPosY,20,50,'hideLayer(fretMarkers[' + stringLoop + '])');
            }
         else {
            newFretMarking = parseInt(newFretMarking);
            var newPosX = Math.floor(guitarPosX + fretCoordsX[currentView][newFretMarking] - (fretMarkerWidth / 2));
            var newPosY = Math.floor(guitarPosY + fretCoordsY[currentView][stringLoop] - (fretMarkerHeight / 2));
            showLayer(fretMarkers[stringLoop]);
            slideLayerTo(fretMarkers[stringLoop],newPosX,newPosY,20,50);
            }
         }
      }
   }

function resetDropBoxes(KEY) {
   if (KEY != 'common') document.forms[0].common.options[0].selected = true;
   for (var keyLoop = 0; keyLoop < keyList.length; keyLoop++) {
      if (KEY != keyList[keyLoop]) document.forms[0].elements[keyList[keyLoop]].options[0].selected = true;
      }
   }

function changeGuitarView(VIEW) {
   for (var stringLoop = 0; stringLoop < 6; stringLoop++) hideLayer(fretMarkers[stringLoop]);
   document.images['guitarneck'].src = 'guitarchordfinder/guitarneck' + (VIEW + 1) + '.jpg';
   currentView = VIEW;
   for (var stringLoop = 0; stringLoop < 6; stringLoop++) {
      var newFretMarking = currentChordStructure.charAt(stringLoop);
      if (newFretMarking == 'X') {
         var newPosX = guitarPosX + fretCoordsX[currentView][0] - (fretMarkerWidth / 2);
         var newPosY = guitarPosY + fretCoordsY[currentView][stringLoop] - (fretMarkerHeight / 2);
         moveLayerTo(fretMarkers[stringLoop],newPosX,newPosY);
         }
      else {
         newFretMarking = parseInt(newFretMarking);
         var newPosX = guitarPosX + fretCoordsX[currentView][newFretMarking] - (fretMarkerWidth / 2);
         var newPosY = guitarPosY + fretCoordsY[currentView][stringLoop] - (fretMarkerHeight / 2);
         moveLayerTo(fretMarkers[stringLoop],newPosX,newPosY);
         showLayer(fretMarkers[stringLoop]);
         }
      }
   }

//-->
