﻿// Made by geeeet@ghtml.com
// Keep these two lines and you're free to use this code

// Known bugs :
// If ie4.5 mac, please press apple-t to remove sidebar, otherwise everything is pushed 20px to the right...

// Corrected bugs :
// 25.01.2001 - When the height of the span "content" was less than the height of the span "contentClip" a javascript error occured, function changed : move()
// 21.02.2001 - Scrolling text wasn't selectable in ie, function changed : move()
// 05.03.2001 - Ie x and y coordinates was wrong when page was scrolled, function changed : getMouse()

// 19.04.2001 - Finally able to remove browser-scrollbar if content is longer than the browser is high:
// Just put this in the style-tag right before the end head-tag:
// body {margin-left:0; margin-right:0; margin-top:0; margin-bottom:0; width:100%;height:100%;overflow:hidden}

// Touch me here :-)
var upH = 18; // Height of up-arrow
var upW = 12; // Width of up-arrow
var downH = 18; // Height of down-arrow
var downW = 12; // Width of down-arrow
var dragH = 26; // Height of scrollbar
var dragW = 17; // Width of scrollbar
var scrollH = 144; // Height of scrollbar
var speed = 4; // Scroll speed

// And now... go to the bottom of the page...

// Browser detection
var dom = document.getElementById ? true:false;
var nn4 = document.layers ? true:false;
var ie4 = document.all ? true:false;

var mouseY; // Mouse Y position onclick
var mouseX; // Mouse X position onclick

var clickUp = false; // If click on up-arrow
var clickDown = false; // If click on down-arrow
var clickDrag = false; // If click on scrollbar
var clickAbove = false; // If click above scrollbar
var clickBelow = false; // If click below scrollbar

var timer = setTimeout("",500); // Repeat variable
var upL; // Up-arrow X
var upT; // Up-arrow Y
var downL; // Down-arrow X
var downT; // Down-arrow Y
var dragL; // Scrollbar X
var dragT; // Scrollbar Y
var rulerL; // Ruler X
var rulerT; // Ruler Y
var contentT; // Content layer Y;
var contentH; // Content height
var contentClipH; // Content clip height
var scrollLength; // Number of pixels scrollbar should move
var startY; // Keeps track of offset between mouse and span

// Mousedown
function down(e){
	if((document.layers && e.which!=1) || (document.all && event.button!=1)) return true; // Enables the right mousebutton
	getMouse(e);
	startY = (mouseY - dragT);
	
	// If click on up-arrow
	if(mouseX >= upL && (mouseX <= (upL + upW)) && mouseY >= upT && (mouseY <= (upT + upH))){
		clickUp = true;
		return scrollUp();
	}	
	// Else if click on down-arrow
	else if(mouseX >= downL && (mouseX <= (downL + downW)) && mouseY >= downT && (mouseY <= (downT + downH))){
		clickDown = true;
		return scrollDown();
	}
	// Else if click on scrollbar
	else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= dragT && (mouseY <= (dragT + dragH))){
		clickDrag = true;
		return false;
	}
	else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= rulerT && (mouseY <= (rulerT + scrollH))){
		// If click above drag
		if(mouseY < dragT){
			clickAbove = true;
			clickUp = true;
			return scrollUp();
		}
		// Else click below drag
		else{
			clickBelow = true;
			clickDown = true;
			return scrollDown();
		}
	}
	// If no scrolling is to take place
	else{
		return true;
	}
}

// Drag function
function move(e){
	if(clickDrag && contentH > contentClipH){
		getMouse(e);
		dragT = (mouseY - startY);
		
		if(dragT < (rulerT))
			dragT = rulerT;		
		if(dragT > (rulerT + scrollH - dragH))
			dragT = (rulerT + scrollH - dragH);
		
		contentT = ((dragT - rulerT)*(1/scrollLength));
		contentT = eval('-' + contentT);

		moveTo();
		
		// So ie-pc doesn't select gifs
		if(ie4)
			return false;
	}
}

function up(){
	clearTimeout(timer);
	// Resetting variables
	clickUp = false;
	clickDown = false;
	clickDrag = false;
	clickAbove = false;
	clickBelow = false;
	return true;
}

// Reads content layer top
function getT(){
	if(ie4)
		contentT = document.all.content.style.pixelTop;
	else if(nn4)
		contentT = document.contentClip.document.content.top;
	else if(dom)
		contentT = parseInt(document.getElementById("content").style.top);
}

// Reads mouse X and Y coordinates
function getMouse(e){
	if(ie4){
		mouseY = event.clientY + document.body.scrollTop;
		mouseX = event.clientX + document.body.scrollLeft;
	}
	else if(nn4 || dom){
		mouseY = e.pageY;
		mouseX = e.pageX;
	}
}

// print_var()
function print_var(){
	window.alert("contentT="+ contentT);
	window.alert("dragT="+ dragT);
}

// Moves the layer
function moveTo(){
	if(ie4){
		document.all.content.style.top = contentT;
		document.all.ruler.style.top = dragT;
		document.all.drag.style.top = dragT;
	}
	else if(nn4){
		document.contentClip.document.content.top = contentT;
		document.ruler.top = dragT;
		document.drag.top = dragT;
	}
	else if(dom){
		document.getElementById("content").style.top = contentT + "px";
		document.getElementById("drag").style.top = dragT + "px";
		document.getElementById("ruler").style.top = dragT + "px";
	}
	//window.alert("contentT="+ contentT);
}

// Scrolls up
function scrollUp(){
	getT();
	
	if(clickAbove){
		if(dragT <= (mouseY-(dragH/2)))
			return up();
	}
	
	if(clickUp){
		if(contentT < 0){		
			dragT = dragT - (speed*scrollLength);
			
			if(dragT < (rulerT))
				dragT = rulerT;
				
			contentT = contentT + speed;
			if(contentT > 0)
				contentT = 0;
			
			moveTo();
			timer = setTimeout("scrollUp()",25);
		}
	}
	return false;
}

// Scrolls down
function scrollDown(){
	getT();
	
	if(clickBelow){
		if(dragT >= (mouseY-(dragH/2)))
			return up();
	}

	if(clickDown){
		if(contentT > -(contentH - contentClipH)){			
			dragT = dragT + (speed*scrollLength);
			if(dragT > (rulerT + scrollH - dragH))
				dragT = (rulerT + scrollH - dragH);
			
			contentT = contentT - speed;
			if(contentT < -(contentH - contentClipH))
				contentT = -(contentH - contentClipH);
			
			moveTo();
			timer = setTimeout("scrollDown()",25);
		}
	}
	return false;
}

// reloads page to position the layers again
function reloadPage(){
	location.reload();
}

// Preload
function eventLoader(){
	if(ie4){
		// Up-arrow X and Y variables
		upL = document.all.up.style.pixelLeft;
		upT = document.all.up.style.pixelTop;		
		// Down-arrow X and Y variables
		downL = document.all.down.style.pixelLeft;
		downT = document.all.down.style.pixelTop;
		// Scrollbar X and Y variables
		dragL = document.all.drag.style.pixelLeft;
		dragT = document.all.drag.style.pixelTop;		
		// Ruler Y variable
		rulerT = document.all.ruler.style.pixelTop;		
		// Height of content layer and clip layer
		contentH = parseInt(document.all.content.scrollHeight);
		contentClipH = parseInt(document.all.contentClip.style.height);
	}
	else if(nn4){
		// Up-arrow X and Y variables
		upL = document.up.left;
		upT = document.up.top;		
		// Down-arrow X and Y variables
		downL = document.down.left;
		downT = document.down.top;		
		// Scrollbar X and Y variables
		dragL = document.drag.left;
		dragT = document.drag.top;		
		// Ruler Y variable
		rulerT = document.ruler.top;
		// Height of content layer and clip layer
		contentH = document.contentClip.document.content.clip.bottom;
		contentClipH = document.contentClip.clip.bottom;
	}
	else if(dom){
		// Up-arrow X and Y variables
		upL = parseInt(document.getElementById("up").style.left);
		upT = parseInt(document.getElementById("up").style.top);
		// Down-arrow X and Y variables
		downL = parseInt(document.getElementById("down").style.left);
		downT = parseInt(document.getElementById("down").style.top);
		// Scrollbar X and Y variables
		dragL = parseInt(document.getElementById("drag").style.left);
		dragT = parseInt(document.getElementById("drag").style.top);
		// Ruler Y variable
		rulerT = parseInt(document.getElementById("ruler").style.top);
		// Height of content layer and clip layer
		contentH = parseInt(document.getElementById("content").offsetHeight);
		contentClipH = parseInt(document.getElementById("contentClip").offsetHeight);
		document.getElementById("content").style.top = 0 + "px";
		
	}
	// Number of pixels scrollbar should move
	scrollLength = ((scrollH-dragH)/(contentH-contentClipH));
	// Initializes event capturing
	if(nn4){
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		window.onresize = reloadPage;
	}
	document.onmousedown = down;
	document.onmousemove = move;
	document.onmouseup = up;
}


/* 

  ================================================
  PVII Accordian Panel scripts
  Copyright (c) 2007 Project Seven Development
  www.projectseven.com
  Version: 1.0.4 -build 27
  ================================================
  
*/

var p7AB=false;
var p7ABi=false;
function P7_setAB(){
	if(!document.getElementById){
		return;
	}
	var h,tA=navigator.userAgent.toLowerCase();
	if(window.opera){
		if(tA.indexOf("opera 5")>-1 || tA.indexOf("opera 6")>-1){
			return;
		}
	}
	h=String.fromCharCode(60,115,116,121,108,101,32,116,121,112,101,61,34,116,101,120,116,47,99,115,115,34,62,46,112,55,65,66,99,111,110,116,101,110,116,123,100,105,115,112,108,97,121,58,110,111,110,101,59,125,60,47,115,116,121,108,101,62);
	h+='\n'+String.fromCharCode(60,33,45,45,91,105,102,32,108,116,101,32,73,69,32,55,93,62,60,115,116,121,108,101,62,46,112,55,65,66,44,46,112,55,65,66,32,100,105,118,123,122,111,111,109,58,49,48,48,37,59,125,60,47,115,116,121,108,101,62,60,33,91,101,110,100,105,102,93,45,45,62);
	h+='\n'+String.fromCharCode(60,33,45,45,91,105,102,32,108,116,101,32,73,69,32,54,93,62,60,115,116,121,108,101,62,46,112,55,65,66,44,46,112,55,65,66,99,111,110,116,101,110,116,44,46,112,55,65,66,116,114,105,103,32,97,123,104,101,105,103,104,116,58,49,37,59,125,60,47,115,116,121,108,101,62,60,33,91,101,110,100,105,102,93,45,45,62);
	document.write(h);
}
P7_setAB();
function P7_opAB(){
	var x,c,tC,ab,tB;
	if(document.getElementById){
		ab='p7ABW'+arguments[0];
		tB=document.getElementById(ab);
		tB.p7Aba=arguments;
		x=arguments[3];
		if(x>0&&x<11){
			c='p7ABc'+arguments[0]+'_'+x;
			tC=document.getElementById(c);
			if(tC){
				tC.style.display='block';
			}
		}
		if(!p7ABi){
			p7ABi=true;
			if(window.addEventListener){
				window.addEventListener("load",P7_initAB,false);
			}
			else if(document.addEventListener){
				document.addEventListener("load",P7_initAB,false);
			}
			else if(window.attachEvent){
				window.attachEvent("onload",P7_initAB);
			}
			else if(typeof window.onload=='function'){
				var p7loadit=onload;
				window.onload=function(){
					p7loadit();
					P7_initAB();
				};
			}
			else{
				window.onload=P7_initAB;
			}
		}
	}
}
function P7_initAB(){
	var i,j,ab,tB,tD,tA,op,ob,tg;
	if(!document.getElementById){
		return;
	}
	for(i=10;i>0;i--){
		ab='p7ABW'+i;
		tB=document.getElementById(ab);
		if(tB){
			tA=tB.getElementsByTagName("A");
			tg='p7ABt'+i;
			for(j=0;j<tA.length;j++){
				if(tA[j].id && tA[j].id.indexOf(tg)==0){
					tA[j].onclick=function(){
						return P7_ABtrig(this);
					};
					tA[j].p7ABstate=0;
					tA[j].p7ABpr=ab;
				}
			}
			ob=i+'_'+tB.p7Aba[3];
			P7_ABopen(ob);
		}
	}
	p7AB=true;
	P7_ABurl();
	P7_ABauto();
}
function P7_ABopen(s){
	var a,g,d='p7ABt'+s;
	a=document.getElementById(d);
	g=s.split("_");
	if(g&&g.length>1&&g[1]==99){
		a=P7_randAB(g[0]);
	}
	if(g&&g.length>1&&g[1]=='a'){
		P7_ABall(s);
	}
	else{
		if(a&&a.p7ABpr){
			if(a.p7ABstate==0){
				P7_ABtrig(a);
			}
		}
	}
}
function P7_ABclose(s){
	var a,d='p7ABt'+s;
	a=document.getElementById(d);
	if(a&&a.p7ABpr){
		if(a.p7ABstate==1){
			P7_ABtrig(a);
		}
	}
}
function P7_ABclick(s){
	var a,d='p7ABt'+s;
	a=document.getElementById(d);
	if(a&&a.p7ABpr){
		P7_ABtrig(a);
	}
}
function P7_randAB(r){
	var i,k,j=0,d,dd,tA,a,rD=new Array();
	dd='p7ABW'+r;
	d=document.getElementById(dd);
	if(d){
		tA=d.getElementsByTagName("A");
		for(i=0;i<tA.length;i++){
			if(tA[i].p7ABpr && tA[i].p7ABpr==dd){
				rD[j]=tA[i].id;
				j++;
			}
		}
		if(j>0){
			k=Math.floor(Math.random()*j);
			a=document.getElementById(rD[k]);
		}
	}
	return a;
}
function P7_ABall(s){
	var i,m,d,dd,st,et,tA,g=s.split("_");
	if(g&&g.length==2){
		st=parseInt(g[0]);
		if(st){
			et=st+1;
		}
		else{
			st=1;
			et=11;
		}
		m=p7AB;
		p7AB=false;
		for(i=st;i<et;i++){
			dd='p7ABW'+i;
			d=document.getElementById(dd);
			if(d){
				tA=d.getElementsByTagName("A");
				for(j=0;j<tA.length;j++){
					if(tA[j].p7ABpr && tA[j].p7ABpr==dd){
						if(g[1]=='a' && tA[j].p7ABstate==0){
							P7_ABtrig(tA[j]);
						}
						else if(g[1]=='c' && tA[j].p7ABstate==1){
							P7_ABtrig(tA[j]);
						}
					}
				}
			}
		}
		p7AB=m;
	}
}
function P7_ABurl(){
	var i,h,s,x,d='pab';
	if(document.getElementById){
		h=document.location.search;
		if(h){
			h=h.replace('?','');
			s=h.split(/[=&]/g);
			if(s&&s.length){
				for(i=0;i<s.length;i+=2){
					if(s[i]==d){
						x=s[i+1];
						if(x){
							P7_ABopen(x);
						}
					}
				}
			}
		}
		h=document.location.hash;
		if(h){
			x=h.substring(1,h.length);
			if(x && x.indexOf("pab")==0){
				P7_ABopen(x.substring(3));
			}
		}
	}
}
function P7_ABtrig(a){
	var i,j=null,op,pD,ad,aT,m=true,cp='p7ABc'+a.p7ABpr.substring(a.p7ABpr.length-1);
	var iD=a.id.replace('t','c'),tD=document.getElementById(iD);
	if(tD){
		m=false;
		pD=document.getElementById(a.p7ABpr);
		op=pD.p7Aba;
		if(op[4]==1&&op[1]==1&&a.p7ABstate==1){
			return m;
		}
		tD=pD.getElementsByTagName("DIV");
		for(i=0;i<tD.length;i++){
			if( tD[i].id && tD[i].id.indexOf(cp)>-1 ){
				if(tD[i].id==iD){
					j=i;
					if( a.className=="p7ABtrig_down"){
						a.p7ABstate=0;
						a.className='';
						P7_ABhide(tD[j],op);
					}
					else{
						a.p7ABstate=1;
						a.className="p7ABtrig_down";
						P7_ABshow(tD[j],op);
					}
				}
				else{
					if(op[1]==1){
						ad=tD[i].id.replace('c','t');
						aT=document.getElementById(ad);
						aT.className='';
						aT.p7ABstate=0;
						P7_ABhide(tD[i],op);
					}
				}
			}
		}
	}
	P7_checkEQH();
	return m;
}
function P7_checkEQH(){
	if(typeof(P7_colH2)=='function'){
		P7_colH2();
	}
	if(typeof(P7_colH)=='function'){
		P7_colH();
	}
}
function P7_ABshow(d,op){
	var h,wd,wP,isIE5=(navigator.appVersion.indexOf("MSIE 5")>-1);
	if(p7AB&&op[2]==3){
		d.style.display='block';
		P7_ABfadeIn(d.id,0);
	}
	else if( (p7AB&&op[2]==1||p7AB&&op[2]==2) && !isIE5 ){
		wd=d.id.replace("c","w");
		wP=document.getElementById(wd);
		if(P7_hasOverflow(d)||P7_hasOverflow(wP)){
			d.style.display='block';
			return;
		}
		wP.style.overflow="hidden";
		wP.style.height="1px";
		d.style.display='block';
		h=d.offsetHeight;
		P7_ABglide(wd,1,h,op[2]);
	}
	else{
		d.style.display='block';
	}
}
function P7_ABhide(d,op){
	var h,wd,wP,isIE5=(navigator.appVersion.indexOf("MSIE 5")>-1);
	if((p7AB&&op[2]==1||p7AB&&op[2]==2)&&!isIE5){
		wd=d.id.replace("c","w");
		wP=document.getElementById(wd);
		if(d.style.display!="none"){
			if(P7_hasOverflow(d)||P7_hasOverflow(wP)){
				d.style.display='none';
				return;
			}
			h=wP.offsetHeight;
			wP.style.overflow="hidden";
			P7_ABglide(wd,h,0,op[2]);
		}
	}
	else{
		d.style.display='none';
	}
}
function P7_hasOverflow(ob){
	var s,m;
	s=ob.style.overflow;
	if(!s){
		if(ob.currentStyle){
			s=ob.currentStyle.overflow;
		}
		else if(document.defaultView.getComputedStyle(ob,"")){
			s=document.defaultView.getComputedStyle(ob,"").getPropertyValue("overflow");
		}
	}
	m=(s&&s=='auto')?true:false;
	return m;
}
function P7_ABfadeIn(id,op){
	var d=document.getElementById(id);
	op+=.05;
	op=(op>=1)?1:op;
	if((navigator.appVersion.indexOf("MSIE")>-1)){
		d.style.filter='alpha(opacity='+op*100+')';
	}
	else{
		d.style.opacity=op;
	}
	if(op<1){
		setTimeout("P7_ABfadeIn('"+id+"',"+op+")",40);
	}
}
function P7_ABglide(dd,ch,th,p){
	var w,m,d,wd,wC,tt,dy=10,inc=10,pc=.15;
	d=document.getElementById(dd);
	m=(ch<=th)?0:1;
	if(p==1){
		tt=Math.abs( parseInt( Math.abs(th)-Math.abs(ch) ) );
		inc=(tt*pc<1)?1:tt*pc;
	}
	inc=(m==1)?inc*-1:inc;
	d.style.height=ch+"px";
	if(ch==th){
		if(th==0){
			wd=d.id.replace("w","c");
			wC=document.getElementById(wd);
			wC.style.display="none";
			d.style.height="auto";
		}
		else{
			d.style.height="auto";
		}
		P7_checkEQH();
	}
	else{
		ch+=inc;
		if(m==0){
			ch=(ch>=th)?th:ch;
		}
		else{
			ch=(ch<=th)?th:ch;
		}
		if(d.p7abG){
			clearTimeout(d.p7abG);
		}
		d.p7abG=setTimeout("P7_ABglide('"+dd+"',"+ch+","+th+","+p+")",dy);
	}
}
function P7_ABauto(){
	var i,k,ab,tB,wH,tr,pp;
	wH=window.location.href;
	for(k=1;k<11;k++){
		tr=null;
		ab='p7ABW'+k;
		tB=document.getElementById(ab);
		if(tB&&tB.p7Aba[5]&&tB.p7Aba[5]==1){
			tA=tB.getElementsByTagName('A');
			if(tA){
				for(i=0;i<tA.length;i++){
					if(tA[i].href==wH){
						if(tA[i].p7ABpr){
							tr=tA[i].id.replace('p7ABt','');
							break;
						}
						else{
							tA[i].className="p7ap_currentmark";
							pp=tA[i].parentNode;
							while(pp){
								if(pp.id&&pp.id.indexOf('p7ABc')==0){
									tr=pp.id.replace('p7ABc','');
									break;
								}
								pp=pp.parentNode;
							}
							break;
						}
					}
				}
				if(tr){
					P7_ABopen(tr);
				}
				else{
					if(typeof(p7ABcm)!='undefined'&&p7ABcm.length){
						for(i=0;i<p7ABcm.length;i++){
							if(p7ABcm[i]&&p7ABcm[i].length>0){
								if(k==p7ABcm[i].charAt(0)){
									P7_ABopen(p7ABcm[i]);
								}
							}
						}
					}
				}
			}
		}
	}
}

var SLIDETIMER = 3;
var SLIDESPEED = 3;
var SCROLLTIMER = 3;
var SCROLLSPEED = 2;
//var STARTINGOPACITY = 40;

// handles section to section scrolling of the content //
function slideContent(id,prefix,timer) {
  var div = document.getElementById(id);
  var slider = div.parentNode;
  clearInterval(slider.timer);
  slider.section = parseInt(id.replace(/\D/g,''));
  slider.target = div.offsetTop;
  slider.style.top = slider.style.top || '0px';
  slider.current = slider.style.top.replace('px','');
  slider.direction = (Math.abs(slider.current) > slider.target) ? 1 : -1;
  //slider.style.opacity = STARTINGOPACITY * .01;
  //slider.style.filter = 'alpha(opacity=' + STARTINGOPACITY + ')';
  slider.timer = setInterval( function() { slideAnimate(slider,prefix,timer) }, SLIDETIMER);
}

function slideAnimate(slider,prefix,timer) {
  var curr = Math.abs(slider.current);
  var tar = Math.abs(slider.target);
  var dir = slider.direction;
  if((tar - curr <= SLIDESPEED && dir == -1) || (curr - tar <= SLIDESPEED && dir == 1)) {
    slider.style.top = (slider.target * -1) + 'px';
	//slider.style.opacity = 1;
	//slider.style.filter = 'alpha(opacity=100)';
    clearInterval(slider.timer);
	if(slider.autoscroll) {
	  setTimeout( function() { autoScroll(slider.id,prefix,timer) }, timer * 1000);
	}
  } else {
	var pos = (dir == 1) ? parseInt(slider.current) + SLIDESPEED : slider.current - SLIDESPEED;
    slider.current = pos;
    slider.style.top = pos + 'px';
  }
}

// handles manual scrolling of the content //
function scrollContent(id,dir) {
  var div = document.getElementById(id);
  clearInterval(div.timer);
  var sections = div.getElementsByTagName('div');
  var length = sections.length;
  var limit;
  if(dir == -1) {
    limit = 0;
  } else {
    if(length > 1) {
      limit = sections[length-1].offsetTop;
    } else {
      limit = sections[length-1].offsetHeight - div.parentNode.offsetHeight + 20;
    }
  }
  //div.style.opacity = STARTINGOPACITY * .01;
  //div.style.filter = 'alpha(opacity=' + STARTINGOPACITY + ')';
  div.timer = setInterval( function() { scrollAnimate(div,dir,limit) }, SCROLLTIMER);
}

function scrollAnimate(div,dir,limit) {
  div.style.top = div.style.top || '0px';
  var top = div.style.top.replace('px','');
  if(dir == 1) {
	if(limit - Math.abs(top) <= SCROLLSPEED) {
	  cancelScroll(div.id);
	  div.style.top = '-' + limit + 'px';
	} else {
	  div.style.top = top - SCROLLSPEED + 'px';
	}
  } else {
	if(Math.abs(top) - limit <= SCROLLSPEED) {
	  cancelScroll(div.id);
	  div.style.top = limit + 'px';
	} else {
	  div.style.top = parseInt(top) + SCROLLSPEED + 'px';
	}
  }
}

// cancel the scrolling on mouseout //
function cancelScroll(id) {
  var div = document.getElementById(id);
  //div.style.opacity = 1;
  //div.style.filter = 'alpha(opacity=100)';
  clearTimeout(div.timer);
}

// initiate auto scrolling //
function autoScroll(id,prefix,timer,restart) {
  var div = document.getElementById(id);
  div.autoscroll = (!div.autoscroll && !restart) ? false : true;
  if(div.autoscroll) {
    var sections = div.getElementsByTagName('div');
    var length = sections.length;
    div.section = (div.section && div.section < length) ? div.section + 1 : 1;
    slideContent(prefix + '-' + div.section,prefix,timer);
  }
}

// cancel automatic scrolling //
function cancelAutoScroll(id) {
  var div = document.getElementById(id);
  div.autoscroll = false;
}

function AnimationFrame(left, top, width, height, time)
{
  this.Left = left;
  this.Top = top;
  this.Width = width;
  this.Height = height;
  this.Time = time;
 
  this.Copy = function(frame)
  {
    this.Left = frame.Left;
    this.Top = frame.Top;
    this.Width = frame.Width;
    this.Height = frame.Height;
    this.Time = frame.Time;
  }
 
  this.Apply = function(element)
  {
    element.style.left = Math.round(this.Left) + 'px';
    element.style.top = Math.round(this.Top) + 'px';
    element.style.width = Math.round(this.Width) + 'px';
    element.style.height = Math.round(this.Height) + 'px';
  }
}

function AnimationObject(element)
{
  if(typeof(element) == "string")
    element = document.getElementById(element);
 
  var frames = null; 
  var timeoutID = -1;
  var running = 0;
  var currentFI = 0;
  var currentData = null;
  var lastTick = -1;
  var callback = null;
 
  var prevDir = 0;
 
  this.AddFrame = function(frame)
  {
    frames.push(frame);
  }
 
  this.SetCallback = function(cb)
  {
    callback = cb;
  }
 
  this.ClearFrames = function()
  {
    if(running != 0)
      this.Stop();
    frames = new Array();
    frames.push(new AnimationFrame(0,0,0,0,0));
    frames[0].Time = 0;
    frames[0].Left = parseInt(element.style.left);
    frames[0].Top = parseInt(element.style.top);
    frames[0].Width = parseInt(element.style.width);
    frames[0].Height = parseInt(element.style.height);
    currentFI = 0;
    prevDir = 0;
    currentData = new AnimationFrame(0,0,0,0,0);   
  }
 
  this.ResetToStart = function()
  {
    if(running != 0)
      this.Stop();
    currentFI = 0;
    prevDir = 0;
    currentData = new AnimationFrame(0,0,0,0,0);
    frames[0].Apply(element);
  }
 
  this.ResetToEnd = function()
  {
    if(running != 0)
      this.Stop();
    currentFI = 0;
    prevDir = 0;
    currentData = new AnimationFrame(0,0,0,0,0);
    frames[frames.length - 1].Apply(element);
  }
 
  this.Stop = function()
  {
    if(running == 0)
      return;
    if(timeoutID != -1)
      clearTimeout(timeoutID);
    prevDir = running;
    running = 0;
  }
 
  this.RunForward = function()
  {
    if(running == 1)
      return;
    if(running == -1)
      this.Stop();
    if(frames.length == 1 || element == null)
      return; 
     
    lastTick = new Date().getTime();

    //Start from the begining
    if(prevDir == 0)
    {
      currentFI = 1;
      currentData.Time = 0;
      currentData.Left = parseInt(element.style.left);
      currentData.Top = parseInt(element.style.top);
      currentData.Width = parseInt(element.style.width);
      currentData.Height = parseInt(element.style.height);
      frames[0].Copy(currentData);
    }
    else if(prevDir != 1)
    {
      currentFI++;
      currentData.Time =
          frames[currentFI].Time - currentData.Time;
    }
     
    running = 1;
    animate();
  }
 
  this.RunBackward = function()
  {
    if(running == -1)
      return;
    if(running == 1)
      this.Stop();
    if(frames.length == 1 || element == null)
      return;
       
    lastTick = new Date().getTime();
   
    //Start from the end
    if(prevDir == 0)
    {
      currentFI = frames.length-2;
      currentData.Left = parseInt(element.style.left);
      currentData.Top = parseInt(element.style.top);
      currentData.Width = parseInt(element.style.width);
      currentData.Height = parseInt(element.style.height);
      currentData.Time = frames[frames.length-1].Time;
      frames[frames.length-1].Copy(currentData);
      currentData.Time = 0;
    }
    else if(prevDir != -1)
    {
      currentData.Time =
          frames[currentFI].Time - currentData.Time;
      currentFI--;
    }
     
    running = -1;
    animate();
  }
   
  function animate()
  {
    if(running == 0)
      return;
    var curTick = new Date().getTime();
    var tickCount = curTick - lastTick;
    lastTick = curTick;
   
    var timeLeft =
       frames[((running == -1) ? currentFI+1 : currentFI)].Time
       - currentData.Time;
   
    while(timeLeft <= tickCount)
    {
      currentData.Copy(frames[currentFI]);
      currentData.Time = 0;
      currentFI += running;
      if(currentFI>= frames.length || currentFI <0)
      {
        currentData.Apply(element);
        lastTick = -1;
        running = 0;
        prevDir = 0;
        if(callback != null)
          callback();
        return;
      }
      tickCount = tickCount - timeLeft;
      timeLeft =
        frames[((running == -1) ? currentFI+1 : currentFI)].Time
        - currentData.Time;
    }
   
    if(tickCount != 0)
    {
      currentData.Time += tickCount;
      var ratio = currentData.Time/
        frames[((running == -1) ? currentFI+1 : currentFI)].Time;

      currentData.Left = frames[currentFI-running].Left +
         (frames[currentFI].Left
         - frames[currentFI-running].Left)
         * ratio;

      currentData.Top = frames[currentFI-running].Top +
         (frames[currentFI].Top
         - frames[currentFI-running].Top)
         * ratio;
      currentData.Width = frames[currentFI-running].Width +
         (frames[currentFI].Width
         - frames[currentFI-running].Width)
         * ratio;

      currentData.Height = frames[currentFI-running].Height +
         (frames[currentFI].Height
         - frames[currentFI-running].Height)
         * ratio;
    }
   
    currentData.Apply(element);

    timeoutID = setTimeout(animate, 33);
  }
 
  this.ClearFrames();
}


