/**
 * A GENERIC script to write the <script>, <link> tags for including
 * all the dependency JavaScript and CSS files for using Menu.
 *
 * Warning: Lots of publications use this script.
 *          For a particular change, clone and change.
 *
 *          Order of <script>s matters.
 */

// Local function to avoid name-space pollution.
(function(){

// Get the property located at the chain "propChain" inside "srcObj".
function getFromPropertyChain(srcObj, propChain) {
	if (!srcObj) {
		return(null);
	}
	
	var whereToLook = srcObj;
	for(var i in propChain) {
		if (typeof whereToLook[propChain[i]] == "undefined" || whereToLook[propChain[i]] == null) {
			return(null);
		}
		whereToLook = whereToLook[propChain[i]];
	}
	
	return(whereToLook);
}

// While including JS, avoid twice inclusion.
function requireJSOnce(src, propChain) {
	if (!getFromPropertyChain(window, propChain.split("."))) {
		document.write("<script src='" + src + "' type='text/JavaScript'></script>");
	}
}

// No headache of twice inclusion of CSS.
function requireCSS(href) {
	document.write("<link rel='stylesheet' type='text/css' href='" + href + "'>");
}

requireCSS("/css/jdMenu.theme.core.css");
requireCSS("/css/jdMenu.theme.gray.css");
requireCSS("/css/jdMenu.footer.css");

requireJSOnce("/js/jquery-1.4.2.js", "jQuery");
requireJSOnce("/js/jquery.positionBy.js", "jQuery.fn.positionBy");
requireJSOnce("/js/jquery.bgiframe.js", "jQuery.fn.bgIframe");
requireJSOnce("/js/jquery.kutils.js", "jQuery.getViewPortDimension");
requireJSOnce("/js/jquery.kepf.js", "jQuery.punchInTop");
requireJSOnce("/js/jquery.jdMenu.js", "jQuery.fn.jdMenu");

requireJSOnce("/js/utils/IBFDUtils.js", "IBFDUtils");
requireJSOnce("/js/utils/IBFDStrUtils.js", "IBFDStrUtils");
requireJSOnce("/js/utils/IBFDUrlUtils.js", "IBFDUrlUtils");
requireJSOnce("/js/utils/IBFDObjUtils.js", "IBFDObjUtils");
requireJSOnce("/js/utils/IBFDDOMUtils.js", "IBFDDOMUtils");
requireJSOnce("/js/utils/TextSelectionUtils.js", "TextSelectionUtils");
requireJSOnce("/js/utils/PrintUtils.js", "PrintUtils");

requireJSOnce("/js/outline/DocTypeAnalyzer.js", "DocTypeAnalyzer");

requireJSOnce("/js/ui/UIComponent.js", "UIComponent");
requireJSOnce("/js/ui/UIComposite.js", "UIComposite");

requireJSOnce("/js/ui/menu/MenuItem.js", "MenuItem");
requireJSOnce("/js/ui/menu/MenuItemToHtml.js", "MenuItemToHtml");
requireJSOnce("/js/ui/menu/MenuManager.js", "MenuManager");

requireJSOnce("/js/ui/cite/CiteData.js", "CiteData");
requireJSOnce("/js/ui/cite/CiteToHtml.js", "CiteToHtml");
requireJSOnce("/js/ui/cite/view/CiteDivStrTmpl.js", "CiteDivStrTmpl");

requireJSOnce("/js/ui/bilingual/BilingualData.js", "BilingualData");
requireJSOnce("/js/ui/bilingual/BilingualDataToHtml.js", "BilingualDataToHtml");
requireJSOnce("/js/ui/bilingual/BilingualManager.js", "BilingualManager");
requireJSOnce("/js/ui/bilingual/comparator/BilingualComparator.js", "BilingualComparator");


})();
