(function(){
/**
 *@copyriht Copyright (c) 2007 Proximity
 *@author Jerome S. Conde
 *@version 1.0 11:22 AM Monday, January 28, 2008
 */
var Proximity = window.Proximity = function() {};
var userAgent = navigator.userAgent.toLowerCase();
Proximity.prototype = {
	agent : userAgent,
	browser : {
		version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
		safari: /webkit/.test(userAgent),
		opera: /opera/.test(userAgent),
		netscape: /netscape/.test(userAgent),
		msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
		mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent)
	},
	
	getTags : function(oNode,sTag,bImmediate) {
		if(typeof oNode == "object") {
			var tags = oNode.getElementsByTagName(sTag) || [];
			var x = [];
			if(!bImmediate) return tags;
			else{
				for(var i=0,j=tags.length;i<j;i++)
					tags[i].parentNode == oNode ? x.push(tags[i]) : null;
				return x;
			}
		}  
	},
	
	getID : function(sID) {
		x = document; 
		return x.getElementById(sID) ? x.getElementById(sID) : x.all? x.all(sID) : null;
	},
	
	getClass : function(oNode,sClassName) {
		var a = [];
		var re = new RegExp('\\b' + sClassName + '\\b');
		var els = this.getTags(oNode,"*");
		for(var i = 0,j = els.length; i < j; i++)
		if(re.test(els[i].className))a.push(els[i]);
		return a;
	},
	
	addClass : function(oTarget,sClassName) {
		if(typeof oTarget == "object" && !this.getClass(oTarget,sClassName)[0]) {
			oTarget.className += (" " + sClassName);
			return oTarget;
		} else return false;
	},
	
	removeClass : function(oTarget,sClassName) {
		if(typeof oTarget == "object") {
			oTarget.className = oTarget.className.replace(sClassName,"");
			return oTarget;
		} else return false;
	},
	
	toggleClass : function(oTarget,sClassName) {
		if(!this.removeClass(oTarget,sClassName)) this.addClass(oTarget,sClassName);
	},
	
	addEvent : function(obj, type, fn) {
		if ( obj.attachEvent ) {
			obj['e'+type+fn] = fn;
			obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
			obj.attachEvent( 'on'+type, obj[type+fn] );
		} else obj.addEventListener( type, fn, false );
		return obj;
	},
	
	removeEvent : function(obj, type, fn) {
		if ( obj.detachEvent ) {
			obj.detachEvent( 'on'+type, obj[type+fn] );
			obj[type+fn] = null;
		} else obj.removeEventListener( type, fn, false );
		return obj;
	},
	
	getEventTarget: function(x) {
		x = x || window.event;
		return x.target || x.srcElement;
	},
	
	each : function(obj,fn){
		if(typeof obj != "object" && typeof fn != "function") return;
		var thisFn = arguments[2];
		if(obj.length){
			for(var i=0,j=obj.length;i<j;i++){
				fn.call(thisFn,i,obj[i]);
			}
		}
		else{
			for(var prop in obj){
				fn.call(thisFn,prop,obj[prop]);
			}
		}
		return obj;
	},
	
	assignFirstChild : function(sParent,sChild) {
		if(this.browser.msie){
			this.each(this.getTags(document,sParent),function(i,el){
				prox.addClass(prox.getTags(el,sChild)[0],"FirstChild");
			});
		}
	},
	
	assignLastChild : function(sParent,sChild) {
		if(this.browser.msie || this.browser.opera){
			this.each(this.getTags(document,sParent),function(i,el){
				var LIs = prox.getTags(el,sChild,true);
				prox.addClass(LIs[LIs.length-1],"LastChild");
			});
		}
	},
	
	popUp : function(sURL,oSpecs,sName) {
		var options = "";
		for(var y in oSpecs)	options += (y+"="+ oSpecs[y] +",");
		var newWin;
		newWin = window.open(sURL,sName ? sName : "",'"'+options+'"');
		if(window.focus) newWin.focus();
		return false;
	},
	
	externalLinks : function() {
		this.each(this.getTags(document,"A"),function(i,el){
			if(/external/.test(el.rel)) el.target = "_blank"; 
		});
	},
	
	handlers : [],
	registerHandlers : function() {
		this.handlers = arguments;
	},
	executeHandlers : function() {
		var y = this.handlers;
		this.each(y,function(i,el){el();});
	}
}
/*used within the scope of Proximity function*/
var prox = new Proximity; 
/*used outside Proximity*/
window.ip$ = new Proximity;
})();
