/* Developer ATTENTION:
 * DO NOT copy this file to your website.
 * We keep updating our services and modifying this file.
 * In such cases, your copied *.js may not work in the future.
 * For correctly embedding WeBuzz.IM web messenger, please visit:
 * http://blog.izuz.net/category/developer/
 */
var winLoc = window.location.toString ();
if (winLoc.indexOf (".webuzz.im/") != -1) {
	window.location.replace ("http://webuzz.im/");
}
/* We keep updating our web messengers */
var j2sBuildDate = "20100714";
var j2sRelative = "2.0.1-v" + j2sBuildDate;
var zimRelative = "wbzz-v20100714";
var widgetRelative = "wz-v20100714";

window["j2s.update.delta"] = [
        "wbzz-v20100714", "wbzz-v20100727", "im/webuzz/g/Buzzing.js",
        "$", "$", "im/webuzz/ViewportSenseUtils.js",
        "$", "$", "im/webuzz/buzz.z.js",
        "$", "$", "im/webuzz/main.z.js"
];

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";

if (window.location.toString ().indexOf ("about:") != -1) {
	document.title = "We Buzz Together - WeBuzz.IM";
}

// 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 multipleSites (path) {
	var length = path.length;
	if ((length > 15 && path.substring (0, 15) == "http://archive.")
			|| (length > 9 && path.substring (0, 9) == "http://a.")) {
		var index = path.lastIndexOf ("/");
		if (index < length - 3) {
			var arr = ['a', 'e', 'i', 'o', 'u', 'y'];
			var c1 = path.charCodeAt (index + 1);
			var c2 = path.charCodeAt (index + 2);
			var idx = (length - index) * 3 + c1 * 5 + c2 * 7; // Hash
			return path.substring (0, 7) + arr[idx % 6] + path.substring (8);
		}
	}
	return path;
}
function generatingScriptFunction (script) {
	return function () {
		eval (script);
		var e = window.event;
		e.cancelBubble = true;
		e.returnValue = false;
		return false;
	};
};

function fixLink (id, args, icon) {
	var alaaDiv = document.getElementById (id);
	if (alaaDiv == null) {
		return;
	}
	var o = window["j2s.lib"];
	//var j2sRelative = (o.alias ? o.alias : o.version);
	var j2sBase = o.base + j2sRelative + "/";
	// var zimRelative = "webuzz-v20090308";
	var zimBase = o.base + zimRelative + "/";
	if (typeof args == "string") {
		alaaDiv.href = args;
		alaaDiv.target = "_blank";
	} else {
		var argsStr = "[";
		if (args != null && args.length > 0) {
			for (var i = 0; i < args.length; i++) {
				argsStr += "\'" + args[i] + "\'";
				if (i != args.length - 1) {
					argsStr += ",";
				}
			}
		}
		argsStr += "]";
		var script = "if(a='im.webuzz.g.MainWindow@" + zimBase + "',r=" + argsStr + ",window['ClazzLoader']!=null)$w$(a,r);else{var d=document,t='onreadystatechange',x=d.createElement('SCRIPT'),f=function(){var s=this.readyState;if(s==null||s=='loaded'||s=='complete'){$w$(a,r);}};x.src='" + j2sBase + "j2slib.z.js';(typeof x[t]=='undefined')?x.onload=f:x[t]=f;d.getElementsByTagName('HEAD')[0].appendChild(x);void(0);}";
		alaaDiv.href = "javascript:" + script;
		if (navigator.userAgent.toLowerCase ().indexOf ("msie") != -1) {
			if (args != null && args.length > 0
					&& (args[0] == "--gtalk" || args[0] == "--msn"
					|| args[0] == "--ymsg" || args[0] == "--facebook"
					|| args[0] == "--aim" || args[0] == "--icq"
					|| args[0] == "--jabber")) {
				alaaDiv.href = "#" + args[0].substring (2);
			} else {
				alaaDiv.href = "#";
			}
			alaaDiv.onclick = generatingScriptFunction (script);
		}
	}
	if (icon != null) {
		var logos = [
				"g-logo.png",
				"m-logo.png",
				"y-logo.png",
				"a-logo.png",
				"i-logo.png",
				"j-logo.png",
				"b-logo.png",
				"mail-logo.png",
				"", //"icon-g.png",
				"", //"icon-m.png",
				"", //"icon-y.png",
				"", //"icon-a.png",
				"", //"icon-i.png",
				"", //"icon-j.png",
				"" //"icon-b.png"
		];
		var margin = 4;
		var width = 32;
		var height = 32;
		var i = -1;
		for (var j = 0; j < logos.length; j++) {
			if (logos[j] == icon) {
				i = j;
				break;
			}
		}
		if (i == -1) {
			var iconURL = multipleSites (icon);
			if (alaaDiv.className != null && alaaDiv.className.indexOf ("shortcut-item") != -1) {
				alaaDiv.style.backgroundImage = "url('" + iconURL + "')";
			} else {
				for (var j = 0; j < alaaDiv.childNodes.length; j++) {
					var item = alaaDiv.childNodes[j];
					if (item != null && item.className != null
							&& item.className.indexOf ("alaa-icon") != -1) {
						item.style.backgroundImage = "url('" + iconURL + "')";
						break;
					}
				}
			}
			return;
		}
		var arraySize = Math.ceil (Math.sqrt (logos.length));
		var ix = i % arraySize;
		var iy = (i - ix) / arraySize;
		var x = ix * (width + margin);
		var y = iy * (height + margin);
		var iconURL = multipleSites (zimBase + "im/webuzz/g/images/logos.png");
		if (alaaDiv.className != null && alaaDiv.className.indexOf ("shortcut-item") != -1) {
			alaaDiv.style.backgroundImage = "url('" + iconURL + "')";
			alaaDiv.style.backgroundPosition = "-" + x + "px -" + y + "px";
		} else {
			for (var j = 0; j < alaaDiv.childNodes.length; j++) {
				var item = alaaDiv.childNodes[j];
				if (item != null && item.className != null
						&& item.className.indexOf ("alaa-icon") != -1) {
					item.style.backgroundImage = "url('" + iconURL + "')";
					item.style.backgroundPosition = "-" + x + "px -" + y + "px";
					break;
				}
			}
		}
	}
}

function addDockLink (id, text) {
	var el = document.getElementById (id);
	if (el != null) {
		return;
	}
	var anchor = document.createElement ("A");
	anchor.id = id;
	anchor.className = "alaa";
	anchor.href = "#";
	anchor.style.display = "none";
	document.body.appendChild (anchor);
	var iconSpan = document.createElement ("SPAN");
	iconSpan.className = "alaa-icon";
	anchor.appendChild (iconSpan);
	anchor.appendChild (document.createTextNode (text));
}

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 adjustDesktop () { // will be called if desktop finished initialization
	if (window["webuzz.im.type"] == null) {
		fixLink ("alaa-gtalk", ["--gtalk", "java2script.talk", "zzzzzzzz"], "g-logo.png");
		fixLink ("alaa-msn", ["--msn", "java2script.talk@gmail.com", "zzzzzzzz"], "m-logo.png");
		fixLink ("alaa-ymsg", ["--ymsg", "java2script.talk", "zzzzzzzz"], "y-logo.png");
		fixLink ("alaa-aim", ["--aim", "j2stalk", "zzzzzzzz"], "a-logo.png");
		fixLink ("alaa-icq", ["--icq", "582890450", "zzzzzzzz"], "i-logo.png");
		fixLink ("alaa-jabber", ["--jabber", "java2script.talk@jabber.org", "zzzzzzzz"], "j-logo.png");
		fixLink ("alaa-facebook", ["--facebook", "java2script.talk", "zzzzzzzz"], "b-logo.png");
		fixLink ("alaa-wemail", "http://webuzz.im/mail/", "mail-logo.png");
	}
	var alaaMail = document.getElementById ("alaa-mail");
	if (alaaMail != null) {
		alaaMail.target = "_blank";
	}
	var alaaTetris = document.getElementById ("alaa-tetris");
	if (alaaTetris != null) {
		alaaTetris.style.backgroundPosition = "center center";
	}
	var alaaControls = document.getElementById ("alaa-controls");
	if (alaaControls != null) {
		alaaControls.style.backgroundPosition = "center center";
	}
}

function loadDesktop () {
	if (window["webuzz.im.type"] == null) {
		addDockLink ("alaa-facebook", "Facebook Chat");
		addDockLink ("alaa-gtalk", "Google Talk");
		addDockLink ("alaa-msn", "Windows Live / MSN Messenger");
		addDockLink ("alaa-ymsg", "Yahoo! Messenger");
		addDockLink ("alaa-aim", "AOL Instant Messenger / AIM");
		addDockLink ("alaa-icq", "ICQ");
		addDockLink ("alaa-jabber", "Jabber");
		addDockLink ("alaa-wemail", "WeMail - Web Mail Client for Gmail, Live Mail/Hotmail, Yahoo! Mail/Rocket Mail, AOL Mail/AIM Mail and others");
	}
	loadJ2SApp ();
}

function initJ2SDesktop () {
	if (document.body != null) {
		loadDesktop ();
	} 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");
}

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" ];

/* Begin of package.js */

/* private */
window["im.webuzz.registered"] = false;

Clazz.declarePackage ("az");
Clazz.declarePackage ("ez");
Clazz.declarePackage ("gz");
Clazz.declarePackage ("mz");
Clazz.declarePackage ("uz");
Clazz.declarePackage ("wz");
Clazz.declarePackage ("yz");

window["im.webuzz.package.callback"] = function () {
	window["im.webuzz.package.callback"] = null;
	var path = ClazzLoader.getClasspathFor ("im.webuzz.*");
	
	ClazzLoader.jarClasspath (path + "modelrpc.z.js", [
		"im.webuzz.model.ZimListener",
		"$.ZimClientListener",
		"$.ZimFriendListener",
		"$.ZimGroupListener",
		"$.ZimMessageListener",
		"$.ZimUserListener",
		"$.ZimAdapter",
		
		"$.ZimItem",
		"$.ZimList",
		"$.ZimMessage",
		"$.ZimUser",
		"$.ZimOwner",
		"$.ZimThread",
		"$.ZimGroup",
		"$.ZimFriend",
		"$.ZimClient",
		"$.ZimManager",

		"ez.AF",
		"$.AT",
		"$.CG",
		"$.EF",
		"$.IF",
		"$.LO",
		"$.NT",
		"$.SF",
		"$.SM",
		"$.UA",
		"$.UN",
		"$.US",
		
		"wz.FC",
		"$.FE",
		"$.GE",
		"$.LE",
		"$.ME",
		"$.MN",
		"$.RC",
		"$.RP",
		"$.TE",
		
		"uz.IMRunnable",
		"$.IStatusMode",
		"$.DelegatableIMPipeSession",
		"$.LoginRunnable",
		"$.AbstractProxyExecutable",
		"$.ProxyBuzzRunnable",
		"$.IMUtils",
		"$.SimpleRSA",
		
		"gz.GPipe",
		"mz.MPipe",
		"yz.YPipe",
		"az.APipe",
		"iz.IPipe",
		"jz.JPipe",
		"bz.FBPipe"
	]);
	ClazzLoader.jarClasspath (path + "main.z.js", [
   		"im.webuzz.ViewportSenseUtils",
   		"im.webuzz.BuzzRequest",
		"$.TitleNotifier",
		"im.webuzz.g.I18N",
		"$.ImageManager",
		"$.Options",
		"$.ShellSingletonUtils",
		"$.TopLogoPanel",
		"$.UserPressence",
		"$.UserStatusPanel",
		"$.SearchContactPanel",
		"im.webuzz.g.prefs.Preferences",
		"im.webuzz.g.MainWindow"
	]);
	ClazzLoader.jarClasspath (path + "buzz.z.js", [
   		"im.webuzz.FlashUtils",

		"im.webuzz.g.Dashboard",
		"$.ContactCard",
		"$.PopupNotifier",
		"$.BuzzToolBar",
		"$.BuzzingUtils",
		"$.Buzzing",

		"im.webuzz.g.themes.Bubble",
		"$.BubblePicture",
		"$.Classi",
		"$.ClassicPicture",
		"$.Orkut",
		"$.OrkutPicture",
		"$.PingPongPicture",
		"$.Serene",
		"$.SerenePicture",
		"$.Swiss",
		"$.SwissPicture"
	]);
	ClazzLoader.jarClasspath (path + "settings.z.js", [
   		"im.webuzz.g.prefs.Settings",
   		"$.OptionGeneral",
   		"$.OptionBuzz",
   		"$.OptionBlocked",
   		"$.OptionNotifications",
   		"$.OptionConnection",
   		"$.OptionAudio",
   		"$.OptionAppearance"
   	]);
	ClazzLoader.jarClasspath (path + "dialogs.z.js", [
  		"im.webuzz.g.NotifyStillRunning",
  		"$.InviteFriendsDialog",
  		"$.BlockFriend",
  		"$.RemoveFriend",
  		"$.AboutWeBuzz"
  	]);
};
if (ClazzLoader.classpathMap["@im.webuzz"] != null) {
	window["im.webuzz.package.callback"] ();
}

/* private */
window["im.webuzz.registered"] = true;

/* End of package.js */

		ClazzLoader.packageClasspath ("im.webuzz", loadingSite + zimRelative, true);
		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"
		]);

		// For SWT Control Examples
		ClazzLoader.packageClasspath ("org.eclipse.swt.examples.controlexample", "http://demo.java2script.org/controls/bin/");

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

			$wt.widgets.Display.getDefault();
			
			window.defaultWindowLeft = "200";
			window.defaultWindowTop = "28";

			adjustDesktop (); // fix dock links and icons
			if (window["localStorage"] != null && localStorage.getItem ("wbzz.store") != null) {
				window["j2s.html5.store"] = true;
			}
			ClazzLoader.loadClass ("im.webuzz.g.MainWindow", function () {
				net.sf.j2s.ajax.SimplePipeRequest.switchToQueryMode (1000);

				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 () {
							var imType = im.webuzz.g.MainWindow.parseIMType ();
							if (imType == null) {
								imType = window["webuzz.im.type"];
							}
							if (imType != null) {
								im.webuzz.g.MainWindow.main(["--" + imType]);
								return;
							}

							im.webuzz.g.MainWindow.loadKnownMessengers ();
						}, 2500);

					}
				}); // end of SimpleStore

				if (window["webuzz.im.type"] != null) {
					return;
				}
				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);

						if (window["webuzz.im.type"] != null) {
							return;
						}
						ClazzLoader.loadClass ("im.webuzz.news.ServicesNewsWidget", function () {
							new im.webuzz.news.ServicesNewsWidget (im.webuzz.balance.BuzzAccessibility.getServiceServer () + "news/simplerpc").start ();
						});
						ClazzLoader.loadClass ("im.webuzz.background.BingBackgroundWidget", function () {
							window.setTimeout (function () {
								new im.webuzz.background.BingBackgroundWidget (im.webuzz.balance.BuzzAccessibility.getServiceServer () + "bingbg/simplerpc").start ();
							}, 1000 + Math.round (Math.random () * 1000));
						});
						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);
					}
				});
				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");
						}
					});
				});
			});

			if (window["webuzz.im.type"] != null) {
				return;
			}
			ClazzLoader.loadClass ("im.webuzz.ViewportSenseUtils", function () {
				if (document.getElementById ("gsidebar") == null) {
					im.webuzz.ViewportSenseUtils.startAdRotating();
				} else {
					im.webuzz.ViewportSenseUtils.switchingAds();
				}
			});
		});
	}
};

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"
	//*/
	"http://personalfinance.ziger.net/",
	"http://lifehack.ziger.net/",
	"http://technews.ziger.net/"
];
(function () {
	var loc = window.location.toString ();
	var idx = loc.indexOf ("#");
	if (idx != -1) {
		loc = loc.substring (0, idx);
	}
	var addCurrentPage = false;
	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) {
		addCurrentPage = true;
	}
	var rnd = Math.random ();
	if (addCurrentPage) {
		if (rnd > 0.5) {
			window["webuzz.im.pages"] = [
				"http://personalfinance.ziger.net/",
				"http://technews.ziger.net/"
			];
		} else if (rnd > 0.25) {
			window["webuzz.im.pages"] = [
				"http://personalfinance.ziger.net/",
				"http://lifehack.ziger.net/"
			];
		} else {
			window["webuzz.im.pages"] = [
				"http://personalfinance.ziger.net/",
				loc
			];
		}
	} else {
		if (rnd > 0.25) {
			window["webuzz.im.pages"] = [
				"http://personalfinance.ziger.net/",
				"http://technews.ziger.net/"
			];
		} else {
			window["webuzz.im.pages"] = [
				"http://personalfinance.ziger.net/",
				"http://lifehack.ziger.net/"
			];
		}
	}
}) ();

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;
		}
	}
}

if (window["imSensed"] == null || !imSensed) {
	//adjustJ2SLibSites ();
	initJ2SDesktop ();
}

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

