var moveableArea; 
var divRatio;    
var ScrollDiv="";
var InnerDiv="";
var scrollDivH="";
var containDivH="";

//Initialize the scrollbar on page load.  (id of the scrollbar, id of the inner div, id of the outer div)
function initializeScrollbar(id, div, containDiv)
{
	
	//masterRatio controls the size of the 'handle' in the scrollbar. Also used to determine scrollbar handle position at all times in ratio to amount the div has scrolled.
	//Default to 1 to work it out based on the actual content vs height ratio.
	var masterRatio=1;
	
	//hide the normal scrollbars, set div to fixed width
	document.getElementById(containDiv).style.overflow="hidden";
	document.getElementById(containDiv).scrollTop=999999; //to force calculation of heights below
	
	//get the height of the involved areas
	containDivH=document.getElementById(containDiv).offsetHeight; //the outer div (overflow hidden - fixed size usually)
	scrollDivH=document.getElementById(containDiv).offsetHeight+document.getElementById(containDiv).scrollTop;         //the inner div (overflow showing - variable size)
    divRatio=(containDivH/scrollDivH);              //the amount available for viewing on screen expressed as a portion of the total height
	document.getElementById(containDiv).scrollTop=0;//reset to top of area by default
	
	//get the height of the up and down images
	var upAr=new Image();
	upAr.src="images/arrowUp.jpg";
	var downAr=new Image();
	downAr.src="images/arrowDown.jpg";
	downAr.height=document.getElementById('scrollDown').offsetHeight;
	upAr.height=document.getElementById('scrollUp').offsetHeight;
	
	//work out the available scrolling area, and the size of the dragging handle
	var scrollbarH=document.getElementById(id).offsetHeight; 
	var scrollArea=document.getElementById('scrollbarArea');
	scrollArea.style.position="absolute";
	scrollArea.style.top=(upAr.height)+"px";
	scrollArea.style.height=(scrollbarH-upAr.height-downAr.height)+"px";
	var scrollbarHandle=document.getElementById('scrollHandle');
	scrollbarHandle.style.position="absolute";
	scrollbarHandle.style.top="0px";
	scrollbarHandle.style.width="100%";
	scrollbarHandle.style.height=((Number(scrollArea.style.height.replace("px",""))*divRatio)*masterRatio)+"px";
	moveableArea=(Number(scrollArea.style.height.replace("px","")))-(Number(scrollbarHandle.style.height.replace("px","")));
	ScrollDiv=containDiv;
	InnerDiv=div;
	
	if(divRatio<1){
		document.getElementById(id).style.visibility="visible";
	}
	else{
	document.getElementById(id).style.visibility="hidden";	
	}

}

//Scrolling variables
var scrollTimer;
var ScrollPos=0;
var timeOut=0;
var Scrolling=0;



//Function to call when beginning to scroll on mousedown/over
function scrollDirection(dir, div, inner){
	if(dir=="up" && Scrolling==0){
		clearInterval(scrollTimer);
		ScrollDiv=div;
		InnerDiv=inner;
	    Scrolling=1;
		scrollTimer=setInterval('scrollDiv(-13)',25);
	}
	else if(dir=="down" && Scrolling==0){
	ScrollDiv=div;
		clearInterval(scrollTimer);
		ScrollDiv=div;
		InnerDiv=inner;
		Scrolling=1;
		scrollTimer=setInterval('scrollDiv(13)',25);	
	}
}



//Scroll the Div by a given number of px
function scrollDiv(step){
	var cur=document.getElementById(ScrollDiv).scrollTop;
	ScrollPos=cur+step;
	document.getElementById(ScrollDiv).scrollTop = ScrollPos;
	if(((scrollDivH)-(containDivH)) ==0 )
					  {
					  var percentScrolled=0;  
					  }
	else{
		
	var percentScrolled= ( (document.getElementById(ScrollDiv).scrollTop) / ((scrollDivH)-(containDivH)));
	}
	document.getElementById('scrollHandle').style.marginTop=(percentScrolled*moveableArea)+"px";	
}


function stopScroll()
{
clearInterval(scrollTimer);
Scrolling=0;
}



////////////////////////////////////////////////
//from http://adomas.org/javascript-mouse-wheel/
function handle(delta) {
	if (delta < 0){
		scrollDiv(12);
		}
	else{
		scrollDiv(-12);
		}
}

function wheel(event){
	var delta = 0;
	if (!event) event = window.event;
	if (event.wheelDelta) {
		delta = event.wheelDelta/120; 
		if (window.opera) delta = -delta;
	} else if (event.detail) {
		delta = -event.detail/3;
	}
	if (delta)
		handle(delta);
}

/* Initialization code. */
if (window.addEventListener)
	window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;

////////////////////////////////////////////////







function swapContent(URL){
	    var iframeEl = window.frames['loader'];	
		iframeEl.location=URL;
}

function loadFromIFRAME(){
	var iframeEl=window.frames['loader'];
	var doc = iframeEl.document.body.innerHTML;
	doc=doc.replace(" class=\"MsoNormal\"","");
	doc=doc.replace(" class=\"Section"," class=\"par");
	doc=doc.replace(/Wingdings/g,"Arial");
	
document.getElementById('panelMiddleText').innerHTML=doc;
document.getElementById('panelMiddle').scrollTop=0;
var tables = document.getElementById('panelMiddleText').getElementsByTagName('table');
for (i=0; i<tables.length; i++) {
	var rows=tables[i].getElementsByTagName('td');
	for(k=0; k<rows.length; k++){
	rows[k].style.border='none';
	}
	var headings=tables[i].getElementsByTagName('h1');
	for(j=0; j<headings.length; j++){
	headings[j].style.fontSize='11px';	
	}
}

initializeScrollbar('scrollbar', 'panelMiddleText', 'panelMiddle')
scrollDiv(-1);
}