if(!friz) { var friz = {}; }

friz = function(){
	 // variable to contain the reference to the <div id="build_site"></div> used for putting things in the page
	var build_site=false;
	var path=false;

	findPaths();
    addEvent(window,"load",Init);
	
	/*
	    Initialize the friz namespace
	*/
	function Init(){
	    // if the build_site exists we are going to capture it
	    if(document.getElementById("build_site")){
		    build_site = document.getElementById("build_site");
	    } else {
	        build_site = document.createElement("div");
	        build_site.id = "build_site";
	        var frag = document.createDocumentFragment();
	        frag.appendChild(build_site);
	        document.body.appendChild(frag);
	    }
		
	    // try to set the paths
	    findPaths();
	    if(path){
	        // if the paths are set we can try to add the style sheet
	        addStyles();

			// add the ie hack if this is an ie browser
			if(window.event){
				var lnk = document.createElement("link");
				lnk.setAttribute("href",path + "css/ie.css");
				lnk.setAttribute("type","text/css");
				lnk.setAttribute("rel","stylesheet");
				document.getElementsByTagName("head")[0].appendChild(lnk);
			}
	    }
	    
	    loadNamespace();
	}
	
	/*
	    Initializes the rest of the friz namespace as needed
	*/
	function loadNamespace(){
	    var elms = document.getElementsByTagName("script");
	    var srcPath;
	    var oName;
	    for(var i = 0; i < elms.length; i++){
	        if(elms[i].getAttribute("src")){
	            srcPath = elms[i].getAttribute("src");
	            if(srcPath.indexOf("friz_")!=-1){
	                oName = srcPath.substring(srcPath.indexOf("friz_"));
	                oName = oName.replace(/(.js)/g,"");
	                oName = oName.replace("_",".");
	                if(typeof eval(oName)=='object')
	                    if(typeof eval(oName).Init=='function')
	                        eval(oName).Init();
	            }
	        }
	    }
	}

	/*
	    Attempts to find the document root url and the path to friz folder
	*/	
	function findPaths(){
		/*
			if the paths haven't been preset then attempt to find them.
			When using SEF URLS the paths need to be preset.
		*/
		if(path===false){
			var scriptElms = document.getElementsByTagName("script")
			for(var i = 0; i < scriptElms.length; i++){
				if(scriptElms[i].getAttribute("src")){
					tmpPath = scriptElms[i].getAttribute("src");
					if(tmpPath.indexOf("java/friz.js")!=-1){
						path = tmpPath.replace("java/friz.js","");
					}
				}
			}
		}
	}
	
	/*
	    Attempts to add the friz style sheet to the document
	*/
	function addStyles(){
	    var dh = document.body.parentNode.getElementsByTagName("head")[0];
	    var lnk = document.createElement("link");
	    lnk.setAttribute("href",path + "css/friz.css");
	    lnk.setAttribute("rel","stylesheet");
	    lnk.setAttribute("type","text/css");
	    dh.appendChild(lnk);
	}
	
	function addEvent(obj,evnt,func){
		if(obj.addEventListener) {
			obj.addEventListener(evnt,func,false);
		} else {
			if(obj.attachEvent) {
				var response = obj.attachEvent("on"+evnt,func);
			} else {
				obj['on' + evnt] = func;
			}
		}
	}
	
	function inheritEvent(obj,evnt,func){
	    if(obj.nodeType!=3){
	        addEvent(obj,evnt,func);
	        if(obj.childNodes){
	            for(var i = 0; i < obj.childNodes.length; i++){
	                inheritEvent(obj.childNodes[i],evnt,func);
	            }
	        }
	    }
	}
	
	function inheritProperty(src,name,includeParent){
		if(includeParent){
			obj[name] = obj;
		}
		
		if(obj.childNodes[0]){
			for(var i = 0; i < obj.childNodes.length; i++){
				inheritProperty(obj.childNodes[i],name,true);
			}
		}
	}
	
	/*
		Public Methods
	*/
	return {
		path:path,
		
		// cross browser addEventListener or attachEvent
		addEvent:function(obj,evnt,func){
		    addEvent(obj,evnt,func);
		},
		
		/*
			Displays a non compliant message when called to warn users
			that their current browser or settings will not allow them to
			view the page properly
		*/
		nonComp:function(){
			var msg = "The internet browser you are using is either out-dated, "
				+ "or not configured to be compatible with current W3C standards. "
				+ "Beaware that the pages in this site may not function properly on your "
				+ "computer.  Thanks.";
			alert(msg);
		},
		
		/*
			Returns the current window width cross browser
		*/
		windowWidth:function() {
			var myWidth = 0;
			if( typeof( window.innerWidth ) == 'number' ) {
				//Non-IE
				myWidth = window.innerWidth;
			} else if( document.documentElement && (document.documentElement.clientWidth)) {
				//IE 6+ in 'standards compliant mode'
				myWidth = document.documentElement.clientWidth;
			} else if( document.body && document.body.clientWidth) {
				//IE 4 compatible
				myWidth = document.body.clientWidth;
			}
			return myWidth;
		},
		
		/*
			Returns the current window height cross browser
		*/
		windowHeight:function() {
			var myHeight = 0;
			if( typeof( window.innerHeight ) == 'number' ) {
				//Non-IE
				myHeight = window.innerHeight;
			} else if( document.documentElement && (document.documentElement.clientHeight)) {
				//IE 6+ in 'standards compliant mode'
				myHeight = document.documentElement.clientHeight;
			} else if( document.body && document.body.clientHeight) {
				//IE 4 compatible
				myHeight = document.body.clientHeight;
			}
			return myHeight;
		},
		
		inheritEvent:function(obj,evnt,func){
		    inheritEvent(obj,evnt,func);
		},
		
		inheritProperty:function(src,name,includeParent){
			inheritProperty(src,name,includeParent);
		},
		
		stringToXML:function(str){
			var xmlDoc;
			try {
				xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
				xmlDoc.async="false";
				xmlDoc.loadXML(str);
			} catch(err) {
				try {
					parser = new DOMParser();
					xmlDoc = parser.parseFromString(str,"text/xml");
				} catch(err) {
					alert(err);
				}
			}
			
			return xmlDoc;				
		},

		buildSite:build_site,
		
		findParentByTag:function(obj,tag){
			var result = obj;
			if((typeof tag)=="string"){
				while(result.tagName.toLowerCase() != tag.toLowerCase()){
					result = result.parentNode;
				}
			} else {
				while((!tag.test(result))){
					result = result.parentNode;
				}
			}
		
			return result;
		},
		
		/*
			takes the paramaters of one object and copies them
			to the other
		*/
		extend:function(dest,src){
			for(var p in src){
				try{
					dest[p] = src[p];
				} catch(err) {
					alert(err.description);
				}
			}
		},
		
		cancelDefault:function(e){
			if(!e) e=window.event;
			e.preventDefault ? e.preventDefault() : e.returnValue = false;
		},
		
		duplicate:function(id){
			var obj = document.getElementById(id);
			var newobj = obj.cloneNode(true);
			if(obj.nextSibling){
				obj.parentNode.insertBefore(newobj,obj.nextSibling);
			} else {
				obj.parentNode.appendChild(newobj);
			}
		},
		
		loadscript:function(path){
			var oscript = document.createElement("script");
			oscript.setAttribute("type","text/javascript");
			oscript.setAttribute("src",path);
			document.getElementsByTagName("head")[0].appendChild(oscript);
		}
	};
}();