/** Original code by Beyond Standards
  * <http://beyondstandards.com/archives/input-placeholders/>
  * Modified by Chauncey McAskill <http://kemryu.com>
  *	- Proper detection of 'placeholder' support.
  *	  <http://diveintohtml5.org/detect.html#input-placeholder>
  *	- Added loop that empties input values 
  *	  to 'onsubmit' events.
  *	- Adding cleaning of variables at the end.
  *	  Might not be necessary. Need to investigate.
  */
function activatePlaceholders() {
	var i = document.createElement('input');
	if ( 'placeholder' in i ) return false;

	var inputs = document.getElementsByTagName('input');
	for (i = 0; i < inputs.length; i++) {
		if (inputs[i].getAttribute('type') == 'text') {
			if (inputs[i].getAttribute('placeholder') && inputs[i].getAttribute('placeholder').length > 0) {
				inputs[i].value = inputs[i].getAttribute('placeholder');
				inputs[i].className += ' placeholder';
				inputs[i].onclick = function() {
					if ( this.value == this.getAttribute('placeholder') ) {
						this.value = '';
						this.className = this.className.replace('placeholder','');
					}
					return false;
				}
				inputs[i].onblur = function() {
					if (this.value.length < 1) {
						this.value = this.getAttribute('placeholder');
						this.className += ' placeholder';
					}
				}
			}
		}
	}
	var forms = document.getElementsByTagName('form');
	for (i = 0; i < forms.length; i++) {
		forms[i].onsubmit = function() {
			for (i = 0; i < inputs.length; i++) {
				if (inputs[i].getAttribute('type') == 'text') {
					var placeholder = inputs[i].getAttribute('placeholder');
					if (placeholder && placeholder.length > 0) {
						if (placeholder == inputs[i].value) inputs[i].value = '';
					}
				}
			}
			return false;
		}
	}
	delete forms;
	delete inputs;
	delete i;
	
}
activatePlaceholders();


(function ($) {

/* ----
       superLink jQuery plugin
       (c) James Padolsey
       ----
       Contributors:
            Brian Fisher
*/

	$.fn.superLink = function (link) {
		link = link || 'a:first';
		return this.each(function () {

			var $container = $(this)
			    ,$targetLink = $(link, $container).clone(true);

/* Take all current mouseout handlers of $container and
               transfer them to the mouseout handler of $targetLink */
			var mouseenters = $(this).data('events') && $(this).data('events').mouseenter;
			if (mouseenters) {
				$.each(mouseenters, function (i, fn) {
					$targetLink.mouseout(function (e) {
						$container.trigger(e.type);
					});
				});
			}

/* Take all current mouseover handlers of $container and
               transfer them to the mouseover handler of $targetLink */
			var mouseleaves = $(this).data('events') && $(this).data('events').mouseleave;
			if (mouseleaves) {
				$.each(mouseleaves, function (i, fn) {
					$targetLink.mouseover(function (e) {
						$container.trigger(e.type);
					});
				});
			}

			$targetLink.click(function () {
				$targetLink.blur();
			}).css({
				position: 'absolute',
				top: $container.offset().top,
				left: $container.offset().left,
				/* IE requires background to be set */
				backgroundColor: '#FFF',
				opacity: 0,
				width: $container.outerWidth(),
				height: $container.outerHeight(),
				padding: 0
			}).appendTo('body');

		});
	};

})(jQuery);
