/*==========
author:	吴颖晖 Freddie
copyright:	Copyright (c) 1998-2009 Flying @ Flying's World
version:	5.4b
*/if("object"!=typeof window.F){var e="Required: F.js";alert(e);throw new Error(e);}/*
==========*/
F[1]={};

/*< browser/standard quirks >*/
F[1].Quirks={
	XHTML_1_0:function(){
		var targets={
			replace:function(){this.target="_top";},
			external:function(){this.target=F.Base64.enc(this.href).replace(/[^A-Za-z0-9_]g/,'_');}
		};
		targets.help=targets.external;	//replicate behaviour
		$.each(targets,function(tgt,rel){$("a[rel='"+tgt+"']").each(rel);});
	},
//IE4: 3.x
//IE5.x: <= 5.5
//IE6: 5.6
//IE7: 5.7
	MS_IE:function(isUpd){/*@cc_on
	@if(@_jscript && (@_jscript_version <= 5.7))
		if(!isUpd){
			$("hr","#yui-main").each(function(){$(this).replaceWith($("<div/>").addClass(this.className).addClass("hr"));});
			//1.IE.css
			$("#navbar ul").append('<span style="text-decoration:blink">&#x2592;</span>');
			$("#navbar li").filter(":not(:first)").prepend("/&ensp;").end().filter(":last").append("&ensp;$");
			var qs=['&ldquo;','&rdquo;','&lsquo;','&rsquo;'];
			$("q q","#yui-main").prepend(qs[2]||qs[0]).append(qs[3]||qs[1]);
			$("q","#yui-main").filter(function(){return $(this).parents("q").length<=0;}).prepend(qs[0]).append(qs[1]);
			//2.css
			$("div.album div.item cite","#yui-main").prepend("〖").append("〗");
		}else setTimeout(function(){
			$(".zh").removeClass("zh");
			$("[lang^='zh']").addClass("zh");
			$("[xml\\:lang^='zh']").addClass("zh");	//does this actually work?
		},500);
	@end
	@*/},
	IE7_js:function(){/*@cc_on
	@if(@_jscript && (@_jscript_version < 5.7))
		//1.IE.css
		$("#bd").css("height","460px");
		//YUI+IE7-js creates a mysterious <!> node that contains bogus margin value
		var tid=setInterval(function(){
			var o=$("#yui-main").parent();  
			if(o.get(0).tagName=="!"){
				o.css("margin-left",0);
				clearInterval(tid);
			}
		},250);
	@end
	@*/},
	WebKit:function(){
		//WebKit interprets width on <col> strictly as min-width.
		$("html.webkit div.album div.item").each(function(){
			var i=0,tbl=this;
			$(tbl).children("col").each(function(){
				var s=this.span||1,w=this.style.width||(this.width+"px");
				for(var j=0;j<s;++j,++i){
					if("px"==w)continue;
					$.each(tbl.tBodies,function(){
						$.each(this.rows,function(){
							var c=this.cells[i];
							if(c)c.style.width=w;
						});
					});
				}
			});
		});
	}
};

/*< content encryption >*/
F[1].Enc={
	email:function(){
		$("a.enc")
		.children("code").text(function(i,txt){
			return F.Base64.dec(txt);
		}).end()
		.each(function(){
			this.href=this.href.replace('@',$(this).text());
		});
	}
};

/*< multilingual UI >*/
F[1].MUI={
	id:"F:lang",
	init:true,
	tags:[//1.css#F[1].MUI.tags*/
		"span[class^='tr:']"
	,	"div[class^='tr:']"
	],
	init:function(){
		$("#lang > ul > li > a").click(function(){
			F[1].MUI.toggle(this.id);
			return false;
		});
		$('#'+F.Lang.get(F[1].MUI.id)).click();
	},
	toggle:function(lid){
		lid=lid||F.Lang.get(F[1].MUI.id);
		//don't translate if no language change, except during initialization
		if(F[1].MUI.init)F[1].MUI.init=false;
		else if(lid==F.Lang.get(F[1].MUI.id))return;
		//translate all
		$(F[1].MUI.tags.join(',')).each(function(){F[1].MUI.tr(this,lid);});
		//keep track of active language
		var duration=7/*days*/;
		F.cookie(F[1].MUI.id,lid,{expires:duration*(24*60),path:"/"});
		//make sure anchors are working
		var ck=F[1].MUI.id+":URI";
		if(F.cookie(ck)!=location.href){
			if(location.hash.length>0)F.FX.scroll_to(location.hash);
			F.cookie(ck,location.href,{path:"/"});
		}
	},
	tr:function(e,lid){
		var cls=$(e).attr("class");
		var nn=e.nodeName.toLowerCase(),subj='<'+nn+" class='"+cls+"'>...</"+nn+"> ";
		//detect translatable ID
		var mat=/^(tr:(([^: ]+):((auto\.)?[^ ]+)))/.exec(cls);
		F.assert(mat,subj+"is not translatable");
		if(mat[3]==lid)return false;
		//find translation
		var lids=lid.split('-');
		lids=$.map(lids,function(p,i){return ((i>0)?(lids[i-1]+'-'):'')+p;}).reverse();
		lids=$.map(lids,function(l){return l+':'+mat[4];});
		//auto-translation?
		if(mat[5])return F[1].MUI.auto_tr($(e),lid,mat[4],lids,subj);
		lids=$.map(lids,function(l){return '#'+l.replace(/([:.])/g,"\\$1");});
		var tr=$(lids.join(',')).eq(0);
		F.assert(tr.length>0,subj+"has no translation in ["+lid+']');
		//backup original, if necessary
		if($('#'+mat[2].replace(/:/g,"\\:")).length<=0)
			tr.before($(e).clone(true).attr({id:mat[2]}).removeClass(mat[1]));
		//translate by cloning the translation node with class & style preserved
		var cs=$(e).attr("class").split(/\s+/),st=$(e).attr("style");
		cs.shift();cs.unshift("tr:"+tr.attr("id"));
		tr=tr.clone(true).removeAttr("id").lang(lid).attr("class",cs.join(' '));
		if(st)tr.attr({style:st});
		$(e).replaceWith(tr);
		F[1].Quirks.MS_IE(true);
		return true;
	},
	auto_tr:function(o,lid,tid,lids,subj){
		var bkup="tr-db",orig=o.children('.'+bkup);
		//restore original first
		if(orig.length>0){
			orig=orig.clone(true).removeClass(bkup);
			o.replaceWith(orig);
			o=orig;
		}
		//look for translation
		var logic=$.map(lids,function(l){return F[1].MUI.auto[l];});
		F.assert(logic,subj+"has no auto-translation logic in ["+lid+']');
		//replace with translation
		var oo=o.clone(true).addClass(bkup),txt=F[1].MUI.auto_tr$(o.text(),logic,lid,subj),cls=o.attr("class").replace(/[^\s]+/,"tr:"+lid+":"+tid);
		o.html(txt).removeAttr("id").attr("class",cls).append(oo).lang(lid);
	},
	auto_tr$:function(txt,logic,lid,subj){
		$.each(logic,function(i,l){
			if("undefined"==typeof(l.length)){
			}else{
				F.assert(l.length==2,subj+"has invalid auto-translation logic for ["+lid+"]");
				txt=txt.replace(l[0],l[1]);
			}
		});
		return txt;
	}
};
// automatic translations
F[1].MUI.auto={
"zh-Hans:auto.y":[
	[/\b(?:(\d\d)|\u2019)(\d\d)\b/g,function(y,y1,y2){return y1+y2+'年';}],
	[/\u2013/g,'～']
],
"zh-Hant:auto.y":[
	[/\b(?:(\d)(\d)|\u2019)(\d)(\d)\b/g,function(y,y1,y2,y3,y4){
		var tr=$.map([y1,y2,y3,y4],function(d){return "〇一二三四五六七八九".charAt(d);});
		tr.push('年');
		return tr.join('');
	}],
	[/\u2013/g,'～']
],
"zh-Hans:auto.m":[
	[/\bJan(\.|(uary)?\b)/,"1月"],
	[/\bFeb(\.|(ruary)?\b)/,"2月"],
	[/\bMar(\.|(ch)?\b)/,"3月"],
	[/\bApr(\.|(il)?\b)/,"4月"],
	[/\bMay\b/,"5月"],
	[/\bJun(\.|e?\b)/,"6月"],
	[/\bJul(\.|y?\b)/,"7月"],
	[/\bAug(\.|(ust)?\b)/,"8月"],
	[/\bSep((t\b)?\.|(tember)?\b)/,"9月"],
	[/\bOct(\.|(ober)?\b)/,"10月"],
	[/\bNov(\.|(ember)?\b)/,"11月"],
	[/\bDec(\.|(ember)?\b)/,"12月"],
	[/\u2013/g,'～']
],
"zh-Hant:auto.m":[
	[/\bJan(\.|(uary)?\b)/,"一月"],
	[/\bFeb(\.|(ruary)?\b)/,"二月"],
	[/\bMar(\.|(ch)?\b)/,"三月"],
	[/\bApr(\.|(il)?\b)/,"四月"],
	[/\bMay\b/,"五月"],
	[/\bJun(\.|e?\b)/,"六月"],
	[/\bJul(\.|y?\b)/,"七月"],
	[/\bAug(\.|(ust)?\b)/,"八月"],
	[/\bSep((t\b)?\.|(tember)?\b)/,"九月"],
	[/\bOct(\.|(ober)?\b)/,"十月"],
	[/\bNov(\.|(ember)?\b)/,"十一月"],
	[/\bDec(\.|(ember)?\b)/,"十二月"],
	[/\u2013/g,'～']
],
"zh-Hans:auto.d":[
	[/\b(\d?\d)(st|nd|rd)?\b/g,function(d,d1){return d1+'日';}],
	[/\u2013/g,'～']
],
"zh-Hant:auto.d":[
	[/\b(\d?\d)(st|nd|rd)?\b/g,function(d,d1){
		var n=d1%10,m=(d1-n)/10,src="#一二三四五六七八九",tr=[];
		if(m>1)tr.push(src.charAt(m));
		if(m>0)tr.push('十');
		if(n>0)tr.push(src.charAt(n));
		tr.push('日');
		return tr.join('');
	}],
	[/\u2013/g,'～']
],
"zh:auto.s":[
	[/\b[Ss]pring\b/,"春季"],
	[/\b[Ss]ummer\b/,"夏季"],
	[/\b([Aa]utumn|[Ff]all)\b/,"秋季"],
	[/\b[Ww]inter\b/,"冬季"]
]
};

/*< page init >*/
F[1].online={
	"im-aim":{
		title:"AIM\u2122",
		"short":"AIM",
		uri:"aim:GoIM?screenname=flyingoe",
		icon:"http://api.oscar.aol.com/presence/icon?k=fl1iitT2NLnbwv8e&t=flyingoe"
	},
	"im-gtalk":{//http://www.google.com/talk/service/badge/New
		title:"Google\u2122 Talk",
		"short":"gTalk",
		uri:"xmpp:"+F.Base64.dec("Zmx5aW5nLm9lQGdtYWlsLmNvbQ=="),
		icon:"http://www.google.com/talk/service/badge/Show?tk=z01q6amlqo9frmfut3c1cpfmo9eec8gebqsjngvv6ebj0gj417pg39jg1ac6mnvtbqef186728peau78gneh31478vjtf4h8e3r0c8k7o5dmljpegmobsdkh3ijhncmqkmbf5v0fk7u2mlf1sn2mg9jicj7aedopujlvotog2&w=9&h=9",
		appendix:$("<img>").attr({id:"im-gtalk-chat",src:"http://www.google.com/talk/service/resources/chaticon.gif",alt:""})
	},
	"im-icq":{
		title:"ICQ\xAE",
		"short":"ICQ",
		uri:"http://wwp.icq.com/people/cmd.php?uin=18681382&action=message",
		mime:"application/x-icq",
		icon:"http://wwp.icq.com/scripts/online.dll?icq=18681382&img=5"
	},
	"im-msn":{//>>	http://settings.messenger.live.com/applications/CreateHtml.aspx
		title:"Windows Live\u2122 Messenger",
		"short":"MSN",
		//uri:"msnim:chat?contact="+F.Base64.dec("d3VfeWluZ2h1aUBob3RtYWlsLmNvbQ=="),
		uri:"http://settings.messenger.live.com/Conversation/IMMe.aspx?invitee=876f885e1ab8032d@apps.messenger.live.com",
		icon:"http://messenger.services.live.com/users/876f885e1ab8032d@apps.messenger.live.com/presenceimage"
	},
	"im-qq":{
		title:"腾讯QQ",
		"short":"QQ",
		uri:"tencent://message?Uin=39732377&Site="+location.host,
		icon:"http://wpa.qq.com/pa?p=1:39732377:4"
	},
	"im-skype":{
		title:"Skype\u2122",
		"short":"Skype",
		uri:"skype:flying_oe?chat",
		icon:"http://mystatus.skype.com/smallicon/flying_oe"
	},
	"im-ym":{
		title:"Yahoo!\xAE Messenger",
		"short":"YIM",
		uri:"ymsgr:SendIM?wu_yinghui",
		icon:"http://opi.yahoo.com/online?u=wu_yinghui&m=g&t=0"
	},
	"im-facebook":{
		title:"Facebook",
		"short":"Facebook",
		uri:"http://www.facebook.com/flying.oe",
		icon:"http://www.facebook.com/badge/752105029.1606.1883568497.png"
	},
	"im-linkedin":{
		title:"LinkedIn\xAE",
		"short":"LinkedIn",
		uri:"http://www.linkedin.com/in/freddiewu",
		icon:"http://www.linkedin.com/img/webpromo/btn_in_20x15.gif"
	},
	"im-kaixin001":{
		title:"开心网",
		"short":"Kaixin001",
		uri:"http://www.kaixin001.com/home/?uid=39474428",
		icon:$("link[rel='home']").attr("href")+"/pix/logo/kaixin001.gif"
	},
	"im-picasa":{
		title:"Picasa Web Albums",
		"short":"Picasa",
		uri:"http://picasaweb.google.com/flying.oe?feat=directlink",
		icon:$("link[rel='home']").attr("href")+"/pix/logo/picasa.gif"
	},
	"im-flickr":{
		title:"Flickr\xAE",
		"short":"Flickr",
		uri:"http://www.flickr.com/photos/9489671@N02/",
		icon:$("link[rel='home']").attr("href")+"/pix/logo/flickr.png"
	}
};
F[1].Online=function(base,intv,cache){
	if(!cache)cache={};
	var o;
	for(o=$(base).children("ul");o.length<=0;$(base).append(o=$("<ul>")));
	$.each(F[1].online,function(id,cfg){
		if(cache[id])cache[id].unbind();	//discard the previous attempt
		var a=$("<a>").attr({href:cfg.uri,title:cfg.title,target:"_blank"});
		if(cfg.mime)a.attr({type:cfg.mime});
		var li=$("<li>").append(a.append(cfg.appendix||""));
		var icon=cfg.icon+((/\/.*\?/.test(cfg.icon))?'&':'?')+new Date().getTime();	//force refresh
		cache[id]=$("<img>").attr({id:id,src:icon,alt:'['+cfg["short"]+']'})
		.load(function(){
			$('#'+id+"_li").remove();	//update with latest status
			a.prepend(this);
			o.append(li.attr({id:id+"_li"}));
		})
		.error(function(){
			if($('#'+id+"_li").length>0)return;	//only update if not already shown
			a.prepend(this.alt);
			o.append(li.attr({id:id+"_li"}));
		});
	});
	return setTimeout(function(){F[1].Online(base,intv,cache);},intv);
};

/*=============*/
/*< page init >*/
$(function(){
	//work around browser bugs
	F[1].Quirks.XHTML_1_0();
	F[1].Quirks.MS_IE();
	F[1].Quirks.IE7_js();
	F[1].Quirks.WebKit();
	//init page
	F[1].Enc.email();
	F[1].MUI.init();
	//FX
	$("#yui-main table.dict").each(function(){F.FX.table_cross_hover(this,"hover","vhover");});
	setTimeout(function(){F[1].Online("#online-im",1.2*60*1000);},1000);
});