function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function makeTitle(){
    allNodes = document.getElementsByClassName("module");
    for(i = 0; i < allNodes.length; i++) {
        title = allNodes[i].firstChild.firstChild;
        image = allNodes[i].firstChild.firstChild.firstChild.firstChild;
        box = allNodes[i].parentNode;
        
        title.onmouseover = function(){
            this.oldsrc = this.firstChild.firstChild.src;
            
            if(this.parentNode.className == 'expanded'){
                this.firstChild.firstChild.src = '/img/hideModBlue.gif';
            }else{
                this.firstChild.firstChild.src = '/img/showModBlue.gif';
            }
            
            //click
            this.firstChild.firstChild.onmouseup=function(){
                if (this.parentNode.parentNode.parentNode.className == 'expanded'){
                    this.parentNode.parentNode.parentNode.className = 'collapsed';
                    this.src = '/img/showModBlue.gif';
                }else{
                    this.parentNode.parentNode.parentNode.className = 'expanded';
                    this.src = '/img/hideModBlue.gif';
                }
                return false;
            }
            this.firstChild.firstChild.onclick=function(){
                return false;
            }
        }
        title.onmouseout = function(){
            this.firstChild.firstChild.src=this.oldsrc;
        }
        
        var defaultView = readCookie('ecoExpandAll');
        if (defaultView == 1){
            title.parentNode.className = 'expanded';
        } else {
            title.parentNode.className = 'collapsed';
        }
    }
}

function expandAllModules(){
    allNodes = document.getElementsByClassName("module");
    for(i = 0; i < allNodes.length; i++) {
        allNodes[i].firstChild.className = 'expanded';
    }
    createCookie('ecoExpandAll','1',365);
}

function collapseAllModules(){
    allNodes = document.getElementsByClassName("module");
    for(i = 0; i < allNodes.length; i++) {
        allNodes[i].firstChild.className = 'collapsed';
    }
    eraseCookie('ecoExpandAll')
}