/*Copyright Ventia Pty Limited. Please do not steal intellectual property.*/

var scroller_els;
var scroller_otherHeight;
var scroller_otherelems;
var scroller_scrollingGridBody;
var scroller_adjustWidth;
var scroller_fixedWidthOtherElement;
function scroller_reset(){
scroller_els=new Array();
scroller_otherHeight=0;
scroller_otherelems=null;
scroller_scrollingGridBody=null;
scroller_adjustWidth=true;
scroller_fixedWidthOtherElement=null;
}
function scroller_onResize(){
var scrollHeight=document.body.scrollHeight;
debug('******************************** SCROLLER *********************');
var wh=getWindowInnerHeight(window);
debug('winheight: '+wh);
debug('scheight: '+scrollHeight);
var h=wh-scroller_otherHeight;
debug('oheight: '+scroller_otherHeight);
debug('height: '+h);
var dw=document.body.scrollWidth;
debug('doc width: '+dw);
var w=getWindowInnerWidth(window);
if(scroller_fixedWidthOtherElement){
if(typeof scroller_fixedWidthOtherElement=='string') scroller_fixedWidthOtherElement=document.getElementById(scroller_fixedWidthOtherElement);
var ww=scroller_fixedWidthOtherElement.offsetWidth;
w-=ww;
}
debug('width: '+w);
var style;
if(h<scrollHeight) scroller_scrollingGridBody=true;
else scroller_scrollingGridBody=false;
for(var i=0;i<scroller_els.length;i++){
var scroller_el=scroller_els[i];
scroller_el.style.height=h;
if(scroller_adjustWidth&&w<dw){
scroller_el.style.width=w;
}
}
debug("scroller_scrollingGridBody= "+scroller_scrollingGridBody);
}
function getTotalHeights(elems){
var total=0;
for(i in elems){
var e=elems[i];
if(typeof e=='string'&&e=="tabContainerId"&&!document.all){
total+=30;
}
else{
if(typeof e=='string') e=document.getElementById(e);
if(e){
debug('he: '+e.offsetHeight);
total+=e.offsetHeight;
}
}
}
return total;
}
function scroller_onLoad(){
scroller_otherHeight=getTotalHeights(scroller_otherelems);
for(var i=0;i<scroller_els.length;i++){
var scroller_el=scroller_els[i];
scroller_el.style.overflow='auto';
}
scroller_onResize();
}
function setInnerScroll(mel,otherelems){
var a=new Array();
a[0]=mel;
setInnerScrollMulti(a,otherelems,false);
}
function setInnerScrollNow(mel,otherelems){
var a=new Array();
a[0]=mel;
setInnerScrollMulti(a,otherelems,true);
}
function setInnerScrollMulti(mels,otherelems,now){
setInnerScrollMulti2(mels,otherelems,now,true)
}
function setInnerScrollMulti2(mels,otherelems,now,onresize){
scroller_reset();
for(var i=0;i<mels.length;i++){
var mel=mels[i];
if(typeof mel=='string') mel=document.getElementById(mel);
if(mel){
scroller_els[scroller_els.length]=mel;
}
}
scroller_otherelems=otherelems;
if(now){
scroller_onLoad();
}
else{
EventManager.addOnLoad(scroller_onLoad);
}
if(onresize){
EventManager.addOnResize(scroller_onResize);
}
}

