
function RacingMenu(){
    this.closedBranches = new Array();
}

RacingMenu.prototype.toggleBranch = function( elmNode ){  
    var branch = elmNode.parentNode;

	if( branch.className == "branch-open" ) {        
        this.addClosedBranch( branch.id )
        branch.className = "branch-closed";
    } else {
        this.removeClosedBranch( branch.id )
        branch.className = "branch-open";
    }
	
    this.setCookie();
}

RacingMenu.prototype.addClosedBranch = function( strId) {
    this.closedBranches[ this.closedBranches.length ] = strId;
}

RacingMenu.prototype.removeClosedBranch = function( strId) {
    var newclosedBranches = new Array();
    
    var len = this.closedBranches.length; 
    for( i=0; i<len; i++ ) {
        var currId = this.closedBranches[i];
        if( strId != currId ){
            newclosedBranches[ newclosedBranches.length ] = currId;
        }
    }
    
    this.closedBranches = newclosedBranches;
}

RacingMenu.prototype.openclosedBranches = function() {
    var len = this.closedBranches.length; 
    for( i=0; i<len; i++ ) {
        var branch = document.getElementById( closedBranches[i] );
        branch.className = "branch-open";
    }
    this.closedBranches = new Array()
}

RacingMenu.prototype.setCookie = function() {
    var cookieValue = "";
    var len = this.closedBranches.length; 
	
    for( i=0; i<len; i++ ) {
        cookieValue += this.closedBranches[i];
        if( i < ( len -1 ) ) {
            cookieValue += '-';
        }
    }
	
	//alert(cookieValue);
    
    document.cookie = "HorseMenu="+cookieValue+"; path=/";	
}
	
	
RacingMenu.prototype.toggleVisibility = function() {	
    var items = document.cookie.split(';');
    var str;
    
    for( i=0; i< items.length; i++ ) {
        if (items[i].indexOf('HorseMenu') > -1) {
            str = items[i].split('=');
            str = str[1].split('-');
            //alert(items[i] + ' / ' + str.length);
            for( j=0; j< str.length; j++ ) {
                var branch = document.getElementById( str[j] );
                if (branch != null) {
                    branch.className = "branch-closed";
                    racingMenu.addClosedBranch( branch.id )
                }
            }
            break;
        }
    }
}