var mm=false, oldy=0, y=0, thumbtop=0, scrolltop=0,divheight=0,scrollamount=0;

function init(dh,sa)
{
  divheight=dh;
  scrollamount=sa;
  thumbtop=0;
  //scrolltop=0;
  y=0;
  oldy=0;
  scrl = document.getElementById("tdscroll"); 
  scrl.onmousedown = scroll1;
  scrl.onmousemove = scroll;
  scrl.onmouseup = scroll2;
  scrl.onmouseout= scroll2;
}

function scroll1(e)
{
  mm=true;
  if(navigator.appName=="Netscape")
    {
      oldy=e.pageY;
      e.preventDefault();
    }
    else
    {
      oldy=event.clientY;
    }
}

function scroll2()
{
  mm=false;
  scrolltop=thumbtop;
  if(scrolltop<0)
    {
      scrolltop=0;
    }
    else if(scrolltop>155)
    {
      scrolltop=155;
    }
}

function scroll(e)
{
  if(mm==true)
  {
    if(navigator.appName=="Netscape")
    {
      y=e.pageY;
    }
    else
    {
      y=event.clientY;
    }
    thumbtop= scrolltop + y - oldy;
    if(thumbtop<0)
    {
      thumbtop=0;
    }
    else if(thumbtop>155)
    {
      thumbtop=155;
    }
    document.getElementById('dvthumb').style.top=thumbtop + "px";
    scrolltext();
  }
}

function scrollup()
{
  thumbtop=scrolltop;
  thumbtop+=155/scrollamount;
  if(thumbtop>155)
    {
      thumbtop=155;
    }
  document.getElementById('dvthumb').style.top=thumbtop + "px";
  scrolltop=thumbtop;
  scrolltext();
}

function scrolldown()
{
  thumbtop=scrolltop;
  thumbtop-=155/scrollamount;
  if(thumbtop<0)
    {
      thumbtop=0;
    }
  document.getElementById('dvthumb').style.top=thumbtop + "px";
  scrolltop=thumbtop;
  scrolltext();
}

function scrolltext()
{
  document.getElementById('dvscroll').style.top=(-thumbtop*divheight/155) + "px";
}

function getUrlVars()
{
  var vars = [], hash;
  var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
  for(var i = 0; i < hashes.length; i++)
  {
	  hash = hashes[i].split('=');
	  vars.push(hash[0]);
	  vars[hash[0]] = hash[1];
	}
	return vars;
}

function findcat()
{
  var category=getUrlVars();
  cat=category['cat'];
  var ns=false;
  if(navigator.appName=="Netscape")
  {
    ns=true;
  }
  var st=0;
  switch(cat)
  {
    case "vscan":
      st=119;
      if(ns==true)
      {
        st=123;
      }
      initvert(2100,20,st);
      break;
    case "vshape":
      st=32;
      if(ns==true)
      {
        st=33;
      }
      initvert(2100,20,st);
      break;
    case "vscope":
      st=138;
      if(ns==true)
      {
        st=143;
      }
      initvert(2100,20,st);
      break;
    case "vcap":
      st=140;
      if(ns==true)
      {
        st=145;
      }
      initvert(2100,20,st);
      break;
    case "vdesign":
      st=72;
      if(ns==true)
      {
        st=75;
      }
      initvert(2100,20,st);
      break;
    case "vmax":
      st=84;
      if(ns==true)
      {
        st=87;
      }
      initvert(2100,20,st);
      break;
    case "vsense":
      st=100;
      if(ns==true)
      {
        st=104;
      }
      initvert(2100,20,st);
      break;
    case "vtouch":
      st=58;
      if(ns==true)
      {
        st=61;
      }
      initvert(2100,20,st);
      break;
    case "vmap":
      st=16;
      if(ns==true)
      {
        st=16;
      }
      initvert(2100,20,st);
      break;
    case "vsop":
      st=45;
      if(ns==true)
      {
        st=47;
      }
      initvert(2100,20,st);
      break;
  }
initpage(2100,20);
}

function initvert(dh,sa,t)
{
  divheight=dh;
  scrollamount=sa;
  thumbtop=0;
  scrolltop=t;
  y=0;
  oldy=0;
  scrl = document.getElementById("tdscroll"); 
  scrl.onmousedown = scroll1;
  scrl.onmousemove = scroll;
  scrl.onmouseup = scroll2;
  scrl.onmouseout= scroll2;
  scrollup();
}

var tid=0,lft=768;
function initpage(scrolt,scrola)
{
  document.getElementById('tdnews').innerHTML='<div style="position:relative;width:753px;overflow:hidden">'+
    '<div id="divscroll" style="width:2000px;position:relative;left:768px">'+
    'Vertebrand gears up for the international market with a new brand identity.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#00BDB5">|</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
    'Explores JV opportunities in Europe and Middle East.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#00BDB5">|</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
    'Wheels India and Agrimart appoint Vertebrand as &#34;brand custodians&#34;.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#00BDB5">|</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
    'Makes waves in the automobile sector Ashok Leyland, TVS Srichakra.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#00BDB5">|</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
    'Forays into branding in the education sector with NTTF.'+
    '</div>'+
    '</div>';
  if(scrolt!=0)
  {
    init(scrolt,scrola);
  }
  startscroll(2000); //use divscroll(above) width as argument
}
function startscroll(samt)
{
  clearInterval(tid);
  tid=setInterval("movenews("+samt+")",10);
}

function movenews(samt)
{
  lft--;
  document.getElementById('divscroll').style.left=lft + "px";
  if(lft<-samt)
  {
    lft=768;
  }
}

function stopscroll()
{
  clearInterval(tid);
}
