scrollObjs = {};
scrollObj.speed = 100; 

scrollSpd = 500;
function scrollObj(win_id, lyr_id, cont_id) {
    this.id = win_id; 
    scrollObjs[this.id] = this;
    this.animString = "scrollObjs." + this.id;
    this.load(lyr_id, cont_id);
}


scrollObj.loadLayer = function(win_id, id, cont_id) {
    if ( scrollObjs[win_id] ) scrollObjs[win_id].load(id, cont_id);
}

scrollObj.prototype.load = function(lyr_id, cont_id) {
    if (!document.getElementById) return;
    var wndo, lyr;
    if (this.lyr_id) {
        lyr = document.getElementById(this.lyr_id);
        lyr.style.visibility = "hidden";
    }
    lyr = document.getElementById(lyr_id);
    wndo = document.getElementById(this.id);
    lyr.style.left = this.x = 0;
    this.wd = cont_id? document.getElementById(cont_id).offsetWidth: lyr.offsetWidth;
    this.maxX = (this.wd - wndo.offsetWidth > 0)? this.wd - wndo.offsetWidth: 0;
    this.lyr_id = lyr_id; 
    lyr.style.visibility = "visible";
    this.on_load(); 
    this.ready = true;
}

scrollObj.prototype.on_load = function() {}  

scrollObj.prototype.shiftTo = function(lyr, x) {
    lyr.style.left = (this.x = x) + "px"; 
}


scrollObj.GeckoTableBugFix = function() {
    var ua = navigator.userAgent;
    if ( ua.indexOf("Gecko") > -1 && ua.indexOf("Firefox") == -1 
        && ua.indexOf("Safari") == -1 && ua.indexOf("Konqueror") == -1 ) {
        scrollObj.hold = [];
        for (var i=0; arguments[i]; i++) {
            if ( scrollObjs[ arguments[i] ] ) {
                var wndo = document.getElementById( arguments[i] );
                var holderId = wndo.parentNode.id;
                var holder = document.getElementById(holderId);
                document.body.appendChild( holder.removeChild(wndo) );
                wndo.style.zIndex = 1000;
                var pos = getPageOffsets(holder);
                wndo.style.left = pos.x + "px"; 
                scrollObj.hold[i] = [ arguments[i], holderId ];
            }
        }
        window.addEventListener("resize", scrollObj.rePositionGecko, true);
    }
}

scrollObj.rePositionGecko = function() {
    if (scrollObj.hold) {
        for (var i=0; scrollObj.hold[i]; i++) {
            var wndo = document.getElementById( scrollObj.hold[i][0] );
            var holder = document.getElementById( scrollObj.hold[i][1] );
            var pos = getPageOffsets(holder);
            wndo.style.left = pos.x + "px"; 
        }
    }
}

function getPageOffsets(el) {
    var left = el.offsetLeft;
    if ( el.offsetParent && el.offsetParent.clientLeft ) {
        left += el.offsetParent.clientLeft;
    }
    while ( el == el.offsetParent ) {
        left += el.offsetLeft;
    }
    return { x:left };
}


scrollObj.scrollBy = function(win_id, x, dur) {
  if ( scrollObjs[win_id] ) scrollObjs[win_id].glideBy(x, dur);
}

scrollObj.scrollTo = function(win_id, x, dur) {
	scrollObj.slideDur = dur;
  if ( scrollObjs[win_id] ) scrollObjs[win_id].glideTo(x, dur);
}


scrollObj.prototype.glideBy = function(dx, dur) {
  if ( !document.getElementById || this.sliding ) return;
  this.slideDur = dur || scrollObj.slideDur;
  this.destX = this.distX = 0;
  this.lyr = document.getElementById(this.lyr_id);
  this.startX = this.x; 
  if (dx < 0) this.distX = (this.startX + dx >= -this.maxX)? dx: -(this.startX + this.maxX);
  else if (dx > 0) this.distX = (this.startX + dx <= 0)? dx: -this.startX;
  
  this.destX = this.startX + this.distX; 
  this.slideTo(this.destX);
}

scrollObj.prototype.glideTo = function(destX, dur) {
  if ( !document.getElementById || this.sliding) return;
  this.slideDur = dur || scrollObj.slideDur;
  this.lyr = document.getElementById(this.lyr_id); 
  this.startX = this.x; 
  this.destX = -Math.max( Math.min(destX, this.maxX), 0);
  this.distX =  this.destX - this.startX;
  this.slideTo(this.destX);
}
scrollObj.prototype.slideTo = function(destX) {
  this.per = Math.PI/(2 * this.slideDur); 
  this.sliding = true;
	this.slideStart = (new Date()).getTime();
	this.aniTimer = setInterval(this.animString + ".doSlide()",10);
  this.on_slide_start(this.startX);
}

scrollObj.prototype.doSlide = function() {
	var elapsed = (new Date()).getTime() - this.slideStart;
	if (elapsed < this.slideDur) {
		var x = this.startX + this.distX * Math.sin(this.per*elapsed);
    this.shiftTo(this.lyr, x); this.on_slide(x);
	} else {
    clearInterval(this.aniTimer); this.sliding = false;
		this.shiftTo(this.lyr, this.destX);
    this.lyr = null; this.on_slide_end(this.destX);
	}
}

scrollObj.prototype.on_slide_start = function() {}
scrollObj.prototype.on_slide = function() {}
scrollObj.prototype.on_slide_end = function() {}

scrollObj.prototype.homeToleft = function(){	
  	document.getElementById("div_1").style.visibility = "visible";
  	scrollObj.scrollTo('wn',0 ,scrollSpd); return false;
}

scrollObj.showleft = function(){
  	document.getElementById("div_1").style.visibility = "visible";
  	scrollObj.scrollTo('wn',0 ,500); return false;
  	document.getElementById("div_1").style.visibility = "visible";
  	document.getElementById("div_1").style.display = "block";
}
scrollObj.showSlide = function(div_id, pos, dur, action){
	if (!(action=="home")){
		if (div_id == 'div_1'){
	  		document.getElementById('maincon1').style.overflowY = "auto";
	  		document.getElementById('maincon2').style.overflow = "hidden";
		}else if (div_id == 'div_2'){
	  		document.getElementById('maincon2').style.overflowY = "auto";
	  		document.getElementById('maincon1').style.overflow = "hidden";
	  		document.getElementById('maincon3').style.overflow = "hidden";
	  	}else if (div_id == 'div_3'){
	  		document.getElementById('maincon3').style.overflowY = "auto";
	  		document.getElementById('maincon2').style.overflow = "hidden";
	  		document.getElementById('maincon4').style.overflow = "hidden";
	  	}else if (div_id == 'div_4'){
	  		document.getElementById('maincon4').style.overflowY = "auto";
	  		document.getElementById('maincon3').style.overflow = "hidden";
	  		if (strUrl.indexOf("howwedo") != -1 || strUrl.indexOf("whatwedo") != -1) {
	  			document.getElementById('maincon5').style.overflow = "hidden";
	  		}
	  	}else if (div_id == 'div_5'){
	  		document.getElementById('maincon5').style.overflowY = "auto";
	  		document.getElementById('maincon4').style.overflow = "hidden";
	  		if (strUrl.indexOf("howwedo") != -1) {
	  			document.getElementById('maincon6').style.overflow = "hidden";
	  		}
	  	}else if (div_id == 'div_6'){
	  		document.getElementById('maincon6').style.overflowY = "auto";
	  		document.getElementById('maincon5').style.overflow = "hidden";
	  	}else if (div_id == 'div_7'){
	  		document.getElementById('maincon7').style.overflowY = "auto";
	  		document.getElementById('maincon6').style.overflow = "hidden";
	  		if (strUrl.indexOf("aboutus") != -1) {
	  			document.getElementById('maincon4').style.overflow = "hidden";
	  		}
	  	}
	  	
	}
  	document.getElementById(div_id).style.visibility = "visible";
  	scrollObj.scrollTo('wn',pos,dur); 
  	if (action == "a1"){  	
  		document.getElementById('column2_4_2').style.overflow = "hidden";
  	}
  	else if (action == "a3"){
  		document.getElementById('column3_4_3').style.overflow = "hidden";
  	}
  	else if (action == "a2"){
  		document.getElementById('column2_4_2').style.overflowY = "auto";
  		document.getElementById('column3_4_3').style.overflowY = "auto";
  	}
  	return false;
}