/*
 * Production javascript
 *
 * Copyright (c) 2008 Vidteq India Pvt Ltd
 * and GPL (GPL-LICENSE.txt) licenses.MSI
 *

 * $Date: 2010/09/03 10:05:58 $
 * $Date: 2010/09/03 10:05:58 $

 * $Rev: $
 */

function fvt () {
  this.firstLoad = true;
  this.videoDom = 'VideoPlayerDiv';
  this.videoSwf = 'VideoPlaylist';
  this.swfAwake = null; // TBD check
  this.playerActive = false;
  this.globalTextIndex=0;
  this.swfMouseRelease=false;
  this.swfMouseOut=false;
  this.theScroll = [];  
  this.noOfTextDirections = 0;
}

fvt.prototype.showLorR = function(which) {
  $('#dynamicDiv').show();
  if(which == 'L') {
    //if(typeof(__experimentalUI)!='undefined' && __experimentalUI) $('#routedetails').hide();
    document.getElementById('routediv').style.display='none';
    document.getElementById('locadiv').style.display='block';
    document.getElementById('VideoPlayerDiv').style.display='none';
    $('#VideoPlayerDiv')[0].style.display='none'; // TBD why ?
    document.getElementById(this.videoDom).innerHTML = '';
    $('#routedetails')[0].innerHTML="";
    ioAreaObj.toggleButtons({"mapexpand":false});
  } else if(which =='R') {
    //if(typeof(__experimentalUI)!='undefined' && __experimentalUI) $('#routedetails').show();
    document.getElementById('routediv').style.display='block';
    document.getElementById('locadiv').style.display='none';
    document.getElementById('VideoPlayerDiv').style.display='block';
    if(ioAreaObj.embed && ioAreaObj.embed.blocate) ioAreaObj.toggleButtons({"locality":true});
    if(ioAreaObj.embed && ioAreaObj.embed.locateStores) ioAreaObj.toggleButtons({"stores":true});
    ioAreaObj.toggleButtons({"mapexpand":true});
  }	
}

fvt.prototype.writeCategory = function(catList) {
  var width=0.75*parseInt(ioAreaObj.embed.vidWidth)-10+"px"
  var categoryDropDown=""; 
  categoryDropDown+="<div style='background-color:inherit;padding-bottom:1px;'><a id='selectcategoryhelptxt' style='font-weight:bold' class=profileFont>Click below to select different category</a></div>";
  categoryDropDown+="<select onchange='ioAreaObj.invokeBizSearch(null,{categoryList:this.options[this.selectedIndex].value});' class='bizcatdropdown' id='bizCatDropDown'>";
  for(var i in catList) {
    if (typeof(catList[0]) != 'undefined') {
      if (typeof(catList[0].name) == 'undefined') {
        var id=catList[i].replace(/\s+/,"_");	
        categoryDropDown+="<option id='"+id+"' value='"+catList[i]+"' >"+catList[i]+"</option>";
      } else {
        var id=catList[i].name.replace(/\s+/g,"_");
        categoryDropDown+="<option id='"+id+"' value='"+catList[i].categoryList+"' >"+catList[i].name+"</option>";
      }
    } else {
	var id=i.replace(/\s+/g,"_");
      categoryDropDown+="<option id='"+id+"' value='"+catList[i]+"' >"+i+"</option>";
    }
  }
  categoryDropDown+="</select>";
  $('#categories')[0].style.display='block';
  $('#categories')[0].innerHTML=categoryDropDown;
  setInterval(function () { ioAreaObj.colorChanger('selectcategoryhelptxt'); },2000);
}

//fvt.prototype.writeCategory_newUI = function(catList) {
//  var width=0.75*parseInt(ioAreaObj.embed.vidWidth)-10+"px"
//  var categoryDropDown="";
//  categoryDropDown+="<ul id='ul-dropdown' class='drop-down'>";
//  for(var i in catList) {
//    if (typeof(catList[0]) != 'undefined') {
//      var id=catList[i].replace(/\s+/,"_");
//      categoryDropDown+="<li id='"+id+"' onclick=ioAreaObj.invokeBizSearch(null,{categoryList:"+catList[i]+",name:"+i+"}) class=drop-down-list>";
//      categoryDropDown+="<a id='"+id+"' class=headlink-drop-down>"+catList[i]+"<a></li>";
//    } else {
//      var id=i.replace(/\s+/g,"_");
//      categoryDropDown+="<li id='"+id+"' onclick='ioAreaObj.invokeBizSearch(null,{\"categoryList\":\""+catList[i]+"\",\"name\":\""+i+"\"});closeAnyDropDowns();' class=drop-down-list ><a id='"+id+"' class=headlink-drop-down>"+i+"</a></li>";
//    }
//  }
//  categoryDropDown+="</ul>";
//  $('#div_biz').append(categoryDropDown);
//  $('#bizdisplay')[0].onclick=null;
//  $('#bizdisplay').click(function () {
//    if($('#div_biz')[0].style.display=='block') {
//      ioAreaObj.selectInTopPanel('');
//      $('#div_biz').hide('slow',null);
//      $('#bizdisplay')[0].className='headlink';
//      $('#div_bizdisplay')[0].className = 'top-panel-height';
//    } else {
//      ioAreaObj.selectInTopPanel('div_bizdisplay');
//      $('#div_biz').show('slow',null);
//      $('#bizdisplay')[0].className='headlink-clicked';
//      $('#div_bizdisplay')[0].className = 'top-panel-height-clicked';
//    }
//   //},
//   /*function () {
//       if($('#div_biz')[0].style.display=='block') {
//           $('#div_biz').hide('slow',null);
//       }
//       else $('#div_biz').show('slow',null);
//       $('#bizdisplay')[0].className='headlink';
//       ioAreaObj.selectInTopPanel('');
//       $('#div_bizdisplay')[0].className = 'top-panel-height';
//       $('#bizdisplay')[0].className='headlink';*/
//  });
//}


fvt.prototype.prepareForShowSrf = function(srfResponse) {
  if (typeof(srfResponse.vid) != 'undefined') return;
  this.showLorR('L');
  var tempHTML ="";
  tempHTML+="<div style='padding-left:10px;padding-right:10px;padding-bottom:10px;color:white;overflow:auto;'><a onfocus='this.blur();' class='simple' >"
  tempHTML+=this.getStatusHtml(srfResponse.srf[0]);
  tempHTML+="</a><br/><div id='locaresults0'>";
  srfResponse.srf[0].domName = 'locaresults0';
  tempHTML+="</div></div>";
  if (typeof(srfResponse.srf[1]) != 'undefined') {
    tempHTML+="<div style='padding:10px;color:white;overflow:auto;'><a onfocus='this.blur();' class='simple' >"
    tempHTML+=this.getStatusHtml(srfResponse.srf[1]);
    tempHTML+="</a><br/><div id='locaresults1'>";
    srfResponse.srf[1].domName = 'locaresults1';
    tempHTML+="</div></div>";
  }
  //var result = TrimPath.processDOMTemplate("locadiv_stuff", data);
  document.getElementById('locadivinside').innerHTML=tempHTML; 
  this.populateShowSets(srfResponse);
}

fvt.prototype.populateShowSetInSrf = function(srf,perSet) {
  srf.showSets = [];
  srf.curShowSet = 0;
  if (srf.results.length == 0) return; 
  for (var i=1;i<=srf.results.length;i+=perSet) {
    srf.showSets.push({'from':i,
      'to' : (i+perSet-1<srf.results.length?(i+perSet-1):srf.results.length)});
  } 
}

fvt.prototype.populateShowSets = function(srfResponse) {
  if (srfResponse.srf.length == 2) {
    if (srfResponse.srf[0].results.length + srfResponse.srf[1].results.length <= 10) {
      this.populateShowSetInSrf(srfResponse.srf[0],10);
      this.populateShowSetInSrf(srfResponse.srf[1],10);
    } else {
      this.populateShowSetInSrf(srfResponse.srf[0],5);
      this.populateShowSetInSrf(srfResponse.srf[1],5);
    }
  } else { // single case
    this.populateShowSetInSrf(srfResponse.srf[0],10);
  }
}

fvt.prototype.getStatusHtml = function(srf) {
  var noOfHits = srf.results.length;
  var data = this.getStartEndData(srf); 
  try {$('#categories')[0].style.display='none';} catch (e) {}	
  switch(srf.srfType) {
    case "location" :
    case "startAddress" :
    case "endAddress" :
      if(typeof(srf.results[0])!='undefined') data.topRelevance=srf.results[0].relevance;
      data.noOfHits = noOfHits; 
      var tempCounter=(noOfHits!=1)?("<b style='font-size:1.2em'>"+noOfHits+"</b>"+" matches"):(" exactly one match");
      var tempCounterApprox=(noOfHits!=1)?("<b style='font-size:1.2em'>"+noOfHits+"</b>"+" matches."):(" one match.");
      var mesg; 
      mesg="Your "+data.sORe;
      if (data.startOrEnd != '') {
        mesg+=" (<b style='font-size:1.2em'>"+data.startOrEnd+"</b>) resulted in "+tempCounter;
      }
      mesg+=".";
      if(parseInt(srf.categoryMatches)) {
          mesg+=" Check out <span onclick=javascript:ioAreaObj.categorySearchInvoke(); style=cursor:pointer;text-decoration:underline; >category</span> matches ";
      }
      /*if(typeof(srf.results[0])!='undefined' && 
         typeof(srf.results[0].relevance) != 'undefined' && 
         srf.results[0].relevance==0) {
        mesg="Your "+srf.parentType+" search for <b style='font-size:1.2em'>"+data.startOrEnd+"</b> failed to get an exact match. It gave approximate "+tempCounterApprox;
      }*/
      if(vidteq.flink && vidteq.flink.ll==1) {mesg="";}
      if (noOfHits && srf.results[0].type == 'center') {mesg = "Your "+data.sORe;}
      break;
    case "locateStores":
      var place=(typeof(ioAreaObj.embed)!='undefined' && 
                 typeof(ioAreaObj.embed.place)!='undefined')?ioAreaObj.embed.place.address.name:' center of Bangalore';
      mesg="Found "+noOfHits+" Stores nearby, please select one of these ";
      if(ioAreaObj.mode=='ROUTE') ioAreaObj.showHelpMessage('Nearest store is selected. Press GO VID to get a route');
      // TBD it does not belong here
      break;
    case "blocate":
      $('#categories')[0].style.display='block';
      if(noOfHits) {
        mesg='';
        if(typeof(__experimentalUI)!='undefined' && __experimentalUI) {
          if (ioAreaObj.embed.blocate.lastSearchCategory && ioAreaObj.embed.blocate.lastSearchCategory != '') {
            mesg="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Nearby <b style='font-size:1.2em'>"+ ioAreaObj.embed.blocate.lastSearchCategory+"</b> are ..";
          }
        }
      } else {mesg=' No results found'}
      break;
    default:
      break;
  }
  return mesg;
}

fvt.prototype.writeStatusNew = function(srf) {
  var noOfHits = srf.results.length;
  //var data = this.getStartEndObj(srf.parentType); 
  var data = this.getStartEndObj(srf); 
  try {$('#categories')[0].style.display='none';} catch (e) {}	
  switch(srf.parentType) {
    case "location" :
    case "startAddress" :
    case "endAddress" :
      if(typeof(srf.results[0])!='undefined') data.topRelevance=srf.results[0].relevance;
      data.noOfHits = noOfHits; 
      var tempCounter=(noOfHits!=1)?("<b style='font-size:1.2em'>"+noOfHits+"</b>"+" matches"):(" exactly one match");
      var tempCounterApprox=(noOfHits!=1)?("<b style='font-size:1.2em'>"+noOfHits+"</b>"+" matches."):(" one match.");
      var mesg; 
      mesg="Your "+data.sORe;
      if (data.startOrEnd != '') {
        mesg+=" (<b style='font-size:1.2em'>"+data.startOrEnd+"</b>) resulted in "+tempCounter;
      }
      mesg+=".";
      /*if(typeof(srf.results[0])!='undefined' && 
         typeof(srf.results[0].relevance) != 'undefined' && 
         srf.results[0].relevance==0) {
        mesg="Your "+srf.parentType+" search for <b style='font-size:1.2em'>"+data.startOrEnd+"</b> failed to get an exact match. It gave approximate "+tempCounterApprox;
      }*/
      if(vidteq.flink && vidteq.flink.ll==1) {mesg="";}
      if (noOfHits && srf.results[0].type == 'center') {mesg = "Your "+data.sORe;}
      break;
    case "locateStores":
      var place=(typeof(ioAreaObj.embed)!='undefined' && 
                 typeof(ioAreaObj.embed.place)!='undefined')?ioAreaObj.embed.place.address.name:' center of Bangalore';
      mesg="Found "+noOfHits+" Stores nearby, please select one of these ";
      if(ioAreaObj.mode=='ROUTE') ioAreaObj.showHelpMessage('Nearest store is selected. Press GO VID to get a route');
      // TBD it does not belong here
      break;
    case "blocate":
      $('#categories')[0].style.display='block';
      if(noOfHits) {mesg='';}
      else {mesg=' No results found'}
      break;
    default:
      break;
  }
  return mesg;
}

fvt.prototype.showFvtMoreOrLess = function (idNo,flag) {
  $('#showMoreOrLess'+idNo)[0].innerHTML=(flag==0)?'Less <<':'More >>';
  if(flag) $('#showMoreDiv'+idNo).hide();
  else $('#showMoreDiv'+idNo).show();
  flag=(flag==0)?1:0;
  $('#showMoreOrLess'+idNo)[0].onclick=function () {fvtObj.showFvtMoreOrLess(idNo,flag);}
}

fvt.prototype.writeSrfToTable = function(srf) {
  if (typeof(srf.showSets[srf.curShowSet]) == 'undefined') return;
  if(vidteq.flink) {
    if(vidteq.flink.leftBar==0) $('#locadiv')[0].style.display='none'
    if(vidteq.flink.leftBar) vidteq.flink.leftBar=1
  }
  var tempRows="<table style='padding:0px;' cellpadding=1 cellspacing=1 width=90% >";
    tempRows+="<tr colspan=2><td></td><td><hr/><td/></tr>";
  for(var i=srf.showSets[srf.curShowSet].from;i<=srf.showSets[srf.curShowSet].to;i++) {
    var localRows;
    var rmReg=new RegExp("<tr><td></td><td><a class=simple style='color:white'>or did you mean ?</a></td></tr>");
    // TBD what is above line doing ?
    tempRows+=getEntityHtml('fvt',srf.results[i-1]);
    tempRows+="<tr colspan=2><td></td><td><hr/><td/></tr>";
  }
  tempRows+="<tr><table cellpadding=5 cellspacing=5><tr>";
  if (typeof(srf.showSets[srf.curShowSet-1]) == 'undefined') {
    tempRows+="<td></td>";
  } else {
    tempRows+="<td><a onfocus='this.blur();' class='simple' href='javascript:void(0)' onclick=javascript:ioAreaObj.srfResponse.srf["+srf.srfIndex+"].curShowSet--;ioAreaObj.writeSrfToTable.apply(ioAreaObj,[]);>&lt&lt&nbsp Previous</a></td>";
  }
  if (typeof(srf.showSets[srf.curShowSet+1]) == 'undefined') {
    tempRows+="<td></td>";
  } else {
    tempRows+="<td><a class='simple' href='javascript:void(0)' onclick=javascript:ioAreaObj.srfResponse.srf["+srf.srfIndex+"].curShowSet++;ioAreaObj.writeSrfToTable.apply(ioAreaObj,[]);>Next &nbsp&gt&gt</a></td>";
  }
  tempRows+="</tr></table></tr>";
  tempRows+="</table>";
  document.getElementById(srf.domName).innerHTML=tempRows;
  //if(vidteq.flink && vidteq.flink.ll) callLocationPopMap(0); 
}
	
fvt.prototype.loadVideoPlayer = function() {
  var w=typeof(ioAreaObj.embed)!='undefined'?ioAreaObj.embed.vidWidth:480; 
  var h=typeof(ioAreaObj.embed)!='undefined'?ioAreaObj.embed.vidHeight:350; 
  var str = AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', w,
			'height', h,
			'src', 'VideoPlaylist',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'exactfit',
			'wmode', 'transparent',
			'devicefont', 'false',
			'id', 'VideoPlaylist',
			'bgcolor', '#000000',
			'name', 'VideoPlaylist',
			'menu', 'true',
			'allowFullScreen', 'false',
			'allowScriptAccess','sameDomain',
			'movie', 'VideoPlaylist',
			'salign', ''
			); //end AC code
  this.vidPlayerHTML=str;
  document.getElementById(this.videoDom).innerHTML = str;
  //fvt.vidPlayerHTML=document.getElementById('VideoPlayerDiv2').innerHTML;
}

fvt.prototype.getVideoObj = function(name) {
  if (navigator.appName.indexOf("Microsoft") != -1) {return window[name]}
  else {return document[name]}
}

fvt.prototype.textSync = function (textIndex,shudZoom) {
  if((typeof(this.getVideoObj(this.videoSwf).playVideo))!='function') {return 0}

  if(this.swfAwake) {clearTimeout(this.swfAwake);}  // TBD not sure
  mboxObj.enableCarDisplay = false;  // block till seeked
  if(shudZoom) {mboxObj.zoom2RoadDp.apply(mboxObj,[textIndex]);}	
  var nearestIndex = mboxObj.syncMapPoints[textIndex];
  // runAll = 1;
  mboxObj.enableCarDisplay = true;  // TBD wait till video play is reint
  this.getVideoObj(this.videoSwf).playVideo(nearestIndex);
}

fvt.prototype.applyEventsSwfPlayer = function () {
  document.getElementById('VideoPlayerDiv').onmouseout=function () {
    if(this.swfMouseRelease) this.swfMouseOut=true;else this.swfMouseOut=false;
  }
  document.getElementById('VideoPlayerDiv').onmousedown=function () {
    this.swfMouseRelease=true;
  }
  if(document.getElementById('body')) {
    document.getElementById('body').onmouseup=function () {
      if(this.swfMouseOut==true && typeof getMovieName("VideoPlaylist").mouseReleased=='function') {
        getMovieName("VideoPlaylist").mouseReleased();
        this.swfMouseRelease=false;
        this.swfMouseOut = false;
      } 
    }	
  }	
}

fvt.prototype.launchVideoPlayerFirstTime = function () {
  this.showLorR('R');
  hasReqestedFlashVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
  if(hasReqestedFlashVersion) {
    if(this.firstLoad) {
      this.loadVideoPlayer();
      this.firstLoad=false;
    } else {
      document.getElementById(this.videoDom).innerHTML=(typeof(this.vidPlayerHTML)==undefined)?'':this.vidPlayerHTML;
    }
  } else {
    document.getElementById(this.videoDom).innerHTML='<br/><br/><a class=maptab style=color:white>Namaskara! <br/>You seem to have Adobe Flash plugin disabled/missing OR Plugin version is old. </a><br/><a href=http://www.adobe.com/go/getflash/ class=maptab style=color:white;text-decoration:underline; >Get the latest flash Plugin</a>';
  }
  this.playerActive = true;
}

fvt.prototype.displayRoute = function(response) {
  this.launchVideoPlayerFirstTime();
  //console.log("directions_div height before "+$('#directions_div').height());
  //console.log("comtab height before "+$('#comtab').height());
  //console.log("routediv height before "+$('#routediv').height());
  var dir=document.getElementById("directions_div");
  $('#directions_div')[0].style.backgroundColor='black';
  if(typeof(__experimentalUI)!='undefined' && __experimentalUI)
    $('#directions_div')[0].style.backgroundColor='white';
  $('#directions_div')[0].style.overflow='hidden';
  //var w=typeof(ioAreaObj.embed)!='undefined'?(parseInt(ioAreaObj.embed.vidWidth)-15):(480-15); 
  //var w=typeof(ioAreaObj.embed)!='undefined'?(parseInt(ioAreaObj.embed.vidWidth)):(480); 
  //var h=typeof(ioAreaObj.embed)!='undefined'?ioAreaObj.embed.vidHeight:169; 
  //var h=typeof(ioAreaObj.embed)!='undefined'?253:169; 
  dir.innerHTML='';
  var innerHTML='';
  innerHTML+="<div class='scrollContainer' id='scroll0ContainerOrig'><div style='left: 0px; top: 0px;' class='scrollContent' id='scroll0ContentOrig'>";
  var tableContent = ""
  tableContent+="<table id='textDirections' width=100% >";
  if(ioAreaObj.embed && ioAreaObj.embed.firstTimeRule && ioAreaObj.embed.firstTimeRule.busId) {
    tableContent+=this.generateBusStops(response);
  } else {
    tableContent+=this.generateTextDirections(response);
  }
  tableContent+="</table>";
  innerHTML += tableContent;
  innerHTML+="</div>";
  innerHTML+="</div>";
  dir.innerHTML=innerHTML;
  //console.log("content height "+$('#scroll0ContentOrig').height());
  //console.log("container height "+$('#scroll0ContainerOrig').height());
  //console.log("directions_div height after "+$('#directions_div').height());
  //console.log("comtab height after "+$('#comtab').height());
  //console.log("routediv height after "+$('#routediv').height());
  if ($('#scroll0ContentOrig').height() > $('#scroll0ContainerOrig').height()) {
    this.addDoubleScroller(dir,$('#scroll0ContainerOrig').width(),$('#directions_div').height(),'scroll0',tableContent);  
  } else { 
    this.theScroll = [];
  } 
}

fvt.prototype.rollTo = function(textIndex) {
  if (typeof(this.theScroll[0]) == 'undefined') { return; }
  var height2Scroll=0;
  for(var i=1;i<=this.noOfTextDirections;i++) {  // TBD mbox obj is it ok ?
    var elem="#textdirrow"+i;
    if(i<=(textIndex)) {height2Scroll+=$(elem)[0].offsetHeight;}
  }
  this.theScroll[0].jumpTo(null,height2Scroll);
  var thumbY = this.theScroll[0].theThumb.minY + Math.round(height2Scroll/this.theScroll[0].theRatio);
  if (thumbY > this.theScroll[0].theThumb.maxY) {
    thumbY=this.theScroll[0].theThumb.maxY ;
  }
  this.theScroll[0].theThumb.style.top = thumbY + "px"; 
  this.theScroll[0].theThumb1.style.top = thumbY + "px"; 
} 

fvt.prototype.addDoubleScroller = function(target,w,h,scrollId,origInnerHTML) {
  var sW = 15; var sH = 15; var sN = 0;
  //TBD dereference fvtObj
  var innerHTML='';
  innerHTML+="<div class='root' id='root0'>";
  innerHTML+="<div style='left: 0px;'class='up' id='up0'><a href='javascript:void(0);' onmouseover='fvtObj.theScroll[0].scrollNorth(0)' onmouseout='fvtObj.theScroll[0].endScroll()' onclick='return false;'><img src='"+imagePathsObj.up+"' height='"+sH+"' width='"+sW+"'></a></div>";
  innerHTML+="<div style='left: 0px;top: "+(h-sH)+"px;' class='dn' id='dn0'><a href='javascript:void(0);' onmouseover='fvtObj.theScroll[0].scrollSouth(0)' onmouseout='fvtObj.theScroll[0].endScroll()' onclick='return false;'><img src='"+imagePathsObj.down+"' height='"+sH+"' width='"+sW+"'></a></div>";
  innerHTML+="<div class='thumb' id='thumb0' style='border: 0pt none ; top: "+sH+"px; left:0px;'><a href='javascript:void(0);'><img src='"+imagePathsObj.thumb+"' height='"+sH+"' width='"+sW+"'></a></div>";

  innerHTML+="<div style='left: "+(w-sW)+"px;' class='up' id='up1'><a href='javascript:void(0);' onmouseover='fvtObj.theScroll[0].scrollNorth(0)' onmouseout='fvtObj.theScroll[0].endScroll()' onclick='return false;'><img src='"+imagePathsObj.up+"' height='"+sH+"' width='"+sW+"'></a></div>";
  innerHTML+="<div style='left: "+(w-sW)+"px;top: "+(h-sH)+"px;' class='dn' id='dn1'><a href='javascript:void(0);' onmouseover='fvtObj.theScroll[0].scrollSouth(0)' onmouseout='fvtObj.theScroll[0].endScroll()' onclick='return false;'><img src='"+imagePathsObj.down+"' height='"+sH+"' width='"+sW+"'></a></div>";
  innerHTML+="<div class='thumb' id='thumb1' style='border: 0pt none ; top: "+sH+"px; left:"+(w-sW)+"px;'><a href='javascript:void(0);'><img src='"+imagePathsObj.thumb+"' height='"+sH+"' width='"+sW+"'></a></div>";
  for(var i=0;i<32;i++)  {
    innerHTML+="<div class='bar' id='bar0_"+i+"' style='border: 0pt none ; top: "+Math.round(sH+i*(h-(sH*2))/32)+"px; left:0px;' height='"+Math.round((h-(sH*2))/32)+"' width='"+sW+"' href='javascript:void(0);' onclick='fvtObj.theScroll[0].theThumb.jumpToIndex("+i+")'></div>";
  }
  for(var i=0;i<32;i++)  {
    innerHTML+="<div class='bar' id='bar1_"+i+"' style='border: 0pt none ; top: "+Math.round(sH+i*(h-(sH*2))/32)+"px; left:"+(w-sW)+"px;' height='"+Math.round((h-(sH*2))/32)+"' width='"+sW+"' href='javascript:void(0);' onclick='fvtObj.theScroll[0].theThumb.jumpToIndex("+i+")'></div>";
  }
  innerHTML +="<div style='left:"+sW+"px; top:0px; width:"+(w-(sH*2))+"px;height:"+h+"px;' class='scrollContainer' id='scroll0Container'><div style='left:0px; top:0px; width:"+(w-(sH*2))+"px;' class='scrollContent' id='scroll0Content'>" + origInnerHTML; 
  innerHTML+="</div>"; 
  innerHTML+="</div>";
  innerHTML+="</div>"; 
  target.innerHTML = innerHTML;
  this.theScroll[0] = new ypSimpleScroll(scrollId,0,0,(w-(sW*2)),h,150);
  this.theScroll[0].load();
  this.theScroll[0].theThumb = document.getElementById('thumb0');
  Drag.init(this.theScroll[0].theThumb,null,0,0,sH,this.theScroll[0].clipH-(sH*2));
  this.theScroll[0].theThumb1 = document.getElementById('thumb1');
  Drag.init(this.theScroll[0].theThumb1,null,this.theScroll[0].clipW+sW,this.theScroll[0].clipW+sW,sH,this.theScroll[0].clipH-(sH*2));
  this.theScroll[0].theRatio = this.theScroll[0].scrollH / (this.theScroll[0].theThumb.maxY - this.theScroll[0].theThumb.minY);
  this.theScroll[0].theThumb.onDrag = function(x, y) {
    fvtObj.theScroll[0].jumpTo(null, Math.round((y - fvtObj.theScroll[0].theThumb.minY) * fvtObj.theScroll[0].theRatio));
    fvtObj.theScroll[0].theThumb1.style.top = y + "px"; 
  }
  this.theScroll[0].theThumb1.onDrag = function(x, y) {
    fvtObj.theScroll[0].jumpTo(null, Math.round((y - fvtObj.theScroll[0].theThumb.minY) * fvtObj.theScroll[0].theRatio));
    fvtObj.theScroll[0].theThumb.style.top = y + "px"; 
  }
  this.theScroll[0].theThumb.jumpToIndex = function(index) {
    fvtObj.theScroll[0].jumpTo(null, Math.round(index*(fvtObj.theScroll[0].theThumb.maxY - fvtObj.theScroll[0].theThumb.minY)/32 * fvtObj.theScroll[0].theRatio));
    fvtObj.theScroll[0].theThumb.style.top = Math.round((index*(fvtObj.theScroll[0].theThumb.maxY-fvtObj.theScroll[0].theThumb.minY)/32)+fvtObj.theScroll[0].theThumb.minY) + "px"; 
    fvtObj.theScroll[0].theThumb1.style.top = Math.round((index*(fvtObj.theScroll[0].theThumb.maxY-fvtObj.theScroll[0].theThumb.minY)/32)+fvtObj.theScroll[0].theThumb.minY) + "px"; 
  }
}

fvt.prototype.generateBusStops = function (response) {
  var innerHTML='';
  for(var i=0;i<response.busStops.length;i++)  {
	innerHTML+='<tr>';
	innerHTML+="<td class='plain' align='center' >"+(i+1)+".</td>";
	innerHTML+="<td class='plain' align='center'>";
	innerHTML+="<a  class='simple' onclick=mboxObj.callBusStopPopup("+i+"); style='color:white;cursor:pointer;' id=busstoptext"+i+">"+response.busStops[i].name+"</a></td>";
	innerHTML+='</tr>';
	innerHTML+="<tr><td></td><td><hr class='vidline'/></td></tr>";
  }
  this.noOfTextDirections = response.busStops.length;
  return innerHTML;	
}

fvt.prototype.generateTextDirections =function (response) {
  var innerHTML='';
  var previousCounts=0;
  for(var i=0;i<response.vid.length;i++)  {
    var classPNG=(MSIE6==true)?"class='pngfixclass'":"''";	
    var cameraDPPopup,whichArrow,tempEmail;
    innerHTML+="<tr id='textdirrow"+(i+1)+"' ><td><div style='color:white;overflow:visible; vertical-align:center' id='dirdiv"+(i+1)+"'>";
    innerHTML+="<table cellspacing=0 cellpadding=0><tr>";
    innerHTML+="<td width=30 height=24 align='center'><img id='textdirpng"+i+"' src='"+response.vid[i].arrowSrc+"' style='cursor:text' "+classPNG+" /></td>";
    var className='plain';
    if(typeof(__experimentalUI)!='undefined' && __experimentalUI) className='plain1';
    innerHTML+="<td class='"+className+"' align='center' width=15>"+(i+1)+".</td>";
    var ck = '';
    className='tiny';
    if(typeof(__experimentalUI)!='undefined' && __experimentalUI) className='tiny1';
    if (response.vid[i].passBy.length > 0) ck += "<br><b class="+className+" ><i> Pass by ";
    if(i>0) previousCounts+=response.vid[i-1].passBy.length;
    for(var j=0;j<response.vid[i].passBy.length;j++) {
      if (j!=0) ck+=", ";
      var className='poi';
      if(typeof(__experimentalUI)!='undefined' && __experimentalUI) className='poi1';
      ck+="<a href=javascript:void(0) class="+className+" onclick='mboxObj.callPopupOneImage("+(j+previousCounts)+")'>"+response.vid[i].passBy[j].name+"</a>";
    }
    className='textdir';
    if(typeof(__experimentalUI)!='undefined' && __experimentalUI) className='textdir1';
    innerHTML+="<td><a onfocus='this.blur();' class='"+className+"' href='javascript:void(0);' onclick='javascript:fvtObj.textSync.apply(fvtObj,["+i+",true]);'>"+response.vid[i].direction+"</a>";
    if (response.vid[i].passBy.length > 0) {
      ck += "</i></b>";
      innerHTML+=ck;
    }
    innerHTML+="</td>";
    for(var j in response.imgData) {
      if(response.imgData[j].dpRoadName) {
        if(response.imgData[i].imgIndex == mboxObj.syncMapPoints[i]) {
          innerHTML+="<td width=45 align='center'><img src='"+imagePathsObj.camera+"' style='cursor:pointer' height='16' href='javascript:void(0)' onClick='mboxObj.callPopupOneImage("+i+")' /></td>";
        }
      }
    }
    innerHTML+="<td width=45 align='center'><img id='dirimage"+(i+1)+"' src='' style='display:none' /></td>";
    innerHTML+="</tr></table></div><hr class='vidline'/></td></tr>";
  }
  this.noOfTextDirections = response.vid.length;
  return innerHTML;
}

fvt.prototype.getStartEndData = function(srf) {
  var which = srf.srfType;
  var data = {};
  data.which = which;
  //data.whichLocation = ioAreaObj.preReqStart;
  data.whichLocation = srf.reqSeed;
  data.sORe = (which=='location') ? 'Location' : 
              (which=='startAddress') ? 'Source' :
              (which=='endAddress') ? 'Destination' : 'Unknown';
  //data.eORs = (which=='location') ? 'Location' : 
  //            (which=='startAddress') ? 'Destination' :
  //            (which=='endAddress') ? 'Source' : 'Unknown';
  //data.startOrEnd = (which=='location') ? ioAreaObj.preReqStart : 
  //                  (which=='startAddress') ? ioAreaObj.preReqStart :
  //                  (which=='endAddress') ? ioAreaObj.preReqEnd : 'Unknown';
  data.startOrEnd = srf.reqSeed;
  //data.endOrStart = (which=='location') ? ioAreaObj.preReqStart : 
  //                  (which=='startAddress') ? ioAreaObj.preReqEnd :
  //                  (which=='endAddress') ? ioAreaObj.preReqStart : 'Unknown';
  data.startCall = (which=='location') ? "ioAreaObj.showSrf.apply(ioAreaObj,[ioAreaObj.srfResponse,'location'])" : 
                   (which=='startAddress') ? "ioAreaObj.showSrf.apply(ioAreaObj,[ioAreaObj.srfResponse,'startAddress'])" :
                    (which=='endAddress') ? "ioAreaObj.showSrf.apply(ioAreaObj,[ioAreaObj.srfResponse,'endAddress'])" : "ioAreaObj.showSrf.apply(ioAreaObj,[ioAreaObj.srfResponse,'location'])";
  data.endCall = (which=='location') ? "ioAreaObj.showSrf.apply(ioAreaObj,[ioAreaObj.srfResponse,'location'])" : 
                   (which=='startAddress') ? "ioAreaObj.showSrf.apply(ioAreaObj,[ioAreaObj.srfResponse,'endAddress'])" :
                    (which=='endAddress') ? "ioAreaObj.showSrf.apply(ioAreaObj,[ioAreaObj.srfResponse,'startAddress'])" : "ioAreaObj.showSrf.apply(ioAreaObj,[ioAreaObj.srfResponse,'location'])";
  return data;
}

fvt.prototype.getStartEndObj = function(srf) {
  var which = srf.parentType;
  var data = {};
  data.which = which;
  //data.whichLocation = ioAreaObj.preReqStart;
  data.whichLocation = srf.reqSeed;
  data.sORe = (which=='location') ? 'Location' : 
              (which=='startAddress') ? 'Source' :
              (which=='endAddress') ? 'Destination' : 'Unknown';
  //data.eORs = (which=='location') ? 'Location' : 
  //            (which=='startAddress') ? 'Destination' :
  //            (which=='endAddress') ? 'Source' : 'Unknown';
  //data.startOrEnd = (which=='location') ? ioAreaObj.preReqStart : 
  //                  (which=='startAddress') ? ioAreaObj.preReqStart :
  //                  (which=='endAddress') ? ioAreaObj.preReqEnd : 'Unknown';
  data.startOrEnd = srf.reqSeed;
  //data.endOrStart = (which=='location') ? ioAreaObj.preReqStart : 
  //                  (which=='startAddress') ? ioAreaObj.preReqEnd :
  //                  (which=='endAddress') ? ioAreaObj.preReqStart : 'Unknown';
  data.startCall = (which=='location') ? "ioAreaObj.displayResults.apply(ioAreaObj,['location',ioAreaObj.response])" : 
                   (which=='startAddress') ? "ioAreaObj.displayResults.apply(ioAreaObj,['startAddress',ioAreaObj.response])" :
                    (which=='endAddress') ? "ioAreaObj.displayResults.apply(ioAreaObj,['endAddress',ioAreaObj.response])" : "ioAreaObj.displayResults.apply(ioAreaObj,['location',ioAreaObj.response])";
  data.endCall = (which=='location') ? "ioAreaObj.displayResults.apply(ioAreaObj,['location',ioAreaObj.response])" : 
                   (which=='startAddress') ? "ioAreaObj.displayResults.apply(ioAreaObj,['endAddress',ioAreaObj.response])" :
                    (which=='endAddress') ? "ioAreaObj.displayResults.apply(ioAreaObj,['startAddress',ioAreaObj.response])" : "ioAreaObj.displayResults.apply(ioAreaObj,['location',ioAreaObj.response])";
  return data;
}

fvt.prototype.clearRouteAndSrf = function () {
  if (this.playerActive) {
    this.playCustomVideo("B|Clearing the video","clear.flv",4,"ClearVideo","clear");
  }
  document.getElementById('locadivinside').innerHTML=fvtObj.clearFvtContent;
  $('#directions_div')[0].style.backgroundColor='white';
  document.getElementById("directions_div").innerHTML='<div style=background-color:white>'+fvtObj.clearFvtContent+'</div>';
}

fvt.prototype.playCustomVideo =function (caption,fileName,duration,roadname,roadtext,customVideo) {
    var playlist = {};
    playlist.img = [];
    playlist.vid = [];
    playlist.vid[0] = {};
    playlist.vid[0].cap =caption;
    playlist.vid[0].video = {};
    playlist.vid[0].video.src = fileName;
    playlist.vid[0].video.duration = duration;
    playlist.vid[0].video.roadname = roadname;
    playlist.NumVvid = [];
    playlist.NumVvid[0] = 0;
    try { playlist.zeroPath = ioAreaObj.response.zeroPath;  }
    catch (e) {}    // TBD not sure what
    playlist.sourceHandle = 0;
    playlist.endHandle = duration;
    playlist.highBwUrl = videoUrl;
    playlist.lowBwUrl = (typeof(videoUrlLb) != 'undefined')?videoUrlLb:'';
    if(customVideo) {
        playlist.highBwUrl=highBwcustomVideoUrl;
        playlist.lowBwUrl=lowBwcustomVideoUrl;
    }
    roadNamesSwf =new Array();
    roadNamesSwf[0] = roadtext;
    durationSwf=new Array();
    durationSwf[0] = 0;
    durationSwf[1] = duration;
    ioAreaObj.response = playlist;
    document.getElementById(this.videoDom).innerHTML = '';
    document.getElementById(this.videoDom).innerHTML=(typeof(this.vidPlayerHTML)==undefined)?'':this.vidPlayerHTML;
    this.playerActive = false;
}

fvt.prototype.changeTextDirectionIfNeeded = function (index) {
  var stringSplit=index.split(":");
  var parentIndex=stringSplit[0];
  var nearestIndex = 0;
  for(var i=0;i<mboxObj.syncMapPoints.length;i++) {  
    if (mboxObj.syncMapPoints[i] > parentIndex) { break; }
    nearestIndex = i;
  }
  if (nearestIndex != this.globalTextIndex) { 
    this.changeTextDirection(nearestIndex); 
  }
}

fvt.prototype.changeTextDirection = function (textIndex) {
  this.globalTextIndex=textIndex; 
  var textDirDivId,arrowImg;
  //var textDirDivId,arrowImg,height2Scroll;
  //height2Scroll=0;
  for(var i=1;i<=mboxObj.syncMapPoints.length;i++) {  // TBD mbox obj is it ok ?
    //var elem="#textdirrow"+i;
    //if(i<=(textIndex)) {height2Scroll+=$(elem)[0].offsetHeight;}
    textDirDivId="dirdiv"+i;
    arrowImg="dirimage"+i;
    document.getElementById(textDirDivId).getElementsByTagName("a")[0].style.fontWeight='normal'
    document.getElementById(textDirDivId).getElementsByTagName("a")[0].style.color='white'
    if(typeof(__experimentalUI)!='undefined' && __experimentalUI) {
      document.getElementById(textDirDivId).getElementsByTagName("a")[0].style.color='black';
    }
    // TBD - there seems to be some murky business here - why everytime ?
    document.getElementById(arrowImg).src='';
    document.getElementById(arrowImg).style.display='none';
  }
  //alert("textChange"+textIndex);
  textDirDivId="dirdiv"+(textIndex+1);
  arrowImg="dirimage"+(textIndex+1);
  document.getElementById(textDirDivId).getElementsByTagName("a")[0].style.color='#FFFF33'
  if(typeof(__experimentalUI)!='undefined' && __experimentalUI) {
    document.getElementById(textDirDivId).getElementsByTagName("a")[0].style.color='blue';
  }
  document.getElementById(textDirDivId).getElementsByTagName("a")[0].style.fontWeight='bold';
  document.getElementById(arrowImg).src=imagePathsObj.arrow;
  document.getElementById(arrowImg).style.display='block';
  this.rollTo(textIndex);
  //$('#directions_div')[0].scrollTop=height2Scroll;
}

fvt.prototype.undoExpandMapPopVideo = function() {
  var elementVar=document.getElementById('videoTd');
  elementVar.className='videosync';
  elementVar.style.position='relative';
  elementVar.style.left='';
  elementVar.style.top='';
  document.getElementById('VideoPlayerDiv').innerHTML=(this.vidPlayerHTML==undefined)?'':this.vidPlayerHTML;
  document.getElementById('maxvideo').style.display="none";
  if(mboxObj.routeActive) {
    this.expaCollapse=true;	
    this.gECIndex = this.globalTextIndex;
  } else {
    document.getElementById('VideoPlayerDiv').innerHTML=''; // TBD
  }
  if(document.getElementById('videoTd').style.visibility=='hidden') {
    this.getBackVideoTd(this);
  }
}

fvt.prototype.expandMapPopVideo = function() {
  
  var elementVar=document.getElementById('videoTd');
  //elementVar.style.borderLeft="0px solid white";
  elementVar.className='popped';
  Drag.init(elementVar);
  elementVar.style.borderLeft.colorValue='#FFCC00';
  elementVar.style.position='absolute';
  elementVar.style.left=(document.body.offsetWidth/2)-240+"px";
  elementVar.style.top=(document.body.offsetHeight/2)-175+"px";
  elementVar.style.zIndex=40000;
  ioAreaObj.toggleButtons({"minvideo":true});
  document.getElementById('maxvideo').style.display="none";
  if(mboxObj.routeActive) {
    this.expaCollapse=true;	
    this.gECIndex = this.globalTextIndex;
  } else {
    document.getElementById('VideoPlayerDiv').innerHTML='';
    this.clearVideoTd();
  }	
}

fvt.prototype.clearVideoTd = function() {
  this.expaCollapse=true;	
  this.gECIndex = this.globalTextIndex;
  document.getElementById('VideoPlayerDiv').innerHTML='';
  document.getElementById('videoTd').style.visibility='hidden';
  document.getElementById('maxvideo').style.display="block";
  document.getElementById('maxvideo').onclick=function () {fvtObj.getBackVideoTd.apply(fvtObj,['maxvideo']);};
}

fvt.prototype.getBackVideoTd = function(caller) {
  document.getElementById('VideoPlayerDiv').innerHTML=(this.vidPlayerHTML==undefined)?'':this.vidPlayerHTML;
  document.getElementById('videoTd').style.visibility='visible';
  document.getElementById('maxvideo').style.display="none";
  if(caller!='govidoption' && caller!='mapexpand') { // caller is maxvideo
    this.expaCollapse=true;	// TBD
    this.gECIndex = this.globalTextIndex;
  //swfAwake=setInterval(function () { textSync(expandIndex); },500);
  }
}

fvt.prototype.swfready = function() {
  if(this.expaCollapse) {
    this.expaCollapse=false;	
    this.textSync(this.gECIndex,false);  // TBD why is it false ?
    return this.gECIndex;
  } else {return 0;}
}



