//Dan Webb's Namespacer
function namespace(i, o) {var w=this,p=i.split("."),s=(!w[p[0]])?w[p[0]]={}:w[p[0]],l=p.length; for (var i=1;i<l-1; i++) s=(!s[p[i]])?s[p[i]]={}:s[p[i]]; return (o)?s[p[l-1]]=o:((!s[p[l-1]])?s[p[l-1]]={}:s[p[l-1]]);}

//namespaced constants for site name, page name, language and utils
//usage ha.page.SITENAME
//usage ha.page.utils.spawn()
//usage ha.page.utils.includeScript()
$(document).ready(
	function() {
		namespace("ha.page", {
			SITENAME : $("body").attr("class"),
			PAGENAME : $("#container").attr("class"),
			LANGUAGE : $("#main").attr("class")
		});
		//add spawn 
		namespace("ha.page.utils", {
		//Accessible new window for advertiser section
		spawn : function(URL,winName,attributes) {
			/*attributes example - note you must pass in width & height first (IE 4+ Mac bug) width=620,height=460,directories=no,location=no,menubar=no,scrollbars=yes,toolbar=no,status=no,resizable=no,top=0,left=0*/
			var newWindow=window.open(URL,winName,attributes);
			newWindow.focus();
			},
		//add dynamic JS include 
		includeScript : function(includeName) {
				//get defensive
				if (!document.getElementsByTagName) return;
				//get a reference to the title tag
				var titleTag = document.getElementsByTagName("title");
				//create a script element
				jsTag=document.createElement("script"); 
				//for XHTML completeness (note: "language" is deprecated)
				jsTag.setAttribute("type", "text/javascript");
				//populate src with the include param
				jsTag.setAttribute("src",includeName);
				//append after title tag (note: it's the first index in the array)
				titleTag[0].parentNode.appendChild(jsTag);
			}
		});	
	}
);

function openWindow(page,width,height,scrolling){
	var winWidth = width;
	var winHeight = height;
	var posLeft = (screen.availWidth - winWidth) / 2;
	var posTop = (screen.availHeight - winHeight) / 2;
	var winInfo = 'width=' + winWidth + ',height=' + winHeight + ',left=' + posLeft + ',top=' + posTop + ',location=no,menubar=no,toolbar=no,status=no,scrollbars=' + scrolling + ',resizable=yes';
	var poplaunch = window.open(page, 'poplaunch', winInfo);
    poplaunch.focus();
}