
function Utils() {
  var that = this;
  function get(eltID) {
    return document.getElementById(eltID);
  }

	this.centerElement = function(objID) {
		var windowHeight = $(window).height();
		var windowWidth = $(window).width();
	
		positionit(objID, ((windowWidth / 2)-(get(objID).offsetWidth/2)), ((windowHeight/2)-(get(objID).offsetHeight/2)) )	
	};

  
	function positionit(objID, addLeft, addTop){
		if (addLeft == null) addLeft = 0;
		if (addTop == null) addTop = 0;
		
		var crossobj=get(objID);
		var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
		var dsocleft=document.all? iebody.scrollLeft : pageXOffset
		var dsoctop=document.all? iebody.scrollTop : pageYOffset

		if (document.all||document.getElementById){
			if (crossobj) {
				crossobj.style.left=parseInt(dsocleft)+addLeft+"px"
				crossobj.style.top=dsoctop+addTop+"px"
			}
		} 
	}

	this.getBrowserHeight = function() {
		if (!document.all) {
			return window.innerHeight;	
	    } else {
			return document.body.clientHeight;
	    } 
	};

	this.getBrowserWidth = function() {
		if (!document.all) {
		    return window.innerWidth;
	    } else {
		    return document.body.clientWidth;
	    } 
	};
  
  //fixme: these find pos functions should be PRIVATE in the UTILS CLASS
	this.findPosY = function(obj)
	{
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
	};

	this.findPosX = function(obj)
	{
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
	};

  this.resize = function() {
    if (g_currently_loaded) {
      that.showModal(g_currently_loaded, null, true);
    }
  };
  
  var g_currently_loaded = null;
  this.showModal = function(eltID, callback, b_resizing) {
    //exception for registration page if they click terms nd condition, dont want to close out the window
    if (g_currently_loaded != "register_content") {
      if (g_currently_loaded != null) {
        that.hideModal(g_currently_loaded);
      }
      g_currently_loaded = eltID;
    }
    $("#" + eltID).css("position", "absolute");
    $("#" + eltID).css("left", "-1000");
    $("#" + eltID).show();
    $("#" + eltID).css("z-index", "100");
    $("#" + eltID + " .jqmClose").click( function() {
      that.hideModal(eltID);
    });
    $(".my_wall").show();
    $(".my_wall").css("height", ($(window).height()-120));

    var x = this.findPosX(document.getElementById("flashContainer"));
    var y = this.findPosY(document.getElementById("flashContainer"));
    $(".my_wall").css("top", y);
    $(".my_wall").css("left", x);
    
    utils.centerElement(eltID);
    
    if (eval(callback)) {
      setTimeout(eval(callback), 300);
    }    
  };

  this.hideModal = function(eltID) {
    g_currently_loaded = null;
    flashCallBack('flModalChange',false);
    $("#" + eltID).hide();
    $(".my_wall").hide();
  };





  
  

	var included_files = new Array();
  //include once isnt really including once, its raelly jus INCLUDE.  ive disabled the include once to help with caching problmes and i dont think its needed to help performance
	this.include_once = function(script_filename, callback) {
		    include_dom(script_filename, callback);

/*
		if (!in_array(script_filename, included_files)) {
	    	included_files[included_files.length] = script_filename;
		    include_dom(script_filename, callback);
		} else {
			if (callback) {
				if ( (script_filename.indexOf(".asp") != -1) || (script_filename == "superPinManager.asp") ) {
					callback("dupe");
				} else {
					callback();
				}
			}
		}
*/
	};

	function include_dom(script_filename, callback) {
	  	t=script_filename.substring(script_filename.lastIndexOf('.')+1);
	  if ( (t=='js') || (t=='php') ) {
			include_js(script_filename, callback);
		} else if (t=='css') {
			include_css(script_filename, callback);
		} else {
			httpRequest.requestQueueFile(script_filename, callback);			
		}

		return false;
	}

	var css;
	function include_css(css_file, callback) {
	    var html_doc = document.getElementsByTagName('head')[0];
	    css = document.createElement('link');
	    css.setAttribute('rel', 'stylesheet');
	    css.setAttribute('type', 'text/css');
	    css.setAttribute('href', css_file);
	    html_doc.appendChild(css);
	
	    // alert state change
	    css.onreadystatechange = function () {
	        if (css.readyState == 'loaded') {
	            if (callback) {
					callback();
				}
	        }
	    }

	    css.onload = function () {
	            if (callback) {
					callback();
				}
	    }
		
	    return false;
	}
	
	function initFF() {
		alert("hi");
	}
	
	
	var js;
	var jsLock = false;
	var JSQueue = new Array();

	function include_js(file, callback, override) { 
		if ( (jsLock == false) || (override) ) {
			jsLock = true;
		    var html_doc = document.getElementsByTagName('head')[0];
		    js = document.createElement('script');
		    js.setAttribute('type', 'text/javascript');
		    js.setAttribute('src', file);
		    html_doc.appendChild(js);
		
		    js.onreadystatechange = function () {
		        if (js.readyState == 'loaded') {
		            if (eval(callback)) {
						eval(callback)();
						checkJSQueue();
					}
		        }
		    }
		
		    js.onload = function () {
	      if (eval(callback)) {
					eval(callback)();
					checkJSQueue();
				}
		    }
		
		    return false;
		} else {
			var newreq = new Object();
			newreq["url"] = file;
			newreq["callback"] = callback;
			
			JSQueue.push(newreq);
		}
	}

	
	function checkJSQueue() {
		if (JSQueue.length) {
			var req = new Object();
			req = JSQueue.shift();
			include_js(req["url"], req["callback"], true);			
		} else {
			jsLock = false;
		}
	}
	

	function in_array(needle, haystack) {
	  for (var i = 0; i < haystack.length; i++) {
	    if (haystack[i] == needle) {
	      return true;
	    }
	  }
	  return false;
	}
  
  
  

}

var utils = new Utils();
