function setAll(display)
{
    if (document.getElementById("glossary") != null)
    {
	    var items = document.getElementById("glossary").getElementsByTagName("li");

	    if (items != null)
	    {
	        var item;
	        var links;

		    for (var i = 0; i < items.length; i++)
		    {
		        item = items[i];
		        
		        if (item.id.substr(0, 8) == "question")
		        {
		            links = item.getElementsByTagName("a");
		            
		            if (links != null && links.length > 0)
		                links[0].className = display != "none" ? "question" : "tooltips";
		        }
		        else if (item.className.substr(0, 6) == "answer")
		        {
		            item.style.display = display;
		        }
			}
				
	        if (display != "none") // block
	        {
	            document.getElementById("collapseall").style.display = "block";
	            document.getElementById("expandall").style.display = "none";
	        }
	        else // none
	        {
	            document.getElementById("collapseall").style.display = "none";
	            document.getElementById("expandall").style.display = "block";
	        }
	    }
	}
}
function glossaryStart() {
    if (document.location.hash) {
        swapAnswer(document.location.hash.substring(9), '');
        document.location.hash = document.location.hash;
    }
}
var currentQuestion = null;
var currentAnswer = null;

function swapAnswer(id, pageName)
{
    var question = document.getElementById("question" + id);

    if (question != null)
    {
        var links = question.getElementsByTagName("a");
        
        if (links != null && links.length > 0)
		    question = links[0];
    }

    var answer = document.getElementById("answer" + id);

    if (question != null && answer != null)
    {
        if (answer.style.display != "block") // none
        {
		    // Register click in instadia
		    if (typeof Instadia_sendEvent == "function" && pageName!="")
			    Instadia_sendEvent("011Ae", "" + pageName + "");
			    
			if (currentQuestion != null)
			    currentQuestion.className = "tooltips";

            currentQuestion = question;
            currentQuestion.className = "tooltips question";

		    if (currentAnswer != null)
			    currentAnswer.style.display = "none";

		    currentAnswer = answer;
		    currentAnswer.style.display = "block";
	    }
	    else
	    {
	        question.className = "tooltips";
	        currentQuestion = null;
	    
		    answer.style.display = "none";
		    currentAnswer = null;
	    }
	}
}




//--------------------------------------------------//
/* MISC

----------------------------------------------------*/

var arrObjHolder=new Array();

/* EVENTHANDLER FOR ONLOAD
----------------------------------------------------*/

function addLoadEvent(func){
	var oldonload=window.onload;
	if(typeof window.onload != 'function'){
		window.onload=func;
	} else {
		window.onload=function(){
			if(oldonload){oldonload();};
			func();
		}
	}
}

/* FUNCTIONS TO INITIATE ON PAGELOAD
----------------------------------------------------*/

addLoadEvent(function(){

	loadTooltips();

});


/* EVENTHANDLER FOR ADDING EVENTS TO OBJECTS
----------------------------------------------------*/

function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

var EventCache = function(){
	var listEvents=[];
	return {
		listEvents: listEvents,
		add: function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush: function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item=listEvents[i];
				if(item[0].removeEventListener){item[0].removeEventListener(item[1], item[2], item[3]);};
				if(item[1].substring(0, 2) != "on"){item[1] = "on" + item[1];};
				if(item[0].detachEvent){item[0].detachEvent(item[1], item[2]);};
				item[0][item[1]] = null;
			};
		}
	};
}();

/* GET ELEMENTS BY CLASSNAME
----------------------------------------------------*/

var getElementsByClassName=function(oElm, strTagName, strClassName){
	var arrElements=(strTagName=='*' && oElm.all)?oElm.all:oElm.getElementsByTagName(strTagName);
	var arrReturnElements=new Array();
	strClassName=strClassName.replace(/\-/g, "\\-");
	var oRegExp=new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0;i<arrElements.length;i++){
		oElement=arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements);
}

/* FUNCTIONALITY FOR NEW TOOLTIPS
----------------------------------------------------*/

var loadTooltips=function(){
	var arrTipElems = getElementsByClassName(document, "*", "tooltips");
	var intElems = arrTipElems.length;
	for(var i=0;i<intElems;i++){
		var TipElm=arrTipElems[i];
		if(TipElm.getAttribute('title')){
			addEvent(TipElm,'mouseover', DisplayTooltip);
		}
	}
}

/* DISPLAY TOOLTIP
----------------------------------------------------*/

var DisplayTooltip=function(event){
	var elmTitle=this.getAttribute('title');
	if(!elmTitle) return;
	this.setAttribute('rel',elmTitle);
	this.setAttribute('title','');
	this.div=document.createElement('div');
	Console.Info(this.div);
	arrObjHolder['infoLyr']=this.div;
	if (document.all) {
		x=event.clientX+document.body.scrollLeft;
		y=event.clientY+document.documentElement.scrollTop;
	}else{
		x=event.pageX;
		y=event.pageY;
	}  
	if(x < 0){x=-500;}
	if(y < 0){y=-500;}  
	this.div.style.left=(x - 30) +'px'; 
	this.div.style.top=(y + 1) +'px'; 
	this.div.id='tooltip-container';
	this.div.zIndex=1000;
	this.div.innerHTML='<em>'+ elmTitle +'</em>';
	document.getElementsByTagName('body')[0].appendChild(this.div);
	addEvent(this,'mouseout', HideTooltip);
}

/* HIDE TOOLTIP
----------------------------------------------------*/

var HideTooltip=function(){
	arrObjHolder['infoLyr'].innerHTML='';
	arrObjHolder['infoLyr'].style.display='none';
	this.setAttribute('title',this.getAttribute('rel'));
}







var Console=function(){
	return {
		Log:function(msg,args){if(typeof console=='undefined') return false;if(!args)args='';console.log(msg,args)},
		Info:function(msg,args){if(typeof console=='undefined') return false;if(!args)args='';console.info(msg,args)},
		Warn:function(msg,args){if(typeof console=='undefined') return false;if(!args)args='';console.warn(msg,args)},
		Error:function(msg,args){if(typeof console=='undefined') return false;if(!args)args='';console.error(msg,args)}
	}
}();