Tooltip.autoFollowMouse = true;
Tooltip.autoHideClick = false;
Tooltip.autoMoveToCursor = true;
Tooltip.showMethod = function (tooltip, options){Effect.Appear(tooltip, options);}
Tooltip.hideMethod = function (tooltip, options){Effect.Fade(tooltip, options);} 

Array.prototype.in_array = function ( obj ) {
	var len = this.length;
	for ( var x = 0 ; x <= len ; x++ ) {
		if ( this[x] == obj ) return true;
	}
	return false;
}
//Event.observe(window, 'scroll', scrollMenu, false);

function scrollMenu() {
	var me = $('menu');
 	
	if (window.pageYOffset)
        ScrollTop = window.pageYOffset;
    else
        ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
     // alert(ScrollTop);
    if(ScrollTop == 0){
    		ScrollTop = ScrollTop+142;
    }
	//new Effect.Move(me,{x:me.left, y: ScrollTop, mode: 'absolute', duration:1.0});
}
function init() {
	/*
	var sect = new Array('Sect1', 'Sect2','Sect1_active', 'Sect2_active');
	//color all current location.
	high.each(function(ev){
			if($(ev)){
				var selected  = $(ev);
				selected.className = $(ev).className+'_active';
				selected.firstChild.src = 'images/sel.gif';
			}
	});
	//alert(document.location);
	for (s = 0; s < sect.length; s++) {		
	    // hide all elements apart from the one with id visible
	    var acc = document.getElementsByClassName(sect[s]);
	    for (i = 0; i < acc.length; i++) {
	        if (acc[i].className == sect[s]) {
		        	if(anc.in_array(acc[i].id)){ 
		          var act = document.getElementById('img_'+acc[i].id);
		           act.src = 'images/min.gif';    
			     }else{
				   acc[i].style.display = 'none';
			     }
	        }
	    }
	}
	*/
	Tooltip.add('trigger', 'tip');
	new Draggable('tip');
	//new Draggable('menu',{constraint:'vertical',handle:'handle'});
	//setTall();
}
function accordion(el, et, lvl) {
	 	var tar = document.getElementById(el);

	 	// IMPORTANT NOTE: the location to these images are rewritten by the static
	 	// CD-ROM generator. If you make changes, please do so to the CDROMGenerator
	 	// class as well.
	 	if(tar.style.display == 'none'){
	 		et.src = 'images/min.gif';
	 	}else{
	 		et.src = 'images/plus2.gif';
	 	}

	 	//new Effect.toggle(el, 'Appear',{duration:0, afterFinish: setTall}); 
	 	if(!navigator.appVersion.match(/\bMSIE\b/)) {
	 		new Effect.toggle(el, 'Appear',{duration:0, afterFinish: setTall}); 
	 	} else {
	 		new Effect.toggle(el, 'Appear',{duration:1}); 
	 	}
}
function addEvent(elm, evType, fn, useCapture) {
    elm["on"+evType]=fn;return;
}
function plusToggle(ev){
		//walk twice.
		var ele = document.getElementById(ev.id).nextSibling.nextSibling;
		Effect.toggle(ele,'appear'); 
		return false;
	}
	/* Ajax Calls */	
function closeTip(event){
		var div = document.getElementById('trigger');
		Tooltip.toggle(div, event);
}
function getPosition(e){
	var left = 0;
	var top  = 0;

	while (e.offsetParent){
		left += e.offsetLeft;
		top  += e.offsetTop;
		e     = e.offsetParent;
	}

	left += e.offsetLeft;
	top  += e.offsetTop;

	return {x:left+5, y:top+5};
}

// IMPORTANT NOTE: This function is rewritten for the static CD-ROM version
// If you make any changes here, please cleck CDROMGenerator::prepareOutputDirs()
// to ensure you don't break it.
function showcourse(course, event, me){
			var div = document.getElementById('trigger');
			var args = 'courseId='+course;
			var ajax = new Ajax.Updater(
				'tip', 
				'course.php', 
				{
						method: 'get', 
						parameters: args, 
						onFailure: handlefail
				}
			);
			if(document.getElementById('tip').isVisible){
				var node = me;
				var tooltip_class = new RegExp("^(.*)\s?tip\s?(.*)$", 'i');
				if (node) {
					var isWithinTooltip = false;
					while (!isWithinTooltip && node.parentNode) {
						// Check if the parent is a close element first, if so, we can break
						// and we still want to close the tooltip
						if (node.className && node.className != null && node.className.match(tooltip_class)) {
							isWithinTooltip = true;
							break;
						}
						node = node.parentNode;
					}
				}
				if(!isWithinTooltip){
					var pos  = getPosition(me);		
					new Effect.Move(document.getElementById('tip'),{ x: pos.x, y: pos.y, mode: 'absolute', duration:0.5});
				}
			}
			else{
				Tooltip.toggle(div, event);	
			}
			
}
function handlefail(request) {
	//$F('course_info') = "Could not retreive course information.";
} 

function setTall() {
	if (document.getElementById) {
		var divs = new Array(document.getElementById('menu'), document.getElementById('content'));

		var maxHeight = 0;
		for (var i = 0; i < divs.length; i++) {
			if(divs[i]) {
				divs[i].style.height = '';
				if (divs[i].offsetHeight > maxHeight) maxHeight = divs[i].offsetHeight;
			}
		}

		for (var i = 0; i < divs.length; i++) {
			if(divs[i]) {
				divs[i].style.height = maxHeight + 'px';
	
				if (divs[i].offsetHeight > maxHeight) {
					divs[i].style.height = (maxHeight - (divs[i].offsetHeight - maxHeight)) + 'px';
				}
			}
		}
	}
}

// Nifty function to add onload events without overwriting
// ones already there courtesy of the lovely and talented
// Simon Willison http://simon.incutio.com/
function addLoadEvent(func) {   
    var oldonload = window.onload;
    if (typeof window.onload != 'function'){
        window.onload = func;
    } else {
        window.onload = function(){
        	oldonload();
        	func();
        }
    }
}

function addResizeEvent(func) {   
    var oldonresize = window.onresize;
    if (typeof window.onresize != 'function'){
        window.onresize = func;
    } else {
        window.onresize = function(){
        oldonresize();
        func();
        }
    }
}

//addEvent(window, "load", init);
addLoadEvent(init);
if(!navigator.appVersion.match(/\bMSIE\b/)) {
	addLoadEvent(setTall);
	addResizeEvent(setTall);
}
