﻿// Sorin Ionescu
// http://www.studioindustryllc.com
// Inspired by the Dragon Labs' Octupus Engine
/*
			$(document).ready(
				function()
				{
					$('p').border();
					$('div#test').border('fancy-');
					$('input').border('fancy-input-');
				}
			);

*/

$.fn.border = function(prefix)
{
	var classNames = [
		'north',
		'east',
		'south',
		'west', 
		'northeast', 
		'southeast', 
		'southwest', 
		'northwest'];
	
	this.each(
		function()
		{
			var borderElement = null;
			var currentElement = this.cloneNode(true);
			var nodeList = this.childNodes;
			var nodeArray = new Array();
							
			for (var index = classNames.length - 1, className; className = classNames[index]; index--) 
			{				
				if (prefix != null)
				{ 
					className = prefix + className;
				}
				
				borderElement = document.createElement('div');
				$(borderElement).addClass(className).css({display: 'block'});
				
				borderElement.appendChild(currentElement);
				currentElement = borderElement;
			}
						
			this.parentNode.replaceChild(currentElement, this);
			
			/* IE Hack:
			 *     IE collapses the bottom and top margins
			 *     rendering the next sibbling partially
			 *     inside of the previous sibbling element.
			 */
			
			/*@cc_on
			$(currentElement).css({zoom: '1'});
			@*/
		}
	);
		
	return this;
};