
var layout = {
	defaultHeader:	"Bindows",
	inApi:			false,

	root:			"./",

	writeHeader:	function (sHeader,sSubHeader) {
		document.write(
		(sSubHeader)?
			'<div class="mainHeading"><h1>' + (sHeader || layout.defaultHeader)+'</h1><h1 id="sub-header">' + sSubHeader +'</h1></div>'
			:
			'<div class="mainHeading"><h1>' + (sHeader || layout.defaultHeader)+'</h1></div>'
		);
	},

	writeNavigationBar:	function () {
		document.write('<div class="navigation-bar"><ul>' +
			'<li><a href="' + layout.root + '" class="current">Bindows&trade;</a>' +
				'<ul>' +
					'<li><a href="' + layout.root + 'features/">Features</a></li>' +
					'<li><a href="' + layout.root + 'benefits/">Benefits</a></li>' +
				'</ul></li>' +
			'<li>Developer Resources<ul>' +
				/*'<li><a href="' + layout.root + 'documentation/">Documentation</a></li>' +*/
				'<li><a href="' + layout.root + 'documentation/samples/">Samples</a></li>' +
				'<li><a href="' + layout.root + 'documentation/tutorials/">Tutorials</a></li>' +
				'<li><a href="' + layout.root + 'documentation/download/">Downloads</a></li>' +
				'<li><a href="' + layout.root + 'documentation/api/"><abbr title="Application Programming Interface">API<abbr></a>' +
					(layout.inApi ?
					'<ul>' +
						'<li><a href="' + layout.root + 'documentation/api/classtree.html">Class Tree</a></li>' +
						'<li><a href="' + layout.root + 'documentation/api/allclasses.html">All Classes</a></li>' +
					'</ul>'
					 : '') +
				'</li>' +
				'<li><a href="' + layout.root + 'faq/"><abbr title="Frequently Asked Questions">FAQ</abbr></a></li>' +
				'<li><a href="' + layout.root + 'webboard/" onclick="return layout.launchForum()">Forum</a></li>' +
			'</ul></li>' +
			'<li>Software<ul>' +
				'<li><a href="' + layout.root + 'download/">Evaluate</a></li>' +
				'<li><a href="' + layout.root + 'download/buy.html">Buy</a></li>' +
			'</ul></li>' +
			'<li>Corporate<ul>' +
				'<li><a href="' + layout.root + 'about/">About</a></li>' +
				'<li><a href="' + layout.root + 'jobs/">Jobs</a></li>' +
				'<li><a href="' + layout.root + 'contact/">Contact</a></li>' +
			'</ul></li>' +
			'<li><a href="' + layout.root + 'news/">News</a></li>' +
			'</ul></div>'+
			(!layout.inApi ? '<div class="navigation-bar" id="news-bar">' +
			'	<ul><li><a href="' + layout.root + 'news/">Latest News:</a></li>' +
			'		<li><a href="' + layout.root + 'news/#BindowsCompiler" class="newsheader">Bindows Compiler (beta) is available</a></li>' +
			'		<hr>' +
			'		<li><a href="' + layout.root + 'news/#Bindows1.51" class="newsheader">Bindows 1.51 Released</a></li>' +
			'		<hr>' +
			'		<li><a href="' + layout.root + 'news/#Hyperion" class="newsheader">Hyperion Using Bindows to Enhance User Interactivity</a></li>' +
			'		<hr>' +
			'		<li><a href="' + layout.root + 'news/#Northrop" class="newsheader">Northrop Grumman and MB Technologies</a></li>' +
			'	</ul>' +
			'</div>':'')
			);
	},

	writeFooter:	function () {
		document.write('<div class="footer">' +
            '<a href="' + layout.root + 'legal/index.html#RefundPolicy">Refund Policy</a>&nbsp;' +
            '<a href="' + layout.root + 'legal/index.html#PrivacyPolicy">Privacy Statement</a>&nbsp' +
            '<a href="' + layout.root + 'legal/index.html#TransactionPolicy">Transaction Security</a>&nbsp' +
		    '<p>Last updated: ' +
			layout.formatDate( new Date(document.lastModified) ) +
			"</p><p class=\"copyright\">&copy;2003-2005 MB Technologies</p></div>");
	},

	formatDate: function (d) {
		function f(n) {
			return n < 10 ? "0" + n : n;
		}
		return d.getFullYear() + "-" + f(d.getMonth() + 1) + "-" + f(d.getDate());
	},

	supportsBindows: function ()
	{
		if ( typeof BiLauncher == "function" )
		{
			var l = new BiLauncher;
			return l.getSupported();
		}

		var ua = navigator.userAgent;
		var opera = /opera/i.test(ua);
		if ( opera )
			return false;
		var ie = /msie/i.test( ua );
		var moz = navigator.product == "Gecko";
		var p = navigator.platform.toLowerCase();
		var v;

		if ( ie )
		{
			/MSIE\s+([^\);]+)(\)|;)/.test( ua );
			v = RegExp.$1;
			if ( p != "win32" && p != "win64" ||	// Is win64 really supported?
				 v < "5.5" )
			{
				return false;
			}
			return true;
		}
		else if ( moz )
		{
			/rv\:([^\);]+)(\)|;)/.test( ua );
			v = RegExp.$1;
			if ( v < "1.4" )
				return false;
			return true;
		}

		return false;
	},

	// at the moment we don't support the web service for Mozilla
	supportsWebService: function ()
	{
		return navigator.product != "Gecko";
	},

	writeSupportedStyles: function () {
		if (layout.supportsBindows()) {
			document.write("<style type=\"text/css\">" +
				".supported { display: block !important; }" +
				"span.supported { display: inline !important; }" +
				(this.supportsWebService() ? "" :
					".partial-support { display: block!important; }" +
					"span.partial-support { display: inline !important; }"
				) +
				".not-supported { display: none !important; }" +
				"</style>");
		}
	},

	biExec:		function (sAdfPath) {
		if (layout.supportsBindows()) {
			biExec(layout.root + "bindows/html/", layout.root + sAdfPath);
			return false;
		}
		return true;
	},

	launchForum: function () {
		if (layout.supportsBindows()) {
			biExec(layout.root + "bindows/html/", layout.root + "webboard/bindows/Webboard.xml");
			return false;
		}
		return true;
	},

	init:	function (sRootPath) {
		layout.root = sRootPath || "./";

		if (layout.supportsBindows())
			document.write("<script type=\"text/javascript\" src=\"" + layout.root + "bindows/html/js/bilauncher.js\"></script>");
		else {
			biExec = function () {
				alert("Bindows requires Internet Explorer 5.5+ or Mozilla 1.4+");
			};
		}
	},

	buildNewsBox:	function () {
		if (document.createElement) {
			// find nav bar
			var divs = document.getElementsByTagName("div");
			var navBar, i, a;
			var l = divs.length;
			for (i = 0; i < l; i++) {
				if (divs[i].className == "navigation-bar") {
					navBar = divs[i];
					break;
				}
			}
			if (!navBar) {
				return;
			}
			var div = document.createElement("div");
			div.className = "navigation-bar";
			var s = "<ul><li><a href=\"#news\">News</a><ul>";

			var h2 = document.getElementById("news");
			if (!h2) {
				return;
			}

			i = 1;
			for (var next = h2; next; next = next.nextSibling) {
				if (next.tagName == "H3" && next.className == "news-item") {
					a = document.createElement("a");
					a.id = a.name = "news-" + i;
					s += "<li><a href=\"#news-" + i + "\">" + next.innerHTML + "</a></li>";
					next.insertBefore(a, next.firstChild);
					i++;
				}
			}
			s +="</ul></li></ul>";
			div.innerHTML = s;
			//div.style.top = navBar.offsetTop + navBar.offsetHeight + 20 + "px";
			div.style.top = "34em";
			navBar.parentNode.insertBefore(div, navBar.nextSibling);
		}
	}
};

layout.writeSupportedStyles();
