if (typeof(WizzgoCore) == "undefined") WizzgoCore = {};

//onDOMReady Event Extension
//http://clientside.cnet.com/code-snippets/event-scripting/a-dom-ready-extension-for-prototype/
Object.extend(Event, {
	_domReady : function() {
		if (arguments.callee.done) return;
		arguments.callee.done = true;

		if (this._timer)  clearInterval(this._timer);
		WizzgoCore.isDomReady = true;
		if(this._readyCallbacks) this._readyCallbacks.each(function(f) { f() });
		this._readyCallbacks = null;
	},
	onDOMReady : function(f) {
		if(WizzgoCore.isDomReady) {
			f();
		}
		else {
			if (!this._readyCallbacks) {
				var domReady = this._domReady.bind(this);

				if (document.addEventListener)
				document.addEventListener("DOMContentLoaded", domReady, false);

				/*@cc_on @*/
				/*@if (@_win32)
				document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
				document.getElementById("__ie_onload").onreadystatechange = function() {
					if (this.readyState == "complete") domReady(); 
				};
				/*@end @*/

				if (/WebKit/i.test(navigator.userAgent)) { 
					this._timer = setInterval(function() {
						if (/loaded|complete/.test(document.readyState)) domReady(); 
						}, 10);
					}

					Event.observe(window, 'load', domReady);
					Event._readyCallbacks =  [];
				}
				Event._readyCallbacks.push(f);
			}
		}
	}
);

GlobalInit = function() {
	var downloadLinksTable = $$('#mb-download a');
	if (downloadLinksTable != null && downloadLinksTable[0] != null) {
		var downloadLink = downloadLinksTable[0];
		if(navigator.appVersion.indexOf("Mac")!=-1) {
			downloadLink.setAttribute('href', '/download/macosx');
		}
		else{
			downloadLink.setAttribute('href', '/download/windows');
		}		
	}
};
Event.onDOMReady(GlobalInit);