/*
	Copyright (c) JB Interactive Pty. Ltd.
	All Rights Reserved
	http://www.jbinteractive.com.au/
*/


(function ($) {

var oldBorder     = null,
	oldLeftMargin = null,
	oldTopMargin  = null,
	// Represents the first element to trigger the mouseover event
	actualElement = null,
	parseValue    = function (value) {
		return (value == 'auto') ? 'auto' : parseInt(value);
	};

$.fn.ie6debug = function () {
	
	// Create the element to display information
	var display = $('<div id="debug-display">')
		.css ({
			position: 'absolute',
			width: '200px',
			height: '10em',
			left: '10px',
			top: '10px',
			backgroundColor: 'white',
			border: '2px solid gray',
			overflow: 'scroll'
		})
		.prependTo(this);
	
	// Now update information on mouseovers
	this.find('*')
		.hover(
			function () {
				// If this is the top element, store it for later
				if (!actualElement)
				{
					actualElement = this;

					// Put a border around the outside and mark it
					oldBorder = $(this).css ('border');
					oldLeftMargin = $(this).css ('marginLeft');
					oldTopMargin = $(this).css ('marginTop');

					var newLeftMargin = parseValue (oldLeftMargin) != 'auto' ? parseValue (oldLeftMargin) - 2 + 'px' : 'auto';
					var newTopMargin = parseValue (oldTopMargin) != 'auto' ? parseValue (oldTopMargin) - 2 + 'px' : 'auto';

					$(this)
						.css({
							border: '2px solid blue',
							marginLeft: newLeftMargin,
							marginTop: newTopMargin
						});
				}

				var name = this.nodeName;
				var id = $(this).attr ('id') ? '#' + $(this).attr ('id') : '';
				var cl = $(this).attr ('class') ? '.' + $(this).attr ('class') : '';

				display.html (display.html () + name + id + cl + "<br />");
			},
			
			function () {
				// Clear the data box
				display.html('');

				// Restore the old border
				$(actualElement)
					.css({
						border: 'none',
						marginLeft: oldLeftMargin,
						marginTop: oldTopMargin
					});

				// Clear the hilighted element
				actualElement = null;
			}
		);
	
	return this;
};
	
	
})(jQuery);
