// Thanks to all those  responsible for the indespensable getElementsByClassName function below; details of those honoured can be found here:
// http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/#comment-1584

function getElementsByClassName(oElm, strTagName, oClassNames){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var arrRegExpClassNames = new Array();
    if(typeof oClassNames == "object"){
        for(var i=0; i<oClassNames.length; i++){
            arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
        }
    }
    else{
        arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
    }
    var oElement;
    var bMatchesAll;
    for(var j=0; j<arrElements.length; j++){
        oElement = arrElements[j];
        bMatchesAll = true;
        for(var k=0; k<arrRegExpClassNames.length; k++){
            if(!arrRegExpClassNames[k].test(oElement.className)){
                bMatchesAll = false;
                break;                      
            }
        }
        if(bMatchesAll){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}

// and now my code...


var myrules = {
	
	'.link' : function(element){
		element.onclick = function(){
			contentSwitch(this,this.id);
			return false;
		}
		
	}
};

Behaviour.register(myrules);
	 
function init() { 
	
	showLatest();
		

};

Behaviour.addLoadEvent(init);


function showLatest() {
	
		var content = new Array();
		
		content = getElementsByClassName(document, "div", "content");
		
		anchorId = content[0].id.substring(7);
				
		
		document.getElementById(content[0].id).style.display = "block";
		
		document.getElementById(anchorId).className = "link, current";				
		
}

function contentSwitch(anchor,id) {
	
		//this takes out the second class from any of the nav elements...
		
		toBeReset = getElementsByClassName(document, "a", "link, current");
		
		for(var i=0;i<toBeReset.length;i++){
		
		toBeReset[i].className = "link";
	}
		targetContent = "content"+id; 
		
		var content = new Array();
		
		content = getElementsByClassName(document, "div", "content");
		
		//  This hides all the content divs to begin with (resets it effectively so it can loop)
		
		for(var i=0;i<content.length;i++){

			content[i].style.display = "none";
		} 
		// Then this changes the corrent one back to visible  
		
		document.getElementById(targetContent).style.display = "block";
				
		
		//this gives the clicked anchor the new current class...
		
		anchor.className = "link, current";
		
	
}





