var winLoc = window.location.toString ();
if (winLoc.indexOf (".webuzz.im/") != -1) {
	window.location.replace ("http://webuzz.im/");
}
/* We keep updating our web mail client*/
var j2sBuildDate = "20100714";
var j2sRelative = "2.0.1-v" + j2sBuildDate;
var zimRelative = "wm-v20100713";
var widgetRelative = "wz-v20100714";

window["j2s.known.xss.domains"] = [
	"webuzz.im",
	"webuzztogether.com",
	"java2script.net",
	"java2script.com",
	"java2script.org",
	"demo.java2script.org",
	"izuz.net",
	"uziz.net",
	"kexmail.com"
];
//window["j2s.xss.cookie.url"] = "http://c." + host + "/xss-cookie.html";

// remove Google Analytics' subdomain cookies
(function () {
	try {
		var domain = document.domain;
		var expired = new Date ();
		expired.setTime (expired.getTime () - 3600000);
		var keys = ["a", "b", "c", "z"];
		for (var i = 0; i < keys.length; i++) {
			document.cookie = "__utm" + keys[i] + "=; expires=" + expired.toGMTString () + "; path=/; domain=." + domain;
		}
	} catch (e) {
	}
}) ();

window["swt.desktop.vscrollbar"] = true;

function markScriptLoadingError (src) {
	var o = window["j2s.lib"];
	if (o.sites != null && o.errors != null) {
		for (var i = 0; i < o.sites.length; i++) {
			if (o.sites[i].length > 0 && src.indexOf (o.sites[i]) == 0) {
				o.errors[i] = true;
				break;
			}
		}
	}
}

function generateScriptErrorCallback () {
	return function () {
		markScriptLoadingError (this.src);
	};
}
function generateScriptCallback () {
	return function () {
		var s = this.readyState;
		if (s == null || s == "loaded" || s == "complete") {
			if (window["ClazzLoader"] != null) {
				window["j2s.lib"].onload (this);
			} else {
				markScriptLoadingError (this.src);
			}
			this.onreadystatechange = null;
			this.onload = null;
		}
	};
}

function loadJ2SLibZJS (path, cb) {
	var sxr = document.createElement ("SCRIPT");
	var deltas = window["j2s.update.delta"];
	if (deltas != null && deltas instanceof Array && deltas.length >= 3) {
		var lastOldVersion = null;
		var lastNewVersion = null;
		for (var i = 0; i < deltas.length / 3; i++) {
			var oldVersion = deltas[i + i + i];
			if (oldVersion != "$") {
				lastOldVersion = oldVersion;
			}
			var newVersion = deltas[i + i + i + 1];
			if (newVersion != "$") {
				lastNewVersion = newVersion;
			}
			var relativePath = deltas[i + i + i + 2];
			var key = lastOldVersion + "/" + relativePath;
			var idx = path.indexOf (key);
			if (idx != -1 && idx == path.length - key.length) {
				path = path.substring (0, idx) + lastNewVersion + "/" + relativePath;
				break;
			}
		}
	}
	sxr.src = path;
	sxr.type = "text/javascript";
	if (cb) {
		var t = "onreadystatechange";
		var xhrCallback = generateScriptCallback ();
		if (typeof sxr[t] == "undefined") {
			sxr.onload = xhrCallback;
			sxr.onerror = generateScriptErrorCallback ();
		} else {
			sxr[t] = xhrCallback;
		}
	}
	document.getElementsByTagName ("HEAD")[0].appendChild (sxr);
}

function loadJ2SApp (forced) {
	// Some visitors use sneakypass to use webuzz.im services. 
	// We just make some change so it will get a much better user
	// experience. We have NO business relationship with sneakypass.
	var host = null;
	try {
		host = window.location.host;
	} catch (e) {
	}
	if (host != null) {
		var isSneakyPass = host.indexOf ("sneakypass") != -1;
		if (isSneakyPass && forced != true) {
			custom_handler = function () {
				loadJ2SApp (true);
			};
			return;
		}
	}
	var o = window["j2s.lib"];
	if (o.loaded) {
		return;
	}
	var checkingInterval = 2000;
	var site = null;
	var prevSite = null;
	var loadFromAnotherSite = false;
	if (o.sites == null || o.sites.length == 0) {
		site = "http://archive.java2script.org/"; // should never reach here!
	} else {
		if (o.index > 0) {
			prevSite = o.sites[o.index - 1];
		}
		site = o.sites[o.index];
		loadFromAnotherSite = true;
	}
	var j2sLibSuffix = "/j2slib.swt.z.js";
	if (prevSite != null && prevSite.length > 0 && !o.errors[o.index - 1]) {
		if (navigator.userAgent.toLowerCase ().indexOf ("opera") != -1) {
			var scripts = document.getElementsByTagName ("SCRIPT");
			if (scripts != null && scripts.length > 0) {
				for (var i = 0; i < scripts.length; i++) {
					var s = scripts[i];
					if (s.src != null && s.src.length > 0 && s.src.indexOf (prevSite) == 0
							&& s.src.indexOf (j2sLibSuffix) == s.src.length - j2sLibSuffix.length) {
						if (s.readyState == "loaded" || s.readyState == "complete") {
							o.errors[o.index - 1] = true; // if successfully loaded, o.errors will be ignored
							checkingInterval = 1000;
						}
						break;
					}
				}
			}
		}
		window.setTimeout (loadJ2SApp, checkingInterval); // Not loaded yet
		return;
	}
	if (o.sites != null && o.sites.length > 0 && o.index >= o.sites.length) {
		alert ("Failed to load Java2Script core libraries from given "
				+ o.sites.length + " sites : " + o.sites + " !\r\n"
				+ "Please check your network!");
		return;
	}
	if (loadFromAnotherSite) {
		if (o.errors == null) {
			o.errors = [];
		}
		o.errors[o.index] = false;
		o.index++;
	}
	loadJ2SLibZJS(site + (o.alias ? o.alias : o.version) + j2sLibSuffix, o.onload);
	window.setTimeout (loadJ2SApp, checkingInterval); // Not loaded, try again with another site
}


function initJ2SDesktop () {
	if (document.body != null) {
		loadJ2SApp();
	} else {
		/* for Mozilla */
		if (document.addEventListener) {
			document.addEventListener ("DOMContentLoaded", loadDesktop, false);
		} else if (/WebKit/i.test (navigator.userAgent)) { // sniff
			var _timer = window.setInterval (function () {
				if (/loaded|complete/.test (document.readyState)) {
					window.clearInterval (_timer);
					loadDesktop (); // call the onload handler
				}
			}, 10);
		} else {
// for Internet Explorer (using conditional comments)
/*@cc_on @*/
/*@if (@_win32)
document.write ("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById ("__ie_onload");
script.onreadystatechange = function () {
	if (this.readyState == "complete") {
		loadDesktop (); // call the onload handler
	}
};
/*@end @*/
		}
	}
}

function createCookie (name, value, days) {
	var expires = "";
	if (days != null) {
		var toExpireDate = new Date();
		toExpireDate.setTime (toExpireDate.getTime () + days * 24 * 3600 * 1000);
		expires = "; expires=" + toExpireDate.toGMTString ();
	}
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie (name) {
	var prefix = name + "=";
	var allCookies = document.cookie.split (';');
	for(var i = 0; i < allCookies.length; i++) {
		var item = allCookies[i].replace (/^\s*/, "");
		if (item.indexOf (prefix) == 0) {
			return item.substring (prefix.length, item.length);
		}
	}
	return null;
}

function fixCookie(type, store) {
	var cookieName = type + ".pref";
	var p = readCookie (cookieName);
	if (p != null) {
		var pp = store.getProperty (cookieName);
		createCookie (cookieName, "", -1);
		if (pp == null) {
			store.setProperty (cookieName, p);
		}
	}
	for (var i = 1; i <= 5; i++) {
		cookieName = type + "." + i + ".pref";
		p = readCookie (cookieName);
		if (p != null) {
			var pp = store.getProperty (cookieName);
			createCookie (cookieName, "", -1);
			if (pp == null) {
				store.setProperty (cookieName, p);
			}
		}
	}
}

function moveXSSCookies (store) {
	fixCookie ("G", store);
	fixCookie ("M", store);
	fixCookie ("Y", store);
	fixCookie ("A", store);
	fixCookie ("I", store);
	fixCookie ("J", store);
	fixCookie ("B", store);

	var cookieName = "wblang";
	var p = readCookie (cookieName);
	if (p != null) {
		var pp = store.getProperty (cookieName);
		createCookie (cookieName, "", -1);
		if (pp == null) {
			store.setProperty ("wbzz.lang", p);
		}
	}
	cookieName = "bgstatus";
	p = readCookie (cookieName);
	if (p != null) {
		var pp = store.getProperty (cookieName);
		createCookie (cookieName, "", -1);
		if (pp == null) {
			store.setProperty (cookieName, p);
		}
	}
	cookieName = "wbzz.visits";
	var p = readCookie (cookieName);
	if (p != null) {
		var v1 = 0;
		try {
			v1 = parseInt (p);
		} catch (e) {}
		var pp = store.getProperty (cookieName);
		var v2 = 0;
		if (pp != null) {
			try {
				v2 = parseInt (pp);
			} catch (e) {}
		}
		createCookie (cookieName, "", -1);
		if (v1 > v2) {
			store.setProperty (cookieName, p);
		}
	}
}

function moveCookie2HTML5Store(cookieName, store) {
	var p = store.getProperty (cookieName);
	if (p != null) {
		var pp = localStorage.getItem (cookieName);
		store.setProperty (cookieName, null);
		if (pp == null) {
			localStorage.setItem (cookieName, p);
		}
	}
}

function movePrefs2HTML5Store(type, store) {
	moveCookie2HTML5Store (type + ".pref", store);
	for (var i = 1; i <= 5; i++) {
		moveCookie2HTML5Store (type + "." + i + ".pref", store);
	}
}

function moveXSSCookies2HTML5Store (store) {
	movePrefs2HTML5Store ("G", store);
	movePrefs2HTML5Store ("M", store);
	movePrefs2HTML5Store ("Y", store);
	movePrefs2HTML5Store ("A", store);
	movePrefs2HTML5Store ("I", store);
	movePrefs2HTML5Store ("J", store);
	movePrefs2HTML5Store ("B", store);

	moveCookie2HTML5Store ("wbzz.lang", store);
	moveCookie2HTML5Store ("bgstatus", store);
	moveCookie2HTML5Store ("wbzz.visits", store);

	moveCookie2HTML5Store ("wz.bing.time", store);
	moveCookie2HTML5Store ("wz.bing.status", store);
	moveCookie2HTML5Store ("wz.news.time", store);
	moveCookie2HTML5Store ("wz.news.status", store);
	moveCookie2HTML5Store ("wz.kkl.time", store);
	moveCookie2HTML5Store ("wz.kkl.status", store);
	moveCookie2HTML5Store ("wz.chrome.time", store);
	moveCookie2HTML5Store ("wz.chrome.status", store);
	moveCookie2HTML5Store ("wbzz.i18n.session", store);

	localStorage.setItem ("wbzz.store", "true");
}

function generateAddThisScriptCallback () {
	return function () {
		var s = this.readyState;
		if (s == null || s == "loaded" || s == "complete") {
			if (window.onload != null) {
				try {
					window.onload ();
				} catch (e) {
				}
			} else {
				window.setTimeout (function () {
					if (window.onload != null) {
						try {
							window.onload ();
						} catch (e) {
						}
					}
				}, 1000);
			}
			this.onreadystatechange = null;
			this.onload = null;
		}
	};
}

function adjustAddThisButtons () {
	window.setTimeout (function () {
		window.onload = null;
		var sxr = document.createElement ("SCRIPT");
		sxr.src = "http://s7.addthis.com/js/250/addthis_widget.js#username=zhourenjian";
		sxr.type = "text/javascript";
		var t = "onreadystatechange";
		var xhrCallback = generateAddThisScriptCallback ();
		if (typeof sxr[t] == "undefined") {
			sxr.onload = xhrCallback;
		} else {
			sxr[t] = xhrCallback;
		}
		document.getElementsByTagName ("HEAD")[0].appendChild (sxr);
	}, 2500);
}

function insertAddThisButton () {
	var toolbox = document.getElementById ("wbzz-add-this");
	if (toolbox == null) {
		toolbox = document.createElement ("DIV");
		toolbox.id = "wbzz-add-this";
		toolbox.className = "addthis_toolbox addthis_default_style";
		toolbox.style.cssText = "margin:32px 8px 16px 7px;height:1em;clear:left;font-family:Arial,sans-serif;font-size:13pt;";
		var panel = document.getElementById ("swt-desktop-panel");
		if (panel != null) {
			var childNodes = panel.childNodes;
			var inserted = false;
			for (var i = 0; i < childNodes.length; i++) {
				var child = childNodes[i];
				if (child.className == "webuzz-widget") {
					panel.insertBefore (toolbox, child);
					inserted = true;
					break;
				} else if (child.className == "page-bottom-end") {
					toolbox.style.marginTop = "16px";
					panel.insertBefore (toolbox, child);
					inserted = true;
					break;
				}
			}
			if (!inserted) {
				toolbox.style.marginTop = "16px";
				panel.appendChild (toolbox);
			}
		} else {
			document.body.appendChild (toolbox);
		}
	}
	if (toolbox.childNodes.length > 2) {
		return toolbox; // already ok
	}

	var addDiv = document.createElement ("A");
	addDiv.className = "addthis_button_compact";
	addDiv.href = "http://www.addthis.com/bookmark.php?v=250&amp;username=zhourenjian";
	toolbox.appendChild (addDiv);
	
	var separatorDiv = document.createElement ("SPAN");
	separatorDiv.className = "addthis_separator";
	toolbox.appendChild (separatorDiv);

	var sharings = [
		"facebook",
		"myspace",
		"twitter",
		"google",
		"googlebuzz",
		"buzz",
		"digg",
		"stumbleupon",
		"delicious",
		"diigo",
		"orkut"
	];
	for (var i = 0; i < sharings.length; i++) {
		var itemDiv = document.createElement ("A");
		itemDiv.className = "addthis_button_" + sharings[i];
		toolbox.appendChild (itemDiv);
	}
	return toolbox;
}

function fixAddThisButtons (btn) {
	var cssLink = document.createElement ("LINK");
	cssLink.rel = "stylesheet";
	cssLink.href = "http://s7.addthis.com/static/r07/widget40.css";
	document.getElementsByTagName ("HEAD")[0].appendChild (cssLink);
	var childNodes = btn.childNodes;
	for (var i = 0; i < childNodes.length; i++) {
		var child = childNodes[i];
		var cssClass = child.className;
		var prefix = "addthis_button_";
		var idx = -1;
		if (cssClass != null && cssClass.indexOf ("addthis_separator") != -1) {
			continue;
		}
		if (cssClass != null && (idx = cssClass.indexOf (prefix)) != -1) {
			child.style.textDecoration = "none";
			var id = null;
			var idxEnd = cssClass.indexOf (" ", idx + prefix.length);
			if (idxEnd == -1) {
				id = cssClass.substring (idx + prefix.length);
			} else {
				id = cssClass.substring (idx + prefix.length, idxEnd);
			}
			var maps = [
				"compact", "",
				"facebook", "Facebook",
				"myspace", "MySpace",
				"twitter", "Tweet This",
				"google", "Google",
				"googlebuzz", "Google Buzz",
				"buzz", "Y! Buzz",
				"digg", "Digg This",
				"stumbleupon", "StumbleUpon",
				"delicious", "Del.icio.us",
				"diigo", "Diigo",
				"orkut", "Orkut"
			];
			for (var j = 0; j < maps.length / 2; j++) {
				if (id == maps[j+ j]) {
					if (id == "compact") {
						child.className += " at300m";
						child.title = "More Sharings";
						//child.appendChild (document.createTextNode ("Share"));
					} else {
						child.className += " at300b";
						var text = maps[j + j + 1];
						if (text.indexOf ("This") == -1) {
							text = "Send to " + text;
						}
						child.title = text;
						child.href = "http://www.addthis.com/bookmark.php?pub=&v=250&source=tbx-250&tt=0&s=" + id
								+ "&url=" + encodeURIComponent(window.location.toString ())
								+ "&title=" + encodeURIComponent(document.title) + "&content=&lng=en";
					}
					child.target = "_blank";
					var iconEl = document.createElement ("SPAN");
					iconEl.className = "at300bs at15t_" + id;
					child.appendChild (iconEl);
					break;
				}
			}

		}
	}
}

window["j2s.object.native"] = true;

window["j2s.lib"] = {
	sites : [
			"http://a.woziger.com/",
			"http://archive.woziger.com/",
			"http://a.webuzz.im/",
			"http://a.java2script.org/",
			"http://archive.java2script.org/",
			"http://a.java2script.net/",
			"http://a.java2script.com/",
			"http://a.kexmail.com/",
			"http://a.izuz.net/",
			"http://a.uziz.net/"//*/
		],
	index : 0,
	base : null,
	alias : j2sRelative, //"2.0.0-v20090310",
	version : "v" + j2sBuildDate, // "v20090310",
	/*forward : true,*/
	mode : "dailybuild",
	loaded : false,
	onload : function (script) {
		var o = window["j2s.lib"];
		if (o.loaded) {
			return;
		}
		o.loaded = true;
		var src = script.src;
		var loadingSite = "http://archive.java2script.org/";
		for (var i = 0; i < o.sites.length; i++) {
			if (src.indexOf (o.sites[i]) == 0) {
				loadingSite = o.sites[i];
				o.base = loadingSite;
				break;
			}
		}
		//var j2sRelative = (o.alias ? o.alias : o.version);
		ClazzLoader.packageClasspath ("java", loadingSite + j2sRelative, true);
		ClazzLoader.packageClasspath ("org.eclipse.swt", loadingSite + j2sRelative, true);

		window["j2s.css.single.site.classes"] = [ "im.webuzz.g.themes" ];

		ClazzLoader.packageClasspath ("im.webuzz.mail", loadingSite + zimRelative, true);
		ClazzLoader.packageClasspath (["uz", "im.webuzz.mail.model", "im.webuzz", "im.webuzz.g.prefs"], loadingSite + zimRelative);
		ClazzLoader.setPrimaryFolder (loadingSite + zimRelative);

		ClazzLoader.packageClasspath ([
				"com.swtdesigner",
				"im.webuzz.widget",
				"im.webuzz.balance",
				"im.webuzz.space",
				"im.webuzz.news",
				"im.webuzz.background",
				"im.webuzz.kaixinmeme.widget",
				"im.webuzz.languages",
				"im.webuzz.google"
		], loadingSite + widgetRelative);

		ClazzLoader.jarClasspath (loadingSite + widgetRelative + "/im/webuzz/widgets.z.js", [
    			"im.webuzz.widget.WidgetUtils",
    			"$.AbstractWidget",

    			"im.webuzz.balance.ServiceAccessible",
    			"$.BuzzAccessibility",

    			"im.webuzz.background.ReadBingBackground",
	    		"$.BingBackgroundWidget",

    			"im.webuzz.kaixinmeme.widget.RetrievePhotoPost",
    			"$.WeBrowseWidget",

    			"im.webuzz.news.ServicesLastestNews",
	    		"$.ServicesNewsWidget",

    			"im.webuzz.space.SpaceUtility",
    			"im.webuzz.google.chrome.Chrome4IEWidget",

    			"im.webuzz.languages.I18NSessionRequest",
			"$.I18NLoadingRequest",
       			"$.I18NTranslatingRequest",
			"$.I18NUpdatingRequest",
       			"$.I18NNode",
       			"$.I18NUtils",
       			"$.LanguagesWidget",
       			"$.I18NEditorWidget",

    			"com.swtdesigner.SWTResourceManager"
		]);

		ClazzLoader.loadClass ("org.eclipse.swt.widgets.Display", function () {
			if (O$.isIE) {
				window["swt.disable.shadow"] = true; // improve IE performance
			}

			window.defaultWindowLeft = "200";
			window.defaultWindowTop = "28";

			if (window["localStorage"] != null && localStorage.getItem ("wbzz.store") != null) {
				window["j2s.html5.store"] = true;
			}
			ClazzLoader.loadClass ("im.webuzz.mail.GLoginWindow", function () {

				net.sf.j2s.store.SimpleStore.getDefault ().execute ({
					run : function () {
						var store = net.sf.j2s.store.SimpleStore.getDefault ();
						var host = null;
						try {
							host = window.location.host;
						} catch (e) {
						}
						if (host != null) {
							host = host.toLowerCase ();
						}
						// To be deleted in September, 2010
						if ((O$.isIE || (host != null && (host.indexOf ("webuzztogether.com") != -1 || host.indexOf ("uziz.net") != -1 )))
								&& store.store != null && store.store.getClass ().getName ().indexOf ("XSS") != -1) {
							moveXSSCookies (store);
						}
						var v = store.getProperty ("wblang");
						if (v != null && v.length > 0) {
							store.setProperty ("wblang", null);
							store.setProperty ("wbzz.lang", v);
						}
						var isLocalFile = false;
						try {
							isLocalFile = window.location.protocol == "file:";
						} catch (e) {
							isLocalFile = true;
						}
						if (window["localStorage"] != null && store.store != null && (!O$.isFirefox || !isLocalFile)
								&& store.store.getClass ().getName ().indexOf ("Cookie") != -1) {
							moveXSSCookies2HTML5Store (store);
							window["j2s.html5.store"] = true;
							net.sf.j2s.store.SimpleStore.singleton = null;
							store = net.sf.j2s.store.SimpleStore.getDefault ();
						}
						var v = store.getProperty ("wbzz.visits");
						if (v != null && v.length > 0) {
							var visits = -1;
							try {
								visits = parseInt (v);
							} catch (e) {
							}
							if (visits > 0) {
								adjustPages (visits);
							}
						}
						var v = store.getProperty ("wblang");
						if (v != null && v.length > 0) {
							store.setProperty ("wblang", null);
							store.setProperty ("wbzz.lang", v);
						}
						var v = store.getProperty ("wbzz.lang");
						if (v != null && v.length > 0) {
							window["webuzz.lang"] = v;
							var updateCB = window["webuzz.language.updatecb"];
							if (updateCB != null) {
								try {
									updateCB (v);
								} catch (e) {
								}
							}
						}

						window.setTimeout (function () {
							im.webuzz.mail.GLoginWindow.main([]);
							org.eclipse.swt.widgets.Display.getDefault().trayCorner.toggleAutoHide();

							var btn = insertAddThisButton ();
							if (!O$.isIE) {
								adjustAddThisButtons ();
							} else {
								fixAddThisButtons (btn);
							}
						}, 1000);
						ClazzLoader.loadClass ("im.webuzz.mail.GmailWindow");
					}
				}); // end of SimpleStore

				ClazzLoader.loadClass ("im.webuzz.space.SpaceUtility", function () {
					window.setTimeout (function () {
						im.webuzz.space.SpaceUtility.checkSpace ();
					}, 500);
				});
				if (O$.isIE) {
					ClazzLoader.loadClass ("im.webuzz.google.chrome.Chrome4IEWidget", function () {
						window.setTimeout (function () {
							new im.webuzz.google.chrome.Chrome4IEWidget ().start ();
						}, 750);
					});
				}
			}); // end of MainWindow

			ClazzLoader.loadClass ("im.webuzz.balance.BuzzAccessibility", function () {
				im.webuzz.balance.BuzzAccessibility.setAccessibleOKCallback ({
					run : function () {
						im.webuzz.balance.BuzzAccessibility.setAccessibleOKCallback (null);
						var server = im.webuzz.balance.BuzzAccessibility.getServiceServer ();
						net.sf.j2s.store.SimpleStore.getDefault ().setProperty ("wbzz.last.server", server);

						ClazzLoader.loadClass ("im.webuzz.news.ServicesNewsWidget", function () {
							new im.webuzz.news.ServicesNewsWidget (im.webuzz.balance.BuzzAccessibility.getServiceServer () + "news/simplerpc").start ();
						});
						ClazzLoader.loadClass ("im.webuzz.kaixinmeme.widget.WeBrowseWidget", function () {
							window.setTimeout (function () {
								new im.webuzz.kaixinmeme.widget.WeBrowseWidget ().start ();
							}, 3000 + Math.round (Math.random () * 3000));
						});
						window.setTimeout (function () {
							ClazzLoader.loadClass ("im.webuzz.languages.LanguagesWidget", function () {
								im.webuzz.languages.I18NUtils.rpcRequestURL = im.webuzz.balance.BuzzAccessibility.getServiceServer () + "i18n/simplerpc";
								im.webuzz.languages.LanguagesWidget.initialize ();
							});
						}, 1000);
						window.setTimeout (function () {
							ClazzLoader.loadClass ("im.webuzz.mail.GmailSenseUtils", function () {
								im.webuzz.mail.GmailSenseUtils.startAdRotating();
							});
						}, 1000);
					}
				});
				ClazzLoader.loadClass ("net.sf.j2s.store.SimpleStore", function () {
					net.sf.j2s.store.SimpleStore.getDefault ().execute ({
						run: function () {
							var store = net.sf.j2s.store.SimpleStore.getDefault ();
							var server = store.getProperty ("wbzz.last.server");
							if (server != null && server.length > 0) {
								window["webuzz.im.last.server"] = server;
							}
							im.webuzz.balance.BuzzAccessibility.test ("u/c");
						}
					});
				});
			});
		});
	}
};

function adjustJ2SLibSites () { // if possible, use similar domains for j2slib loading
	var sites = window["j2s.lib"].sites;
	var host = null;
	try {
		host = window.location.host.toLowerCase ();
	} catch (e) {
	}
	if (host != null && host.length > 0) {
		var segments = host.split (/\./);
		if (segments.length >= 2) {
			var domain = segments[segments.length - 2] + "." + segments[segments.length - 1];
			var keyPart = "." + domain + "/";
			for (var i = 0; i < sites.length; i++) {
				if (sites[i].indexOf (keyPart) != -1) {
					if (i != 0) {
						var tmp = sites[i];
						for (var j = i; j >= 1; j--) {
							sites[j] = sites[j - 1];
						}
						sites[0] = tmp;
					}
					break;
				}
			}
		}
	}
}

window["webuzz.im.pages"] = [
	"http://ziger.net/access-blocked-im.html",
	"http://ziger.net/web-im.html",
	"http://ziger.net/p/engadget-20090421.html",
	"http://ziger.net/p/techmeme-20090421.html",
	"http://ziger.net/p/digg-20090421.html",
	"http://ziger.net/p/stock-20100329.html",
	"http://ziger.net/p/lifehack-20100329.html",
	"http://ziger.net/p/techmeme-20100329.html",
	"http://ziger.net/p/stock-20100406.html",
	"http://ziger.net/p/techmeme-20100406.html",
	"http://ziger.net/p/lifehack-20100407.html",
	"http://ziger.net/p/digg-20100407.html",
	"http://ziger.net/p/stock-20100423.html",
	"http://ziger.net/p/lifehack-20100423.html",
	"http://ziger.net/p/techmeme-20100423.html",
	"http://ziger.net/p/personal-20100423.html",
	"http://ziger.net/p/lifehack-20100511.html",
	"http://ziger.net/p/stock-20100511.html",
	"http://ziger.net/p/techmeme-20100511.html",
	"http://ziger.net/p/lifehack-20100624.html",
	"http://ziger.net/p/mobile-20100706.html",
	"http://ziger.net/p/invest-20100706.html",
	"http://ziger.net/p/lifetips-20100706.html",
	"http://ziger.net/p/gadget-20100719.html",
	"http://ziger.net/p/invest-20100719.html",
	"http://ziger.net/p/lifetips-20100719.html"
];

function adjustPages (visits) {
	var pages = window["webuzz.im.pages"];
	if (pages == null) {
		return;
	}
	var changed = false;
	if (pages.length > 10) {
		if (visits > 20) {
			var newPages = [];
			for (var i = Math.max (0, pages.length - 10); i < pages.length; i++) {
				newPages[newPages.length] = pages[i];
			}
			window["webuzz.im.pages"] = newPages;
			changed = true;
		} else if (visits > 10) {
			var newPages = [];
			for (var i = Math.min (5, pages.length - 10); i < pages.length; i++) {
				newPages[newPages.length] = pages[i];
			}
			window["webuzz.im.pages"] = newPages;
			changed = true;
		}
	}
	if (!changed) {
		var newPages = [];
		for (var i = 0; i < Math.min (8, pages.length); i++) {
			newPages[newPages.length] = pages[i];
		}
		window["webuzz.im.pages"] = newPages;
	}
	if (visits < 5) {
		var loc = window.location.toString ();
		var idx = loc.indexOf ("#");
		if (idx != -1) {
			loc = loc.substring (0, idx);
		}
		var ps = window["webuzz.im.pages"];
		if (loc.indexOf ("izuz.net/") != -1 || loc.indexOf ("uziz.net/") != -1
				|| loc.indexOf ("demo.java2script.org/" + "gtalk/") != -1
				|| loc.indexOf ("demo.java2script.org/" + "msnlive/") != -1) {
			ps[ps.length] = loc;
		}
	}
}

//adjustJ2SLibSites ();
initJ2SDesktop ();

window["webuzz.im.servers"] = [
        "http://z3.webuzz.im/",
        "http://z2.webuzz.im/",
        "http://z1.webuzz.im/",
        "http://z3.webuzz.im/",
        "http://z2.webuzz.im/",
        "http://z1.webuzz.im/",
        "http://z3.kexmail.com/",
        "http://z2.kexmail.com/",
        "http://z1.kexmail.com/",
        "http://z3.izuz.net/",
        "http://z2.izuz.net/",
        "http://z1.izuz.net/",
        "http://z3.uziz.net/",
        "http://z2.uziz.net/",
        "http://z1.uziz.net/",
        "http://z3.demo.java2script.org/",
        "http://z2.demo.java2script.org/",
        "http://z1.demo.java2script.org/",
        "http://z3.java2script.org/",
        "http://z2.java2script.org/",
        "http://z1.java2script.org/",
        "http://z3.java2script.net/",
        "http://z2.java2script.net/",
        "http://z1.java2script.net/",
        "http://z3.java2script.com/",
        "http://z2.java2script.com/",
        "http://z1.java2script.com/"
];

var adsBox = document.getElementById ("google-ads-box");
if (adsBox != null) {
	var gad = document.createElement ("IFRAME");
	gad.id = "google-ad";
	gad.setAttribute("frameBorder", "0");
	//gad.src = "http://ziger.net/wemail-web-mail.html";
	//gad.src = "http://ziger.net/p/personal-20100423.html#304440";
	var pages = [
		"http://personalfinance.ziger.net/",
		"http://technews.ziger.net/",
		"http://lifehack.ziger.net/"
	];
	gad.src = pages[Math.floor (Math.random () * pages.length)] + "#304440";

	gad.style.position = "absolute";
	gad.style.overflow = "hidden";
	gad.style.border = "0 none transparent";

	gad.style.width = "336px";
	gad.style.height = "280px";
	gad.style.margin = "0";
	gad.style.marginLeft = "8px";
	gad.style.marginTop = "8px";
	gad.style.padding = "0";
	adsBox.appendChild (gad);
}
