/**
 * @author trixta
 */
(function($){

$.each({
	focus: 'focusin',
	blur: 'focusout'	
}, function( original, fix ){
	$.event.special[fix] = {
		setup:function() {
			if ( $.browser.msie ) return false;
			this.addEventListener( original, $.event.special[fix].handler, true );
		},
		teardown:function() {
			if ( $.browser.msie ) 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);
		}
	};
});

function addTabindex(jElm){  
	if(!jElm.is('a, area, input, button, select, textarea, [tabindex=0]')){  
		jElm.css({outline: 'none'}).attr({tabindex: '-1'});  
	}  
	return jElm;  
}  
var focusTimer;  
$.fn.setFocus = function(time){  
	if(!this[0]){return this;}  
	var jElm = $(this[0]);  
	clearTimeout(focusTimer);  
	focusTimer = setTimeout(function(){  
		try{  
			addTabindex(jElm)[0].focus();  
		} catch(e){}  
	}, time || 0);  
	return this;  
};


   
   
var uId = new Date().getTime();  
$.fn.getID = function(){  
	var id = '';  
	if(this[0]){  
		var elem = $(this[0]);  
		id = elem.attr('id');  
		if(!id){  
			id = 'ID-' + (uId++);  
			elem.attr({'id': id});  
		}  
	}  
	return id;  
};  

$.each(
	{  
		labelWith: 'aria-labelledby',  
		describeWith: 'aria-describedby',  
		ownsThis: 'aria-owns',  
		controlsThis: 'aria-controls',
		activateThis: 'aria-activedescendant'
	}, 
	function(name, prop){  
		$.fn[name] = function(elem){  
			return this.attr(prop, $(elem).getID());  
		};  
});  
	
})(jQuery);
