﻿// Sorin Ionescu
// http://www.studioindustryllc.com
// Inspired by the Dragon Labs' Octupus Engine
// Edited to suit fredericback.com project requirements

$.fn.border = function(prefix)
{
	var classNames = [
		'north',
		'east',
		'south',
		'west',
		'northeast',
		'southeast',
		'southwest',
		'northwest'];

	this.each(
		function()
		{
			var borderElement = null;
			var currentElement = this.parentNode.innerHTML;
			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).addClass('clearfix').css({display: 'block'});

				//borderElement.appendChild(currentElement);
				borderElement = '<div class="'+className+' clearfix" style="display:block;">'+currentElement+'</div>';
				currentElement = borderElement;
			}

			//this.parentNode.replaceChild(currentElement, this);
			this.parentNode.innerHTML = currentElement;


			/* 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;
};