/**
 * @author Alexander Farkas
 * @ version 1.05
 */
(function($){

/**
 * Copyright (c) 2007 Jörn Zaefferer
 */


(function(){
	$.support.focusInOut = !!($.browser.msie);
	if (!$.support.focusInOut) {
		$.each({
			focus: 'focusin',
			blur: 'focusout'
		}, function(original, fix){
			$.event.special[fix] = {
				setup: function(){
					if (!this.addEventListener) {
						return false;
					}
					this.addEventListener(original, $.event.special[fix].handler, true);
				},
				teardown: function(){
					if (!this.removeEventListener) {
						return false;
					}
					this.removeEventListener(original, $.event.special[fix].handler, true);
				},
				handler: function(e){
					arguments[0] = $.event.fix(e);
					arguments[0].type = fix;
					return $.event.handle.apply(this, arguments);
				}
			};
		});
	}
	//IE has some troubble with focusout with select and keyboard navigation
	var activeFocus = null, block;
	
	$(document)
		.bind('focusin', function(e){
			var target = e.realTarget || e.target;
			if (activeFocus && activeFocus !== target) {
				e.type = 'focusout';
				$(activeFocus).trigger(e);
				e.type = 'focusin';
				e.target = target;
			}
			activeFocus = target;
		})
		.bind('focusout', function(e){
			activeFocus = null;
		});
		
})();
})(jQuery);