function showmapbox(id) {
	var obj=document.getElementById('map_box_'+id);
	if(obj!=null) obj.style.display='block';
}

function hidemapbox(id) {
	var obj=document.getElementById('map_box_'+id);
	if(obj!=null) obj.style.display='none';
}

function showhide(id) {
	var obj=document.getElementById(id);
	if(obj!=null) {
		if(obj.style.display=='none') obj.style.display='block';
		else obj.style.display='none';
	}
}

function scroll_number(num) {
	var obj;
	
	//Show the new message and hide all other messages:
	obj=document.getElementById('messages');
	if(obj!=null) {
		for(var i_node=0; i_node<obj.childNodes.length; i_node++) { //for all children
			var node=obj.childNodes[i_node];
			if(node.nodeType==1 && node.className=='message') { //this is an element-type node and ...
				if(node.id=='message_'+num) {
				    changeOpac(0, node.id);
				    opacity(node.id, 0, 100, 1000); //fade it in
				    node.style.display='block';
				}
				else {
				    node.style.display='none';
			    }
			}
		}
	}

	//Update the dialler:
	obj=document.getElementById('scroll_numbers');
	if(obj!=null) {
		for(var i_node=0; i_node<obj.childNodes.length; i_node++) { //for all children
			var node=obj.childNodes[i_node];
			if(node.nodeType==1 && node.nodeName=='A') { //this is an element-type node and ...
				if(node.id=='scroll_button_'+num) node.className='current';
				else node.className='';
			}
		}
	}
}

function scroll_forward() {scroll_increment(1);}
function scroll_back() {scroll_increment(-1);}

function scroll_increment(increment) {
	var obj;
	
	//Find the current number:
	var current=1;
	var total_count=0; //the total number of messages - to be used later
	obj=document.getElementById('scroll_numbers');
	if(obj!=null) {
		for(var i_node=0; i_node<obj.childNodes.length; i_node++) { //for all children
			var node=obj.childNodes[i_node];
			if(node.nodeType==1 && node.nodeName=='A') { //this is an element-type node and ...
			    total_count=total_count+1;
			    if(node.className=='current') {
			        current=parseInt(node.innerHTML);
			    }
			}
		}
	}
	
	//Increment current and see if such a message exists:
	current=current+increment;
	obj=document.getElementById('scroll_button_'+current)
	if(obj==null) {
	    if(increment>=0) current=1;
	    else current=total_count;
	}
	
	//Go:
	scroll_number(current);
}

function scroll_automatic() {
    if(!scroll_stopped) scroll_forward();
    setTimeout('scroll_automatic()', 20000);
}

var scroll_stopped=false;
function scroll_stop() {scroll_stopped=true;}
function scroll_start() {scroll_stopped=false;}


/*Fade-in/fade-out functions, adapted from: http://brainerror.net/scripts/javascript/blendtrans/ */
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
        setTimeout("clear_filter('" + id + "')", (timer * speed)+1);
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
        setTimeout("clear_filter('" + id + "')", (timer * speed)+1);
    }
}

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function clear_filter(id) {
    var object = document.getElementById(id).style;
    object.removeAttribute('filter');
}
/*end of fade-in/fade-out functions*/