
TTLinks={

TTLinksId : 'theTTLinksId',

screenReader : true,
textSize : true,
design : true,
languages : true,
Mp3 : true,
reset : true,
help : true,
readStory : true,
stop : true,
zoomIn : true,
zoomOut : true,
zoomReset : true,

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

TTContentId : false,

mp3Link : 'Save as MP3',
textSizeLink : 'Text size', 
readMainStoryLink : 'Read main story',
stopLink : 'Stop reading',
zoomInLink : 'Zoom in',
zoomOutLink : 'Zoom out',
zoomResetLink : 'Reset zoom',

helpURL : 'http://www.textic.com/help.html',

hindiURL : ' http://translate.google.com/translate?u=http%3A%2F%2Fwww.wiltshire.police.uk%2F&hl=en&ie=UTF8&sl=en&tl=hi',

polandURL : ' http://translate.google.com/translate?u=http%3A%2F%2Fwww.wiltshire.police.uk%2F&hl=en&ie=UTF8&sl=en&tl=pl',

portugalURL : ' http://translate.google.com/translate?u=http%3A%2F%2Fwww.wiltshire.police.uk%2F&hl=en&ie=UTF8&sl=en&tl=pt',

romaniaURL : ' http://translate.google.com/translate?u=http%3A%2F%2Fwww.wiltshire.police.uk%2F&hl=en&ie=UTF8&sl=en&tl=ro',

czechURL : ' http://translate.google.com/translate?u=http%3A%2F%2Fwww.wiltshire.police.uk%2F&hl=en&ie=UTF8&sl=en&tl=cs',

bulgariaURL : ' http://translate.google.com/translate?u=http%3A%2F%2Fwww.wiltshire.police.uk%2F&hl=en&ie=UTF8&sl=en&tl=bg',

croatiaURL : ' http://translate.google.com/translate?u=http%3A%2F%2Fwww.wiltshire.police.uk%2F&hl=en&ie=UTF8&sl=en&tl=hr',

arabicURL : ' http://translate.google.com/translate?u=http%3A%2F%2Fwww.wiltshire.police.uk%2F&hl=en&ie=UTF8&sl=en&tl=ar',


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

//updates link on page load
screenReaderLink : function()
{
 
  try
  {  
    loadedTTCookie = this.getCookie('loadedTT');
  
    el = document.getElementById(this.screenReaderLinkId);
    
    if(loadedTTCookie==2)
    {
      el.innerHTML=this.screenReaderLinkOff;
    }
    else
    {
      el.innerHTML=this.screenReaderLinkOn;
    }
  
  }
  catch(err)
  {
    //alert(err)
    setTimeout('TTLinks.screenReaderLink()', 200);
  }
  
},

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

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
  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();
  
},

resetAll : function()

{

 

  minfSize=12;

 

  minlHeight=17;

  

  theBody.style.fontSize=minfSize+"px";

 

  theBody.style.lineHeight=minlHeight+"px";  

 

  this.clearStyles('clear');

  

  this.deleteCookie('TTfontSize');

 

},





displayTTLinks : function()
{

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

    //text size link
    TTLinks +=(this.textSize)?'<a href="javascript:TTLinks.changeTextSize();">'+this.textSizeLink+'</a>':'';

    //design link
    TTLinks +=(this.design)?'<a href="javascript:TTLinks.cssSwitch(\'clear\');"><img src="TTlinks/images/bgdefault.gif" alt="yellow" /></a><a href="javascript:TTLinks.cssSwitch(\'styleb\');"><img src="TTlinks/images/bgblue.gif" alt="blue" /></a><a href="javascript:TTLinks.cssSwitch(\'stylec\');"><img src="TTlinks/images/bgred.gif" alt="red" /></a><a href="javascript:TTLinks.cssSwitch(\'styled\');"><img src="TTlinks/images/bgyellow.gif" alt="yellow" /></a><a href="javascript:TTLinks.cssSwitch(\'stylee\');"><img src="TTlinks/images/bgblack.gif" alt="reverse" /></a>':'';
 
    //languages link
    TTLinks +=(this.languages)?'<a href="javascript:TTLinks.popup(\''+this.hindiURL+'\');"><img src="TTlinks/images/hindi.gif" alt="Hindi" /></a><a href="javascript:TTLinks.popup(\''+this.polandURL+'\');"><img src="TTlinks/images/poland.gif" alt="Poland" /></a><a href="javascript:TTLinks.popup(\''+this.portugalURL+'\');"><img src="TTlinks/images/portugal.gif" alt="Portugal" /></a><a href="javascript:TTLinks.popup(\''+this.romaniaURL+'\');"><img src="TTlinks/images/romania.gif" alt="Romania" /></a><a href="javascript:TTLinks.popup(\''+this.czechURL+'\');"><img src="TTlinks/images/czech.gif" alt="Czech" /></a><a href="javascript:TTLinks.popup(\''+this.bulgariaURL+'\');"><img src="TTlinks/images/bulgaria.gif" alt="Bulgaria" /></a><a href="javascript:TTLinks.popup(\''+this.croatiaURL+'\');"><img src="TTlinks/images/croatia.gif" alt="Croatia" /></a><a href="javascript:TTLinks.popup(\''+this.arabicURL+'\');"><img src="TTlinks/images/arabia.gif" alt="Arabic" /></a>':'';
  
    //mp3 link
    TTLinks +=(this.Mp3)?'<a href="javascript:TTLinks.saveMp3();">'+this.mp3Link+'</a>':'';

    //reset link
    TTLinks +=(this.reset)?'<a href="javascript:TTLinks.resetAll();  if(loadedTT==3){TTLinks.screenReaderToggle();}">'+this.resetLink+'</a>':'';

    //help link
    TTLinks +=(this.help)?'<a href="javascript:TTLinks.popup(\''+this.helpURL+'\');">'+this.helpLink+'</a>':'';
  
    //read main story link
    TTLinks +=(this.readStory)?'<a href="javascript:TTLinks.readMainStory();">'+this.readMainStoryLink+'</a>':''; 
  
    TTLinks +=(this.stop)?'<a href="javascript:TTStopPlaying();">'+this.stopLink+'</a>':''; 

    TTLinks +=(this.zoomIn)?'<a href="javascript:zoomIn();">'+this.zoomInLink+'</a>':'';

    TTLinks +=(this.zoomOut)?'<a href="javascript:zoomOut();">'+this.zoomOutLink+'</a>':'';

    TTLinks +=(this.zoomReset)?'<a href="javascript:resetZoom();">'+this.zoomResetLink+'</a>':'';
    
    TTel.innerHTML = TTLinks;
  
  }
  catch(e)
  {
    setTimeout('TTLinks.displayTTLinks()', 200);
  }
      
},

preserveLinkBackground : function()
{
  try
  {
    var el = document.getElementById(this.screenReaderLinkId);
  
    el.onmouseout = function()
    {
      el.style.backgroundColor=TTLinks.linkBgColor;
      el.style.color=TTLinks.linkColor;    
    }
  }
  catch(e)
  {
    setTimeout('TTLinks.preserveLinkBackground()', 200);    
  }
  
},

changeTextSize : function()
{
    

  if(this.TTContentId)
    theBody=document.getElementById(this.TTContentId);
  else
    theBody=document.body;

  minfSize=12;
  
  maxfSize=28;

  minlHeight=16;
  
  maxlHeight=35;
  
  currentfSize=theBody.style.fontSize;

  currentlHeight=theBody.style.lineHeight;

  //alert(currentlHeight)
  
  if(!currentfSize)
    currentfSize=minfSize;
  else
    currentfSize=currentfSize.replace('px','')

  if(!currentlHeight)
    currentlHeight=minlHeight;
  else
    currentlHeight=currentlHeight.replace('px','')
  
  currentfSize=currentfSize*1.3;
   
  if(currentfSize>=maxfSize)
    currentfSize=minfSize;

  currentlHeight=currentlHeight*1.3;
   
  if(currentlHeight>=maxlHeight)
    currentlHeight=minlHeight;
  
  theBody.style.fontSize=currentfSize+"px";

  theBody.style.lineHeight=currentlHeight+"px";
  
  this.setCookie('TTfontSize', currentfSize);
  
},

setTextSize : function()
{
  
  try
  {
    currentfSize=this.getCookie('TTfontSize');
        
    if(this.mainContentId)
      theBody=document.getElementById(this.mainContentId);
    else
      theBody=document.body;
      
    theBody.style.fontSize=currentfSize+"px";
  }
  catch(e)
  {
  
  }  

},

setCookie : function(name, value, expires, path, domain, secure)
{

  //cookie is valid throughout dir's
  path='/';

  if (expires) 
  {
  var expireDate = new Date();
  expireDate.setTime(expireDate.getTime() + 3600000*24*expires);
  }
    
  document.cookie= name + "=" + escape(value) +
  ((expires) ? "; expires=" + expireDate.toGMTString() : "") +
  ((path) ? "; path=" + path : "") +
  ((domain) ? "; domain=" + domain : "") +
  ((secure) ? "; secure" : "");

},


getCookie : function(name)
{

  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);

  if (begin == -1)
  {
    begin = dc.indexOf(prefix);
    
    if (begin != 0) 
      return null;
  }
  else
  {
    begin += 2;
  }
  
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
  {
    end = dc.length;
  }
  
  return unescape(dc.substring(begin + prefix.length, end));

},

deleteCookie : function(name, path, domain)
{
  
  //cookie is valid throughout dir's
  path='/';
  
  if (this.getCookie(name))
  {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
  
},

cssAdd : function()
{
  
  for(i=0;i<this.designsArray.length;i++) 
  {
    csshref='TTlinks/css/' + this.designsArray[i] + '.css';
    
    var objHead = document.getElementsByTagName('head');
    var objCSS = document.createElement('link');
    objCSS.rel = 'stylesheet'; 
    objCSS.href = csshref;
    objCSS.type = 'text/css';
    objCSS.id = 'TT'+this.designsArray[i];  
    objHead[0].appendChild(objCSS); 
    objCSS.disabled = true;
   }    

},


setCss : function()
{
  try
  {
    stylePref=this.getCookie('TTstyle');
    this.cssSwitch(stylePref)
  }
  catch(err)
  {
    setTimeout('this.setCss()', 200);
  }
  
},

cssSwitch : function(style)
{
  
  this.clearStyles(style)
  
  this.setCookie('TTstyle', style);
  
},

clearStyles : function(keepStyle)
{ 
  var id, id2;
  
  id="TT"+keepStyle;
  
  for(i=0;i<this.designsArray.length;i++)
  {
    id2="TT"+this.designsArray[i];
    
    if(id==id2)
    {
      document.getElementById(id).disabled=false;
    }
    else
    {
      document.getElementById(id2).disabled=true;
    }
  }
  
  if(keepStyle=='clear') 
  {
    this.setCookie('TTstyle', ' ');
    this.deleteCookie('TTstyle');
  }
    
},

popup : function(url)
{
  pop=window.open(url,'popup','width=800,height=900,scrollbars=yes,resizable=yes'); 
},

addScript : function()
{
  var d = document;
  var h = d.getElementsByTagName("head")[0];
  var s = d.createElement("SCRIPT");
  s.src = "http://s3.talklets-secure.com/Talklets2/jsLaunch.aspx";
  s.type = "text/javascript";
  h.appendChild(s);
},

innit : function()
{

  TTLinks.addScript();

  TTLinks.cssAdd();

  TTLinks.displayTTLinks();

  TTLinks.screenReaderLink();

  TTLinks.setCss();
  
  TTLinks.setTextSize();

},

checkReady : function()
{
  
  var compstate='';
  
  try
  {
    compstate = document.readyState
  }
  catch(e)
  {}
  
  if(navigator.appName == "Microsoft Internet Explorer")
  {
    if( document.body && (compstate == "interactive" || compstate == "complete") )
    {
      TTLinks.innit();
    }
    else
    {
      setTimeout('TTLinks.checkReady()', 200);
    }
  }
  else
  {
      TTLinks.innit();
  }
  

} 
  
}


//id of links container
TTLinks.TTLinksId = 'theTTLinksId';
// display screen reader link - true/false
TTLinks.screenReader = true;
// display text size link - true/false
TTLinks.textSize = true;
// display design link - true/false
TTLinks.design = true;
// display languages link - true/false
TTLinks.languages = true;
// display mp3 link - true/false
TTLinks.Mp3 = true;
//reset link
TTLinks.reset = true;
//help link
TTLinks.help = true;

// display read main story link - true/false
TTLinks.readStory = false;
// display stop link - true/false
TTLinks.stop = false;
// display zoom in - true/false
TTLinks.zoomIn = false;
// display zoom out - true/false
TTLinks.zoomOut = false;
// display zoom reset - true/false
TTLinks.zoomReset = false;
// id for screen reader link
TTLinks.screenReaderLinkId = 'screenReaderLink';
// screen reader link on text
TTLinks.screenReaderLinkOn =  '<img src="TTlinks/images/screenreaderon.gif" alt="Switch Talking Text ON" />';
// screen reader link off text
TTLinks.screenReaderLinkOff = '<img src="TTlinks/images/screenreaderoff.gif" alt="Switch Talking Text OFF" />';
// if using element with id for main story text, leave blank to use smart story finder - id/false
TTLinks.TTContentId = 'TTcontent';
// textsize link text
TTLinks.textSizeLink = '<img src="TTlinks/images/textsize.gif" alt="Change text size" />';
// mp3 link text
TTLinks.mp3Link = '<img style="float: left;" src="TTlinks/images/mp3.gif" alt="MP3" />';
// reset link text
TTLinks.resetLink = '<img style="float: left;" src="TTlinks/images/reset.gif" alt="reset" />';
// help link text
TTLinks.helpLink = '<img style="float: left;" src="TTlinks/images/help.gif" alt="help" />';

TTLinks.helpURL = 'http://www.textic.com/help.html';

TTLinks.designsArray = new Array("stylea", "styleb", "stylec", "styled", "stylee");

// main story link text
TTLinks.readMainStoryLink = 'Read main story';
// stop link text
TTLinks.stopLink = 'Stop reading';
// zoom in link text
TTLinks.zoomInLink = 'Zoom in';
// zoom out link text
TTLinks.zoomOutLink = 'Zoom out';
// resret zoom  link text
TTLinks.zoomResetLink = 'Reset zoom';
//links background color - prevents stuck link highlight when turning screen reader off
TTLinks.linkBgColor = '#ffffff';
//links text color - prevents stuck link highlight when turniing screen reader off
TTLinks.linkColor = '#0033FF';

window.onload = TTLinks.checkReady;







