var RowSelector =
{
	rowClassName: "hwjsRowSelector",
	selectClassName: "selected",
	rowsArr: new Array(),
	init:function()
	{
		if( Core.getElementsByClassName( RowSelector.rowClassName, document, "TR" ).length != 0 )
		{
			//find all the rows
			RowSelector.rowsArr = Core.getElementsByClassName( RowSelector.rowClassName, document, "TR" );
			//find the radio buttons within the rows
			var radioArr = new Array();
			for( var i=0; i<RowSelector.rowsArr.length; i++ )
			{
				//add the radio button to the list
				var temp = RowSelector.rowsArr[i].getElementsByTagName( "INPUT" )[0];
				temp.row = RowSelector.rowsArr[i];//store the reference to the parent. This should make it easier to find in the click handler
				radioArr[radioArr.length] = temp;
			}
			//assign the event handlers. note - this could be done in the loop above
			for( var j=0; j<radioArr.length; j++ )
			{
				Core.addEventListener( radioArr[j], "click", RowSelector.clickHandler );
				//deal with the first load case
				if( radioArr[j].checked )
				{
					radioArr[j].row.className += " " + RowSelector.selectClassName;
				}
			}
		}
	},
	clickHandler:function( event )
	{
		//clear all the other rows of the selected class name
		RowSelector.clearAll();
		//find the parent row and give it a class
		this.row.className += " " + RowSelector.selectClassName;
		return;
	},
	clearAll:function()
	{
		for( var i=0; i<RowSelector.rowsArr.length; i++ )
		{
			if( Core.hasClass( RowSelector.rowsArr[i], RowSelector.selectClassName ) )
			{
				Core.removeClass( RowSelector.rowsArr[i], RowSelector.selectClassName );
			}
		}
	}
};
var HelpLink =
{
	containerClassName: "helpBubbleContainer",
	outerClassName: "helpBubble",
	innerClassName: "helpBubbleInner",
	imgClassName: "helpBubbleImg",
	leftVal: "",
	init:function()
	{
		if( Core.getElementsByClassName( HelpLink.containerClassName, document, "SPAN" ).length != 0 )
		{
			var containerArr = Core.getElementsByClassName( HelpLink.containerClassName, document, "SPAN" );
			for( var i=0; i<containerArr.length; i++ )
			{	
				//get hold of the image witin the span
				var imageTemp = containerArr[i].getElementsByTagName( "IMG" )[0];
				//build the spans
				var outerSpan = document.createElement( "span" );
				outerSpan.className = HelpLink.outerClassName;
				var innerSpan = document.createElement( "span" );
				innerSpan.className = HelpLink.innerClassName;
				var imageSpan = document.createElement( "span" );
				imageSpan.className = HelpLink.imgClassName;
				var textTemp = document.createTextNode( imageTemp.title );
				innerSpan.appendChild( imageSpan );
				innerSpan.appendChild( textTemp );
				outerSpan.appendChild( innerSpan );
				containerArr[i].appendChild( outerSpan );	
				HelpLink.leftVal = Core.getComputedStyle( outerSpan, "left" );
				outerSpan.style.display = "none";			
				//let the image have a reference to the outer span
				imageTemp.spanRef = outerSpan;
				//assign the event handler to many actions
				Core.addEventListener( imageTemp, "mouseover", HelpLink.helpHandlerOn );
				//off actions
				Core.addEventListener( imageTemp, "mouseout", HelpLink.helpHandlerOff );
			}
		}
	},
	helpHandlerOn:function( event )
	{
		this.spanRef.style.left = "-9999px";
	 	this.spanRef.style.display = "";
		//get the height of the element we will show
		var boxHeight = this.spanRef.scrollHeight;
		var topValue = (boxHeight)*-1;
		this.spanRef.style.top =  topValue + "px";
		this.spanRef.style.left = HelpLink.leftVal;
	},
	helpHandlerOff:function( event )
	{
	 	this.spanRef.style.display = "none";
	}
};
var SkipLink = 
{
	oldSkipClassName: "skipLink",
	newSkipClassName: "hwjsSkipLink",
	init:function()
	{
		if( Core.getElementsByClassName( SkipLink.oldSkipClassName, document, "P" ).length != 0 )
		{
			var skipLinks = Core.getElementsByClassName( SkipLink.oldSkipClassName, document, "P" );
			for( var i=0; i<skipLinks.length; i++ )
			{
				Core.addEventListener( skipLinks[i], "focus", SkipLink.focusHandler );
				Core.addEventListener( skipLinks[i], "blur", SkipLink.blurHandler );
			}
		}
	},
	focusHandler:function( event )
	{
		this.className += " " + SkipLink.newSkipClassName;
	},
	blurHandler:function( event )
	{
		Core.removeClass( this, SkipLink.newSkipClassName )
	}
};
var WeirLevels = 
{
	weirId: "weirContainer",
	weirInfoClass: "weirInfo",
	selectedStateClass: "selected",
	ddList: new Array(),
	dtList: new Array(),
	init:function()
	{
		//see if the element is within the page
		if( document.getElementById( WeirLevels.weirId, document, "DIV" ) )
		{
			//find the elements and assign the right handlers
			var outerDiv = document.getElementById( WeirLevels.weirId, document, "DIV" );
			WeirLevels.dtList = document.getElementsByTagName( "DT" );
			WeirLevels.ddList = document.getElementsByTagName( "DD" );
			for( var i=0; i<WeirLevels.dtList.length; i++ )
			{
				WeirLevels.dtList[i].siblingRef = WeirLevels.ddList[i];
				WeirLevels.ddList[i].style.display = "none";
				Core.addEventListener( WeirLevels.dtList[i], "mouseover", WeirLevels.mouseOverHandler );
				//Core.addEventListener( dtList[i], "mouseout", WeirLevels.mouseOutHandler );					
			}
			//get the initial state working
			WeirLevels.dtList[0].className = WeirLevels.selectedStateClass;
			WeirLevels.ddList[0].style.display = "";
			WeirLevels.ddList[0].className = WeirLevels.weirInfoClass;	
		}
	},
	mouseOverHandler:function( event )
	{
		WeirLevels.hideAll();
		this.className = WeirLevels.selectedStateClass;
		this.siblingRef.style.display = "";
		this.siblingRef.className = WeirLevels.weirInfoClass;	
	},
	mouseOutHandler:function( event )
	{
		this.siblingRef.style.display = "none";
		Core.removeClass( this.siblingRef, WeirLevels.weirInfoClass )
	},
	hideAll:function()
	{
		for( var i=0; i<WeirLevels.dtList.length; i++ )
		{
			if( Core.hasClass( WeirLevels.dtList[i], WeirLevels.selectedStateClass ) )
			{
				Core.removeClass( WeirLevels.dtList[i], WeirLevels.selectedStateClass )
				WeirLevels.dtList[i].siblingRef.style.display = "none";
				Core.removeClass( WeirLevels.dtList[i].siblingRef, WeirLevels.weirInfoClass )
				return;
			}
		}
	}
};
Core.start( WeirLevels );