
TTLinks={

name: 'TTLinks',
//TTLinksId : 'theTTLinksId',
TTLinksId : 'toolbar',

screenReader : true,
Mp3 : true,
readStory : true,
stop : true,

screenReaderLinkId : 'screenReaderLink',
screenReaderLinkOn : 'Turn screen reader on',
screenReaderLinkOff : 'Turn screen reader off',
screenReaderLinkOnTitle : 'Turn screen reader on',
screenReaderLinkOffTitle : 'Turn screen reader off',

TTcontentId : false,

mp3Link : 'Save as MP3',

readMainStoryLink : 'Read main story',

stopLink : 'Stop reading',

linkBgColor : '#000000',
linkColor : '#ffffff',

//updates link on page load
screenReaderLink : function()
{
 
  try
  {  
    loadedTTCookie = getCookies('loadedTT');
  }
  catch(err)
  {
    setTimeout('TTLinks.screenReaderLink()', 200);
    return 0;
  }
  
  el = document.getElementById(this.screenReaderLinkId);
  el2 = document.getElementById('TTLink1');
  
  if(loadedTTCookie==2)
  {
    el.innerHTML=this.screenReaderLinkOff;
    el2.title=this.screenReaderLinkOffTitle;
  }
  else
  {
    el.innerHTML=this.screenReaderLinkOn;
    el2.title=this.screenReaderLinkOnTitle;
  }
  
},

//toggles screenreader and link
screenReaderToggle : function()
{
  ToggleOnOff();
  
  var el = document.getElementById(this.screenReaderLinkId);
  var el2 = document.getElementById('TTLink1');
   
  if(loadedTT==2)
  {
    el.innerHTML=this.screenReaderLinkOff;
    el2.title=this.screenReaderLinkOffTitle;
  }
  else
  {
    el.innerHTML=this.screenReaderLinkOn;
    el2.title=this.screenReaderLinkOnTitle;
  }
  
},

SaveTT2 : function() 
{ 
  document.TexticTalkSubmit.TextIn.value=seltxt; 
  document.TexticTalkSubmit.Down.value=DLconst; 
  document.TexticTalkSubmit.submit(); 
  document.TexticTalkSubmit.Down.value=0;
},

mp3ById : function()
{
  //dont find story
  setselecttext(1);
  
  //FF thinks seltxt is an object?
  seltxt+='';
  
  if(!seltxt)
  {
  
    elmp3 = document.getElementById(this.TTcontentId);
  
    curtext = elmp3.innerHTML; 
    
    //clear the last text read. 
    lasttext = ""; 
    //Read it. 
  
    seltxt = ReplaceTags(curtext);
  }
    
  this.SaveTT2();

},

saveMp3 : function()
{
  if(this.TTcontentId)
  {
    this.mp3ById();
  }
  else
  {
    SaveTT();
  }
},

readMainStory : function()
{ 
  
  if(this.TTcontentId)
  {
    el = document.getElementById(this.TTcontentId); 
      
    curtext= el.innerHTML;
       
  }
  else
  {
    FindStory();

    curtext= curel.innerHTML;
  
  }

  lasttext="";
  
  curtext= ReplaceTags(curtext);
  
  readit();
  
},

displayTTLinks : function()
{
  
  var TTel = document.getElementById(this.TTLinksId);
  
  var TTLinks='';
  
  //screenreader link
  TTLinks +=(this.screenReader)?'<a href="javascript:'+this.name+'.screenReaderToggle();" id="'+this.screenReaderLinkId+'"   >'+this.screenReaderLinkOn+'</a>':'';

  //mp3 link
  TTLinks +=(this.Mp3)?'<a href="javascript:'+this.name+'.saveMp3();"  >'+this.mp3Link+'</a>':'';

  //read main story link
  TTLinks +=(this.readStory)?'<a href="javascript:'+this.name+'.readMainStory();"  >'+this.readMainStoryLink+'</a>':''; 

  TTLinks +=(this.stop)?'<a href="javascript:TTStopPlaying();"  >'+this.stopLink+'</a>':''; 
  
  TTel.innerHTML = TTLinks;
      
},
displayTTLinks2 : function()
{
  
  
  //screenreader link
  document.getElementById('TTLink1').innerHTML =(this.screenReader)?'<a href="javascript:'+this.name+'.screenReaderToggle();" id="'+this.screenReaderLinkId+'"   >'+this.screenReaderLinkOn+'</a>':'';

  //mp3 link
  document.getElementById('TTLink2').innerHTML =(this.Mp3)?'<a href="javascript:'+this.name+'.saveMp3();"  >'+this.mp3Link+'</a>':'';

  //read main story link
  document.getElementById('TTLink3').innerHTML =(this.readStory)?'<a href="javascript:'+this.name+'.readMainStory();"  >'+this.readMainStoryLink+'</a>':''; 

  document.getElementById('TTLink4').innerHTML =(this.stop)?'<a href="javascript:TTStopPlaying();"  >'+this.stopLink+'</a>':''; 
  
      
},

preserveLinkBackground : function()
{
  //el.style.backgroundColor='red !important';
  
  var el = document.getElementById(this.screenReaderLinkId);
  
  el.onmouseout = function()
  {
    el.style.backgroundColor='#fff';
    el.style.color='#ffffff';
  }

},


innit : function()
{

  setTimeout('TTLinks.displayTTLinks2()', 100);

  setTimeout('TTLinks.screenReaderLink()', 200);

  setTimeout('TTLinks.preserveLinkBackground()', 200);

}

}

// full path to images dir
fullPathImages = themeroot+'/style/images/';
//fullPathImages = 'images/';

//id of links container
TTLinksId = 'toolbar';
// display screen reader link - true/false
TTLinks.screenReader = true;
// display mp3 link - true/false
TTLinks.Mp3 = true;
// display read main story link - true/false
TTLinks.readStory = true;
// display stop link - true/false
TTLinks.stop = true;
// id for screen reader link
TTLinks.screenReaderLinkId = 'screenReaderLink';
// screen reader link on text
//TTLinks.screenReaderLinkOn =  '<img src="'+fullPathImages+'reader.gif"  alt="Turn screen reader on" width="30" height="30" title="Turn screen reader on">';
TTLinks.screenReaderLinkOn =  '<img src="'+fullPathImages+'reader.gif"  alt="Point and Read on" width="30" height="30" title="Point and Read on">';
// screen reader link off text
//TTLinks.screenReaderLinkOff = '<img src="'+fullPathImages+'reader-off.gif"  alt="Turn screen reader off" width="30" height="30" title="Turn screen reader off">';
TTLinks.screenReaderLinkOff = '<img src="'+fullPathImages+'reader-off.gif"  alt="Point and Read off" width="30" height="30" title="Point and Read off">';
// if using element with id for main story text, leave blank to use smart story finder - id/false
TTLinks.TTcontentId = '';
//TTLinks.TTcontentId = 'content';
// mp3 link text
TTLinks.mp3Link = '<img src="'+fullPathImages+'mp3.gif" alt="Save as MP3"  width="30" height="30" title="Save as MP3">';
// main story link text
TTLinks.readMainStoryLink = '<img src="'+fullPathImages+'main-story.gif"  alt="Read main story" title="Read main story" width="30" height="30">';
// stop link text
TTLinks.stopLink = '<img src="'+fullPathImages+'main-story-off.gif"  alt="Stop reading" width="30" height="30" title="Stop reading">';
//links background color - prevents stuck link highlight when turning screen reader off
TTLinks.linkBgColor = '#fff';
//links text color - prevents stuck link highlight when turniing screen reader off
TTLinks.linkColor = '#fff';
screenReaderLinkOnTitle = 'Turn screen reader on';
screenReaderLinkOffTitle = 'Turn screen reader off';


window.onload= TTLinks.innit;

