// JavaScript Document

/* Code for toggling the paragraphs in the services area */
// P1 is the paragraph being replaced. P2 is the paragraph replacing.
// We assume that P1.style.display != none && P2.style.display == none.
function toggle_p(p1, p2) {
	var p1_style = document.getElementById(p1).style;
	var p2_style = document.getElementById(p2).style;
	p1_style.display = (p1_style.display != 'none' ? 'none' : '' );
	p2_style.display = (p2_style.display != 'none' ? 'none' : '' );	
}

/* Code for showing/hiding a DIV depending on its current status */
function show_hide(div_id) {
	var div = document.getElementById(div_id).style;
	div.display = (div.display != 'none' ? 'none' : '' );
}

/* Code for Teleprompter 
* Created by Jeremy Keith (http://adactio.com) - http://javascript.internet.com/miscellaneous/teleprompter.html
* Adapted by David Quiros (http://www.webproart.com)
*/
var scroll = function(element) {
	var scrolling, inc;
	var pixel_shift = 1;			// pixel_shift: number of pixels the element will move up on each loop			
 	var wait = 80;				
	var breakspace = 50;			// breakspace: amount of space that the bottom of the element will need to exceed 
 									// (considering it's moving up) before it is shown again.
	var getYpos = function() {		
  		var ypos = element.offsetTop;
  		var thisNode = element;
  		while (thisNode.offsetParent &&  (thisNode.offsetParent != document.body)) {
  		 	thisNode = thisNode.offsetParent;			// loop to find the greatest parent in the chain (whether html or body)
  			ypos += thisNode.offsetTop;					// and return the vertical (top) offset of the element from the parent.
 		}
/*		alert ("Element top offset: " + ypos);*/
 		return ypos;
 	};

	var doScroll = function() {
  		var y = parseInt(getYpos(),10);
  		y=y-inc;								// Decreases by 'inc' the current vertical offset of the element (given by getYpos)
		if (y + element.offsetHeight < element.offsetParent.offsetTop - breakspace) {	
			y = element.offsetParent.offsetTop + element.offsetParent.offsetHeight;
		}
  		y=y+"px";								// and sets it to be the new TOP value.
/*		alert ("Element new top offset is going to be: " + y);*/
  		element.style.top = y;					// CAREFUL: the margin value set by CSS will be added to this y coordinate
  		scrolling = window.setTimeout(doScroll,wait);		// so, if margin > inc, the element will move down instead of up
 	};											// This function will run again after 'wait' milliseconds

 	var toggleScrolling = function() {
  		if (scrolling) {
   			window.clearTimeout(scrolling);		// If the element is scrolling then it will stop the next call to 'doScroll'
   			scrolling = null;					// and set 'scrolling' to null
  		} else {
   			doScroll();
  		}
 	};
	inc = parseInt(getYpos(),10) + pixel_shift;
	scrolling = window.setTimeout(doScroll,wait);
 	element.onclick = toggleScrolling;
};

var init = function() {
 	if (document.getElementById && document.getElementById("div_tp_content")) {
		  scroll(document.getElementById("div_tp_content"));
 	}
};

window.onload = init;