	/*
	* File: common.js
	*/

	function hide()
	{
		if(hide.arguments.length > 0)
		{
			var el = hide.arguments[0];
			el = (typeof(el) == "string") ? document.getElementById(el) : el;
			if(el && typeof(el) == "object") el.style.display = "none";
		}
		return false;
	}

	function show()
	{
		var display = "block";
		if(show.arguments.length > 0)
		{
			if(show.arguments.length > 1)
			{
				display=show.arguments[1];
			}
			var el = show.arguments[0];
			el = (typeof(el) == "string") ? document.getElementById(el) : el;
			if(el && typeof(el) == "object")el.style.display = display;
		}
		return false;
	}

	function remove()
	{
		if(remove.arguments.length > 0)
		{
			var el = remove.arguments[0];
			el = (typeof(el) == "string") ? document.getElementById(el) : el;
			if(el && typeof(el) == "object") el.parentNode.removeChild(el);
		}
		return false;
	}

	function include(filename)
	{
		var scripts = document.getElementsByTagName("script");
		for(var i in scripts) if(scripts[i].src == filename) return false;

    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', filename);
    html_doc.appendChild(js);
    return false;
	}//include

	// simple email validation
	function validateEmail(val)
	{
		re = /.+\@.+\..+/;
		OK = re.exec(val);
		return (OK);
	}
	
	function expandBox(id, c){
		var e = document.getElementById(id);
		e.className = e.className == c ? "" : c;
	}//expandBox
	
	function setElementOpacity(elem, opacity)
	{
	  var opacityProperty = getOpacityProperty();	
	  if (!elem || !opacityProperty) return;
	  if (opacityProperty == "filter")
	  {
	    elem.style.filter = "alpha(opacity=" + (opacity * 100) + ")";
	  }
	  else
	  {
	    elem.style[opacityProperty] = opacity;
	  }
	}

	function getOpacityProperty()
	{
	  if (typeof document.body.style.opacity == 'string') return 'opacity'; // CSS3 compliant (Moz 1.7+, Safari 1.2+, Opera 9)
	  else if (typeof document.body.style.MozOpacity == 'string') return 'MozOpacity'; // Mozilla 1.6-, Firefox 0.8 
	  else if (typeof document.body.style.KhtmlOpacity == 'string') return 'KhtmlOpacity'; // Konqueror 3.1, Safari 1.1
	  else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) return 'filter'; // Internet Exploder 5.5+
	  return false;
	}
	
	function addEvent(e,f){eval('var o='+e+';if(typeof('+e+')!="function")'+e+'=f;else '+e+'=function(e){if(o)o(e);f(e);}')} 
	
	function cursorePosition(e){
		e = e || window.event;
		var cursor = {x:0, y:0};
		if(e.pageX || e.pageY){
			cursor.x = e.pageX;
			cursor.y = e.pageY;
		}else{
			cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
			cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
		}
		return cursor;
	}//cursorePosition
	
function positionTop(e){var r=0;while(e){r+=e.offsetTop;e=e.offsetParent;}return r;}


function initScroll(){
var SCROLLERS = [];
var SCROLL_M;
var SCROLL_W;

	var scroller = function(id){
		if(!SCROLLERS[id]){
			var s = {content:document.getElementById(id)};
			s.main = s.content.parentNode;
			s.scrollbar = s.main.childNodes[1];
			s.indicator = s.scrollbar.childNodes[0];
			s.indicator_height = s.indicator.offsetHeight;
			s.content_height = s.content.offsetHeight;
			s.main_height = s.main.offsetHeight;
			s.length = s.scrollbar.offsetHeight - s.indicator_height - 2;
			s.position = 0;
			s.indicator_position = function(){return positionTop(s.indicator) + s.indicator_height/2;}
			s.scroll = function(p){
				if(p && s.content_height > s.main_height){
					p = s.position - p;
					if(p < 0) p = 0;
					else if(p > 100) p = 100;
					s.indicator.style.top = Math.round(p*s.length/100) + "px";
					s.content.style.top = "-" + Math.round(p*(s.content_height - s.main_height)/100) + "px";
					s.position = p;
				}
			}
			SCROLLERS[id] = s;
		}
		return SCROLLERS[id];
	}//scroller
	
	var smScroll = function(){SCROLL_M = {id:this.parentNode.parentNode.childNodes[0].id};return false;}
	var emScroll = function(){SCROLL_M = null;}
	var swScroll = function(){SCROLL_W = {id:this.childNodes[0].id};}
	var ewScroll = function(){SCROLL_W = null;}
	
	var mScroll = function(e){
		if(!SCROLL_M) return false;
		var s = scroller(SCROLL_M.id);
		if(s) s.scroll((s.indicator_position() - cursorePosition(e).y)*100/s.length);
	}//mScroll
	
	var wScroll = function(e){
		if(!SCROLL_W) return false;
		var s = scroller(SCROLL_W.id);
		if(s) s.scroll(10*e);
		return true;
	}//wScroll
		
	addEvent("document.onmousemove", mScroll);
	addEvent("onscroll", wScroll);
	addEvent("document.onmouseup", emScroll);
		
	var i, divs = document.getElementsByTagName("div");
	for(i in divs){
		if(divs[i] && divs[i].className && divs[i].className == "scrolled"){
			var content = divs[i];
			var main = divs[i].parentNode;
			var scrollbar = main.childNodes[1];
			var indicator = scrollbar.childNodes[0];
			
			var copy = main.cloneNode(true);
			copy.className += ' pre';
			document.getElementsByTagName("body")[0].appendChild(copy);
			if(copy.childNodes[0].offsetHeight > copy.offsetHeight){
				scrollbar.style.display = "block";
				indicator.onmousedown = smScroll;
				main.onmouseover = swScroll;
				main.onmouseout = ewScroll;
			}
			remove(copy);
		}
	}
	
}//initScroll

var onscroll;

function wheel(event){
	var delta = 0;
	if(!event) event = window.event;
	if(event.wheelDelta){
		delta = event.wheelDelta/120;
		if(window.opera) delta = -delta;
	}else if(event.detail) delta = -event.detail/3;
	if(delta && onscroll && onscroll(delta)){
		if(event.preventDefault) event.preventDefault();
		event.returnValue = false;
	}
}//wheel

if(window.addEventListener) window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;
