


var charPause = 40;        // msecs between adding a new character to the message
var messagePause = 2000;   // pause between messages
var msg = -1;              // the current message in messages
var message = ''           // set to current message
var idx = 1;               // the index of the last character shown
var icon = null;           // the icon currently displaying


messageTotal = 2;

messages = {
         0:{ticker:"2011 calendar now available---click here", title:"2011 calendar now available---click here", text:"The Peter Brook 2011 calendar is now available for £7.99 plus p&p.Go to accessories to order your copy. ", icon:"specialIcon"},
         1:{ticker:"New show starts 24 september--click here", title:"New show starts 24 september--click here", text:"A new show of Peter Brook originals plus new and old prints will start at the A C Gallery, 11 Bryam Street, Huddersfield on the 24th september.There will be a preview evening on the 23rd september starting at 6.30pm.The gallery telephone number for more information is 01484 423402 ", icon:"specialIcon"}}

// Called from onLoad event
function startTicker()
{
   //If there are newsitems then run the ticker - otherwise do nothing
   if (messageTotal > 0)
   {
      ticker = $("newsTicker");
      ticker.setStyle({display:'block'});
      newsFrame = $("frame");
      Event.observe(ticker, 'click', showItem);
      Event.observe(newsFrame, 'click', hideItem);
      showMessages();
   } else {
       $("newsTicker").setStyle({display:'none', border:'none'});
   }
}

function showMessages()
{
   msg += 1;
   if (msg == messageTotal) {
      msg = 0;
   }
   idx = 1;
   message = messages[msg].ticker;
   t = setTimeout(typeIt, charPause);
}

function typeIt()
{
   //type the current character of the current message
   var data = message.substr(0,idx) + suffix();
   ticker.innerHTML = data;
   idx += 1; //next character
   //if (idx == 5) return;
   if (idx > message.length) {
      t = setTimeout(showMessages, messagePause);
   } else {
      t = setTimeout(typeIt,charPause);
   }
}

function suffix()
{
   if( idx == message.length || (idx % 2) == 1) {
     return '';
   }
   else {
      return '<img id="newscursor" src="images/block_cursor.jpg">';
   }
}


function showItem()
{
   hideItem();
   //popukate template for news item
   tmpl = new Template('<div id="newstitle">#{title}</div><div id="newsparagraph">#{text}</div>')
   data = messages[msg];
   html = tmpl.evaluate(data);
   newsFrame.setStyle({display:'block'});
   icon = $( messages[msg].icon );
   $('currentIcon').src = icon.src;
   //icon.setStyle({display:'block',position:'absolute', left:'127px', top:'145px'})
   $("newsDetail").innerHTML = html;
}

function hideItem() {
   if (icon != null) {
      icon.setStyle({display:'none'}); 
   }
   newsFrame.setStyle({display:'none'});
}



