function formatPath(pathInput) {
  var pathOutput;
  var pathLength = pathInput.length;
  if ((pathLength !== 0) && (pathInput.charAt(pathLength - 1) != '/')) {
    pathOutput = pathInput + '/';
  } else {
    pathOutput = pathInput;  
  }
  return pathOutput;
}

function flashMovie(pth,mov,mDir,img,iDir,wd,ht,bg,rpt,alt,imWd,imHt,fPar,mode) {

  // Initialize some vars:
  var output;
  var moviePath;
  
  // ...make sure there's a trailing slash on the paths:
  pth = formatPath(pth);
  mDir = formatPath(mDir);
  iDir = formatPath(iDir);
  
  var srcAttr = ' src="' + pth + iDir + img + '"';
  var wdAttr = ' width="' + wd + '"';
  var htAttr = ' height="' + ht + '"';
  var imWdAttr = ' width="' + imWd + '"';
  var imHtAttr = ' height="' + imHt + '"';
  if (fPar) {
    var query = '?' + fPar;
  } else {
    query = '';  
  }
  var dataAttr = ' data="' + pth + mDir + mov + '.swf' + query + '"';
  var valueAttr = ' value="' + pth + mDir + mov + '.swf' + query + '"';
  var bgColAttr;
  var rptAttr;
  var altAttr;
  

  
  // ...be forgiving if the colour value comes with or without a '#':
  if (bg.charAt(0) != '#') {
    bgColAttr = ' value="#' + bg + '"';
  } else {
    bgColAttr = ' value="' + bg + '"';
  }
    
  // ...and assign some of them, based on the incoming values from the function:
  if (alt != '') {
    altAttr = ' alt="' + alt + '"';
  } else {
    altAttr = ' alt=""';  
  }

  // Put the output together:
  output  = '\n<object type="application/x-shockwave-flash"' + dataAttr + wdAttr + htAttr + '>\n';
  output += '<param name="movie"'+ valueAttr + '>\n';
  output += '<param name="bgcolor"' + bgColAttr + '>\n';
  
  // Show the 'loop' param if we were passed a value for it:
  if (rpt != '') {
    output += '<param name="loop" value="' + rpt + '">\n'; 
  }
  if (iDir) {
    output += '<img' + srcAttr + imWdAttr + imHtAttr + altAttr + ' />\n';
  }
  output += '</object>';
  
  switch (mode) {
    case 'generate':
      return output;
    break;
    
    default:
      document.write(output);   
  }
}


// A function to build the file path:						
function flashMovieFile(i) {
	var theMovie = 'theFile=http://vanrecital.com/audio/' + mp3files[i][0] + '&autoplay=yes';
	return theMovie;
}


// A function to output the file info to the screen:
function flashMovieInfo(i) {
	var theMovieText = mp3files[i][1];
	var theConcertPage = mp3files[i][2];
	var theSpan = document.createElement('span');
	var theContainer = document.getElementById('player').getElementsByTagName('p')[0];
	var theLink ='<a href="/events/concert_template.cfm?concertid=' + theConcertPage + '">More&hellip;</a>';
						
	theSpan.innerHTML = theMovieText + ' ' + theLink;
	theContainer.appendChild(theSpan);						
}


// A function that generates a random number, between 0 and the length of the array it receives - 1:
function createRandomNumber(array) {
	//var theRandomNumber = Math.floor(Math.random()*(array.length-1));
	var theRandomNumber = Math.floor(Math.random()*(array.length));
	return theRandomNumber;	
}