/**
Adds border images to block level elements by adding additional nodes within these elements.
*/
com.soulfresh.Borders = function( vStyle, vElementName, vTest )
{
	
	// if an element name was not passed, default to div
	vElementName = ( vElementName == undefined || vElementName == null ) ? "div" : vElementName;
	
	// get the nodes to which we wish to add corners
	var divs = document.getElementsByTagName( vElementName );
	var bordered_divs = [];
	
	// locate all divs with vStyle in their class attribute
	for (var i = 0; i < divs.length; i++) 
	{
		if ( divs[i].className.indexOf( vStyle ) > -1 )
			bordered_divs.push( divs[i] );
	}
	
	// add additional divs to each of the divs we have found
	for (var i = 0; i < bordered_divs.length; i++) 
	{
		// declare variables
		var original = bordered_divs[i];
		var vId = original.id;
		var vContent = original.innerHTML;
		
		// change the classname so that non-js browsers use the original styles
		original.className = original.className.replace( vStyle, "" );
		
		// remove the content from the original container
		original.innerHTML = "";
		
		// if the original element had an id
		if( vId != "" && vId != null && vId != undefined )
			// reset the original's id to something like "styleIdName"
			original.id = vStyle + vId.substring( 0, 1 ).toUpperCase() + vId.substring( 1, vId.length );
		
		// create a div to contain the content from the original element
		var vContentDiv = document.createElement( "div" );
		vContentDiv.innerHTML = vContent;
		
		// if the original element had an id
		if ( vId != "" && vId != null && vId != undefined )
			// give the new content element the id from the original element
			vContentDiv.id = vId;
			
		// remove the original's classname and give it to the new content div
		vContentDiv.className = original.className;
		original.className = "";
		
		// Now create the bordering divs
		var tr = document.createElement( "div" );
		tr.className = vStyle + "T";
		var br = document.createElement( "div" );
		br.className = vStyle + "R";
		var bl = document.createElement( "div" );
		bl.className = vStyle + "B";
		var tl = document.createElement( "div" );
		tl.className = vStyle + "L";
		
		// Now glue the nodes back into the document
		original.appendChild( tr );
		tr.appendChild( br );
		br.appendChild( bl );
		bl.appendChild( tl );
		tl.appendChild( vContentDiv );
	}
	
} 