var fuckingie=0;
var ScrollBarsCount = 0;

var scrollHeight = new Array();
scrollHeight[1]=87;
scrollHeight[2]=280;
scrollHeight[3]=0;
scrollHeight[4]=0;

var scrollBarHeight = new Array();
scrollBarHeight[1]=0; 
scrollBarHeight[2]=0; 
scrollBarHeight[3]=0; 
scrollBarHeight[4]=0; 

var maxscrollpos = new Array();
maxscrollpos[1]=0;
maxscrollpos[2]=0;
maxscrollpos[3]=0;
maxscrollpos[4]=0;

var elid =  'jsscroll';
var barid = 'scrollbar';
var scrollStep = 5;
var scrollTop = 0;
var curId="1";
var three=3;


function hide(id)
{
 var sb = document.getElementById(id);
 if (sb)
	sb.style.display="none";
}


function show(id)
{
 var sb = document.getElementById(id);
 if (sb)
	sb.style.display="block";
}


s=navigator.userAgent;
x=s.search(/Safari/);
var safari=0;
if (x!=-1) safari=1;

x=s.search(/Opera/);
var opera=0;
if (x!=-1) opera=1;


function scroll(sc)
{
 var el = document.getElementById(elid+curId);

 Top=parseInt(el.style.marginTop+0);
// scrollTop=parseInt(Top.substring(0,Top.length-2));
 scrollTop=Top;

 scrollTop += scrollStep*sc*three;
 if (scrollTop > 0) 
  scrollTop = 0;
  
 hght= el.offsetHeight-scrollHeight[parseInt(curId)];
	    
 if (scrollTop<-hght)
   scrollTop=-hght;  

 var z=-(scrollTop/hght)*maxscrollpos[parseInt(curId)];
 var xel = document.getElementById("scrollbar"+curId);
 ttt=xel.style.marginTop;
 
 xel.style.marginTop=z+"px";
 el.style.marginTop = scrollTop+"px";
}



function scrollPercent(percent,snum)
{
  s=elid; 
  s=s+snum;
  var ell = document.getElementById(s);
  tty= -percent*(ell.offsetHeight-scrollHeight[snum]);
  tty=Math.round(tty);
/*  hght= ell.offsetHeight-scrollHeight[snum];
*/
  ell.style.marginTop = tty+"px";
/*  var z=-(scrollTop/hght)*maxscrollpos[snum];
  var xel = document.getElementById("scrollbar"+snum);
  ttt=xel.style.marginTop;

  xel.style.marginTop=z+"px";*/

  autoexec();
}


var ie=document.all;
var nn6=document.getElementById&&!document.all;
var isdrag=false;
var y,x;
var dobj;

function movemouse(e)
{
  if (isdrag)
  {
    s=dobj.id;
    snum=s.charAt(s.length-1);
    yy  = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
    
    if (snum=="1" || snum=="2" || snum=="3")
     {
      if (yy<0) { yy=0; }
      if (yy>maxscrollpos[snum]) {  yy=maxscrollpos[snum];  }
      dobj.style.marginTop=yy+"px";
      scrollPercent(yy/maxscrollpos[snum],snum);
     }
    return false;
  }
}

function selectmouse(e) 
{
  var fobj       = nn6 ? e.target : event.srcElement;
  var topelement = nn6 ? "HTML" : "BODY";

  while ( (fobj.tagName != topelement && fobj.className != "dragme1") && (fobj.tagName != topelement && fobj.className != "dragme2") && (fobj.tagName != topelement && fobj.className != "dragme3")  && (fobj.tagName != topelement && fobj.className != "dragme4"))
  {
    fobj = nn6 ? fobj.parentNode : fobj.parentElement;
  }

  if ( (fobj.className=="dragme1") || (fobj.className=="dragme2") || (fobj.className=="dragme3") || (fobj.className=="dragme4") )
  {
    isdrag = true;
    dobj = fobj;

    ty = parseInt(dobj.style.marginTop+0);
    y = nn6 ? e.clientY : event.clientY;

    document.onmousemove=movemouse;
    return false;
  }
}

 document.onmousedown=selectmouse;
 document.onmouseup=new Function("isdrag=false");



function hanldeScroll(e)
{
 if (ScrollBarsCount==0) return;

 e = (e) ? e : window.event;
 
 src= nn6 ? e.target : event.srcElement; 
// 
//  alert(src.id);
if (src.nodeType==3)
 src=src.parentNode;
if (!src.id && !src.parentNode)
	return;
while (src && src.id!=null && src.id.substring( 0 , src.id.length-1)!="jsscroll" && src.id.substring( 0 , src.id.length-1)!="jsscrollclip")
	 {
	   if (src.parentNode==null)
		{
			return;
		}
	   if (src.parentNode!=null)
		src=src.parentNode;
	 }
 if (!src)
  return; 
 
 if (src.id==null)
  return;

 curId=src.id.charAt(src.id.length-1);
 sbd=document.getElementById("scrollbar"+curId).style.display; 
 if (document.getElementById("scrollbar"+curId).style.display!='block')
 	return;
 var delta = (e.wheelDelta) ? e.wheelDelta : e.detail;
 


 if (fuckingie || safari || opera) ie=1; else ie=-1;
 
 if (delta>0)
  scroll(1*ie);
 else 
  scroll(-1*ie);  
}


if (safari)
document .onmousewheel = hanldeScroll;
else
 {
  if(document.attachEvent)
  document.attachEvent("onmousewheel", hanldeScroll);
  else
  window.addEventListener("DOMMouseScroll", hanldeScroll, false);
 }

function scrolltohref()
{
reg=/[?&]scroll=(.*)$/;
arr=reg.exec(document.location);
if (!arr) return;
if (!arr[1]) return;
gotoobj=document.getElementById(arr[1]);
if (!gotoobj) return;
top1=gotoobj.offsetTop;
oldThree=three;
three=1;
oldScrollStep=scrollStep;
scrollStep=1;
scroll(-1*top1);
scrollStep=oldScrollStep;
three=oldThree;
}

function autoexec()
{
 for (n=1; n<ScrollBarsCount+1; n++)   // n<4
 {
  s=elid;
  s=s+n;
  bar=barid;
  bar=bar+n;
  var el = document.getElementById(s);
  var csb= document.getElementById("contentsb"+barid);
  if(el)
	  t=el.offsetHeight;

  if (t>scrollHeight[n])
   {
    show(bar);
    if (csb)
	show(csb);
    yy=scrollHeight[n]*scrollHeight[n]/t;
    var sb = document.getElementById(bar);
    yy=Math.round(yy);
    if (sb) sb.style.height=yy+"px";
    scrollBarHeight[n]=yy;
    maxscrollpos[n]=scrollHeight[n]-scrollBarHeight[n];
   }
  else
   {
    hide(bar);
    if (csb)
 	hide(csb);
   }    
 }
 scrolltohref();
}
