var elementtop = 0;
var pageheight= 0;
var bottompos = 0;
var maxheight;
var maxwidth;
var newheight;
var leftpanelheight;
var rightpanelheight;
var minheight = 100;
var isrolldownrunning = false;
var isrolluprunning = false;

rD = {
init: function(container_id,content_id){
	
	var d = document.getElementById(container_id);	
	d.style.backgroundImage = "url(newsflash/arrow_up_7.png)";
	
	var contentheight = rD.getHeight(content_id);
	contentheight += 10;
	d.style.height = contentheight;

	pageheight = rD.getPageheight();

	
	
	},
//James Padolsey  james.padolset.com
getDocHeight: function()  {
	
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
},	
getPageheight: function (){
	return document.documentElement.clientHeight;
},

getHeight: function (id){

var h = document.getElementById(id).offsetHeight;

return h;
},

getWidth: function (id){

var h = document.getElementById(id).offsetWidth;

return h;
},

reset: function (){
	
	maxheight = 0;
	newheight = 0;
	isrolldownrunning = false;
	isrolluprunning = false;	
},

roll: function (container_id, content_id){
		
	if(isrolldownrunning || isrolluprunning){return;}

var containerheight = rD.getHeight(container_id);
var contentheight = rD.getHeight(content_id);

if(contentheight > containerheight){
	
	rD.rollDown(container_id, content_id);
}
else{
	rD.rollUp(container_id, content_id);
}

},

rollUp: function (container_id, content_id){
	
	
if(!isrolluprunning){

newheight = rD.getHeight(container_id);
leftpanelheight = rD.getHeight('left_panel');
rightpanelheight = rD.getHeight('right_panel');
isrolluprunning = true;

}

newheight -= 5;
leftpanelheight -= 5;
rightpanelheight -= 5;

if(newheight <= minheight){
	rD.reset();
	var d = document.getElementById(container_id);
	d.style.backgroundImage = "url(newsflash/arrow_down_7.png)";
return;
}

if(rD.getDocHeight() > pageheight ){

	window.scrollBy(0,-5);
}

var d = document.getElementById(container_id);
d.style.height = newheight + 'px';
var d2 = document.getElementById('left_panel');
d2.style.height = leftpanelheight + 'px';
var d3 = document.getElementById('right_panel');
d3.style.height = rightpanelheight + 'px';
setTimeout (function(){rD.rollUp(container_id, content_id)}, 10);

},

rollDown: function (container_id, content_id){
	

if(!isrolldownrunning){
		
maxheight = rD.getHeight(content_id);
newheight = rD.getHeight(container_id);
leftpanelheight = rD.getHeight('left_panel');
rightpanelheight = rD.getHeight('right_panel');
isrolldownrunning = true;

}

newheight += 5;
leftpanelheight += 5;
rightpanelheight += 5;

if(newheight > maxheight +20){
	rD.reset();
	var d = document.getElementById(container_id);
	d.style.backgroundImage = "url(newsflash/arrow_up_7.png)";

	
return;
}


if(rD.getDocHeight() > pageheight + 50){

	window.scrollBy(0,5);

}

var d = document.getElementById(container_id);
d.style.height = newheight + 'px';
var d2 = document.getElementById('left_panel');
d2.style.height = leftpanelheight + 'px';
var d3 = document.getElementById('right_panel');
d3.style.height = rightpanelheight + 'px';
setTimeout (function(){rD.rollDown(container_id, content_id)}, 10);

}
};
