// JavaScript Document
var topVehicles = new Array("camry","corolla","noah","rav4");
var topDestinations = new Array("kingston","port_antonio","ocho_rios","montego_bay","negril","mandeville");
var topDestinationsWebsites = new Array("town1","town2","ocho-rios-jamaica","montego-bay-jamaica","town5","town6");


function GenerateRandomTopVehicle(){
	ImageNameArray = topVehicles;
	ImgUrlPrefix = "http://www.mobay.com/images/top/";
	ImgUrlSuffix = ".jpg";
	ImgTagPrefix = '<img width="270" height="130" alt="" hspace="0" vspace="0" border="0" align="right" id="topvehicle" src="';
	ImgTagSuffix = '">';
	RndImgNum = Math.round(Math.random()*(ImageNameArray.length-1));
	ImgTagHtml = ImgTagPrefix + ImgUrlPrefix + ImageNameArray[RndImgNum] + ImgUrlSuffix + ImgTagSuffix;
	return ImgTagHtml;
}

function GenerateRandomDestination(){
  destinations = topDestinations;
  RndDestNum = Math.round(Math.random()*(destinations.length-1));
  DestName = destinations[RndDestNum];
  DestWebsite = topDestinationsWebsites[RndDestNum];
  DestCaption = capitalizeWords(replaceCharacters(DestName,'_',' '));
  return ReturnHTMLTags(DestCaption,DestName,DestWebsite);
}

function ReturnHTMLTags(Cap,Name,Name2){
  HTMLTag = '<div class="side-'+Name+'"><a href=http://www.mobay.com/'+Name2+'.htm><img src="http://www.mobay.com/images/arrow.gif" width="148" height="198" border="0" hspace="0" vspace="0" alt="'+Cap+'" /></a></div>\n';
	HTMLTag = HTMLTag + '<div class="sidecaption">'+Cap+'</div>\n';
  return HTMLTag;
}

function replaceCharacters(conversionString,inChar,outChar){
  var convertedString = conversionString.split(inChar);
  convertedString = convertedString.join(outChar);
  return convertedString;
}

function capitalizeWords(string){
  var tmpStr, tmpChar, preString, postString, strlen;
  tmpStr = string.toLowerCase();
  stringLen = tmpStr.length;
  if (stringLen > 0){
    for (i = 0; i < stringLen; i++){
      if (i == 0){
        tmpChar = tmpStr.substring(0,1).toUpperCase();
        postString = tmpStr.substring(1,stringLen);
        tmpStr = tmpChar + postString;
      }else{
        tmpChar = tmpStr.substring(i,i+1);
        if (tmpChar == " " && i < (stringLen-1)){
          tmpChar = tmpStr.substring(i+1,i+2).toUpperCase();
          preString = tmpStr.substring(0,i+1);
          postString = tmpStr.substring(i+2,stringLen);
          tmpStr = preString + tmpChar + postString;
        }
      }
    }
  }
  return tmpStr;
}

