/**Author: Jerome S. Conde
 *UI Developer
 *Impact Proximity
 */
var Proximity = new Object();

Proximity = (function() {
	
	var funcs = {};

	/** All functions related to Browser
	*/
	function Browser(){}
		Browser.prototype.getAgent = function (){
			return navigator.userAgent.toLowerCase();
		};
		Browser.prototype.getName = function (){
			y = this.getAgent();
			if(y.indexOf("msie") > -1) return "MSIE";
			if(y.indexOf("firefox") > -1) return "Firefox";
			if(y.indexOf("netscape") > -1) return "Netscape";
			if(y.indexOf("opera") > -1) return "Opera";
			if(y.indexOf("safari") > -1) return "Safari";
		};
		Browser.prototype.getVersion = function (){ 
			z = this.getAgent();
			if(this.isIE()){x = z.indexOf("msie"); return z.substring(x + 5,x + 8);}
			if(this.isGecko()){
				if(z.indexOf("firefox") > -1){x = z.indexOf("firefox"); return z.substring(x + 8,x + 11);}
				if(z.indexOf("netscape") > -1){x = z.indexOf("netscape"); return z.substring(x + 9,x + 12);}
				if(z.indexOf("safari") > -1){x = z.indexOf("safari"); return z.substring(x + 7,x + 8);}
			}
			if(this.isOpera()){x = z.indexOf("opera"); return z.substring(x + 6,x + 9);}	
		};
		Browser.prototype.isMac = function (){return this.getAgent().indexOf("mac") > -1 ? true : false;};
		Browser.prototype.isIE = function (){return this.getAgent().indexOf("msie") > -1 ? true : false;};
		Browser.prototype.isIE6	= function (){return this.isIE()&&this.getVersion() == "6.0";};
		Browser.prototype.isGecko =	function (){return this.getAgent().indexOf("gecko") > -1 ? true : false;};
		Browser.prototype.isFirefox = function (){return this.getAgent().indexOf("firefox") > -1 ? true : false;};
		Browser.prototype.isNetscape = function (){return this.getAgent().indexOf("netscape") > -1 ? true : false;};
		Browser.prototype.isOpera = function (){return this.getAgent().indexOf("opera") > -1 ? true : false;};
		Browser.prototype.isSafari = function (){return this.getAgent().indexOf("safari") > -1 ? true : false;};
		Browser.prototype.isModern = function (){
			var y = this;var x = y.isIE()&&parseFloat(y.getVersion()) >= 6.0 || y.getName() == "Firefox" && parseFloat(y.getVersion()) >= 1.0;;
			x = x || y.getName() == "Netscape" && parseFloat(y.getVersion()) >= 7.0 || y.isOpera() && parseFloat(y.getVersion()) >= 8.0;
			return x;
		};
	funcs.Browser = Browser;
	
	function Util(){}
		Util.prototype.includeJS = function(jsFileSource){
			document.write("\n<script type=\"text/javascript\" src=\"" + jsFileSource + "\">");
			document.write("</script>\n");
		};
		Util.prototype.assignFirstChild = function(){
			var t = new Browser();
			if(t.isIE()){
				uls = document.getElementsByTagName("UL");
				if(uls.length>0){
					for(var i = 0;i<uls.length;i++){
						x = uls[i].getElementsByTagName("LI");
						if(x[0] && x[0].className.indexOf("FirstChild")<0){
							x[0].className += x[0].className == "" ? "FirstChild" : " FirstChild";
						}
					}
				}
			}
		};
		Util.prototype.assignLastChild = function(){
			var t = new Browser();
			if(t.isIE() || t.isOpera()){
				uls = document.getElementsByTagName("UL");
				if(uls[0]){
					for(var i=0;i<uls.length;i++){
						var lst = uls[i].lastChild;
						if(lst && lst.tagName == "LI"){
							if(lst.className.indexOf("LastChild")<0){
								lst.className += lst.className == "" ? "LastChild" : " LastChild";
							}
						}
					}
				}
			}
		};
		Util.prototype.assignFirstAndLastChild = function(){
			this.assignFirstChild();
			this.assignLastChild();
		};
		Util.prototype.sfHover = function(IdToHover){
			var t = new Browser();
			if(t.isIE()){
				for (var j = 0; j < IdToHover.length; j++)
				{
					if(this.getID(IdToHover[j])){
						var sfEls = this.getID(IdToHover[j]).getElementsByTagName("LI");
						for (var i = 0; i < sfEls.length; i++){
							sfEls[i].onmouseover=function(){
								this.className += " sfhover";
							}
							sfEls[i].onmouseout = function() {
								this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
							}
						}
					}
				}
			}
			/** Fix for IE6 bg flicker **/
			var m = document.uniqueID /*IE*/ && document.compatMode /*>=IE6*/ && !window.XMLHttpRequest /*<=IE6*/ && document.execCommand;
			if(!!m){ m("BackgroundImageCache", false, true) /* = IE6 only */ }
		};
		Util.prototype.sfNode = function(navId){ 
			var thisID = this.getID(navId); 
			if(thisID){
				var sfEls = thisID.getElementsByTagName("LI");
				var b = new Browser();
				for (var i = 0; i < sfEls.length; i++) {
					if(sfEls[i].getElementsByTagName("UL").length>0){
						sfEls[i].className += " sfNode";
						if(b.isIE()){
							sfEls[i].onmouseover = function(){
								this.getElementsByTagName("UL")[0].style.display = "block";
							}
							sfEls[i].onmouseout = function(){
								this.getElementsByTagName("UL")[0].style.display = "none";
							}
						}
					}
				}
			}
		};
		Util.prototype.getID = function(id){
			x = document; return x.getElementById(id) ? x.getElementById(id) : x.all? x.all(id) : null;
		};
		Util.prototype.getClass = function(node,classname){
			var a = [];
			var re = new RegExp('\\b' + classname + '\\b');
			var els = node.getElementsByTagName("*");
			for(var i = 0,j = els.length; i < j; i++)
			if(re.test(els[i].className))a.push(els[i]);
			return a;
		};
		Util.prototype.activeImageSwitcher = function(node,classname,postFix,ext){
			var activeLIs = this.getClass(node,classname);
			var imgTemp = null;
			if(activeLIs.length){ 
				for(var i = 0;i < activeLIs.length;i++){
					imgTemp = activeLIs[i].getElementsByTagName("IMG");
					if(imgTemp.length){
						imgTemp[0].src = imgTemp[0].src.replace(ext,postFix + ext);
					}
				}
			}
		};

	funcs.Util = Util;
	
	return funcs;
})();

var ip$ = new Proximity.Util();
