var w = 997;
var p = new Array();
p[0] = Array('00-home.jpg', '', 0);
p[1] = Array('01-what-we-do.jpg', '', 1);
p[2] = Array('02-our-clients.jpg', '', 2);
p[3] = Array('03-taxstar.jpg', '', 3);
p[4] = Array('04-logos.jpg', '', 3);
p[5] = Array('05-identities.jpg', '', 3);
p[6] = Array('06-ge-money.jpg', '', 3);
p[7] = Array('07-print.jpg', '', 3);
p[8] = Array('08-alife.jpg', '', 3);
p[9] = Array('09-websites.jpg', '', 3);
p[10] = Array('10-goody.jpg', '', 3);
p[11] = Array('11-egg-corp.jpg', '', 3);
p[12] = Array('12-revlon.jpg', '', 3);
p[13] = Array('13-contact.jpg', 'm-contact', 4);

var ct = false;
var c = 0;
var cb = 0;
var cc = false;

window.onload = _td;

function _play()
{
   if (ct)
      _pause();
   else {
      _next();
      ct = setInterval('_next()', 4000);
      domID('play').setAttribute('src', 'pause.gif');
   }
}

function _pause()
{
      clearInterval(ct);
      ct = false;
      domID('play').setAttribute('src', 'play.gif');
}

function _next()
{
   if (c<p.length)
      c++; 
   else {
      if (ct)
      {
         _pause();
         return;
      }
      _goto(0,0);
      _goto(1);
      return;
   }
   _scroll();
}

function _previous()
{
   if (c>0)
      c--
   else
   {
      _goto(p.length,0);
      c = p.length - 1;
   }
   _scroll();
}

function _goto(i, d)
{
   if (i>=0 && i<=p.length)
      c = i;
   else
      c = 0;
   cb = c+2;
   if (d!=undefined)
      _scroll(d);
   else
      _scroll();
}

var a = false;

function _scroll(d)
{
   if (a)
      a.stop();
   cc = true;
   if (d==undefined)
      var d = Math.abs(cb - c);
   cb = c;
   a = new YAHOO.util.Scroll(domID('gui-content'), {scroll: { to: [c*w, 0]}}, 2*d, YAHOO.util.Easing.easeOut);
   if (d==0)
      domID('gui-content').scrollLeft = c*w;
   a.onComplete.subscribe(_scrollF);
   a.animate();
}

function _scrollF()
{
   var obj = domID('gui-navigation').getElementsByTagName('li')[p[c][2]];
   var nav = domID('indicator');
   var l = obj.offsetLeft;
   var w = obj.offsetWidth;
   nav.style.width = w +'px';
   nav.style.left = l +'px';  
}

var pre = 0;

function _td()
{
   domID('gui-content').style.scrollLeft = 0;
   if (pre<p.length)
   {
      var i = document.createElement('img');
       var td =  document.getElementsByTagName('tr')[0].appendChild(document.createElement('td'));
       i.setAttribute('src', p[pre][0]);
       if (p[pre][1].length>0)
         i.setAttribute('usemap', '#'+ p[pre][1]);
       i = td.appendChild(i);
       domEvent(i, 'load', _td);
       pre++;
   } else if (pre==p.length) {
      var i = document.createElement('img');
      var td =  document.getElementsByTagName('tr')[0].appendChild(document.createElement('td'));
      i.setAttribute('src', p[0][0]);
      if (p[0][1].length>0)
      i.setAttribute('usemap', '#'+ p[0][1]);
      i = td.appendChild(i);
   }
   
   if (!cc)
   {
      if (pre==p.length)
      {
         if (document.location.href.toString().indexOf('contact.html')>0)
            _goto(13,0);
         if (document.location.href.toString().indexOf('subscribe.html')>0)
         {
            _goto(13,0);
            newsletter();
         } else if (document.location.href.toString().indexOf('portfolio.html')>0)
            _goto(3,0);
         else if (document.location.href.toString().indexOf('our-clients.html')>0)
            _goto(2,0);
         else if (document.location.href.toString().indexOf('what-we-do.html')>0) 
            _goto(1,0);
         else
            _goto(0,0);
      }
   }
}

function domID(i)
{
   if (document.getElementById)
      return document.getElementById(i);
   else if (document.all)
      return document.all[i];
   else
      return false;
}

function domE(e)
{
   if (!e)
      var e = window.event;
   if (e.target)
      return e.target;
   else if (e.srcElement)
      return e.srcElement;
   else
      return false;
}

function domEvent(o, t, f)
{
   if (o.addEventListener)
      o.addEventListener(t, f, false);
   else if (o.attachEvent)
      o.attachEvent('on'+ t, f);
   else
      return false;
   return true;
}

var ajx_r = false;
var ajx_c = false;
var ajx_u = false;
var ajx_q = false;


function newsletter()
{
    if (e = prompt('Please enter your email address',''))
    {
         document.form['mb-uyljh-uyljh'].value = e;
         document.form.submit();
    }
}
