var i18n = {
	lang : [],
	init : function(lang) {
		this.lang = lang;
	},
	get : function(key) {
		if (!this.lang[key]) {
			throw 'Unkonwn lang key';
		}
		return this.lang[key];
	}
}

function button(n){ 
 	var h =(document.body.clientWidth-413)/2+"px";
 	var g = document.getElementById('g'+n).style.display=='none';
	if(!g){
		$("#g0").slideUp('fast');
		$("#g0").css('left',h);
	}else{
		$("#g0").slideDown('fast');
		$("#g0").css('left',h);
	}
}

function hoverli(n) {
	for(var i=1;i<3;i++){
		$('#tb_'+i).attr('class', 'normaltab');
		$('#tbc_0'+i).attr('class', 'undis');
	}	 
	$('#tbc_0'+n).attr('class', 'dis');
	$('#tb_'+n).attr('class', 'hovertab');
}

function about(n) {
	for ( var i=1; i<5; i++ ) {
		$('#tb_'+i).attr('class','li_about1');
		$('#tbc_0'+i).attr('class', 'undis');
	}
	$('#tbc_0'+n).attr('class', 'dis');
	$('#tb_'+n).attr('class', 'li_about2');
}

function rrr(n, len, class1, class2) {
	for(var i=1;i<len+1;i++){
		$('#tb_'+i).attr('class',class1);
		$('#tbc_0'+i).attr('class', 'undis');	
	}
	$('#tbc_0'+n).attr('class', 'dis');
	$('#tb_'+n).attr('class', class2);
}

function shareToRenren() {
	var s = screen, d = document, e = encodeURIComponent;
	if (/renren\.com/.test(d.location))
		return;
	var f = 'http://share.renren.com/share/buttonshare?link=', u = d.location, l = d.title, p = [
			e(u), '&title=', e(l) ].join('');
	function a() {
		if (!window.open( [ f, p ].join(''), 'xnshare', [
				'toolbar=0,status=0,resizable=1,width=626,height=436,left=',
				(s.width - 626) / 2, ',top=', (s.height - 436) / 2 ].join('')))
			u.href = [ f, p ].join('');
	}
	;
	if (/Firefox/.test(navigator.userAgent))
		setTimeout(a, 0);
	else
		a();
};

function shareToSinaMB() {
	(function(s, d, e, r, l, p, t, z, c) {
		var f = 'http://v.t.sina.com.cn/share/share.php?appkey=1177300682', u = z
				|| d.location, p = [ '&url=', e(u), '&title=', e(t || d.title),
				'&source=', e(r), '&sourceUrl=', e(l), '&content=',
				c || 'gb2312', '&pic=', e(p || '') ].join('');
		function a() {
			if (!window
					.open(
							[ f, p ].join(''),
							'mb',
							[
									'toolbar=0,status=0,resizable=1,width=440,height=430,left=',
									(s.width - 440) / 2, ',top=',
									(s.height - 430) / 2 ].join('')))
				u.href = [ f, p ].join('');
		}
		;
		if (/Firefox/.test(navigator.userAgent))
			setTimeout(a, 0);
		else
			a();
	})(screen, document, encodeURIComponent, '', '', '', '', '', 'utf-8');
}

function shareToDouban() {
	var d = document, e = encodeURIComponent, s1 = window.getSelection, s2 = d.getSelection, s3 = d.selection;
	var s = s1 ? s1() : s2 ? s2() : s3 ? s3.createRange().text : '', r = 'http://www.douban.com/recommend/?url='
			+ e(d.location.href)
			+ '&title='
			+ e(d.title)
			+ '&sel='
			+ e(s)
			+ '&v=1';
	var x = function() {
		if (!window
				.open(r, 'douban',
						'toolbar=0,resizable=1,scrollbars=yes,status=1,width=450,height=330'))
			location.href = r + '&r=1';
	};
	if (/Firefox/.test(navigator.userAgent)) {
		setTimeout(x, 0)
	} else {
		x()
	}
}

function shareToKaixin() {
	var openPostWindow = function(url, data, name) {
		var tempForm = document.createElement('form');
		tempForm.id = 'tempForm1';
		tempForm.method = 'post';
		tempForm.action = url;
		tempForm.target = 'kaixin001';
		var hideInput = document.createElement('input');
		hideInput.type = 'hidden';
		hideInput.name = 'rcontent';
		hideInput.value = data;
		tempForm.appendChild(hideInput);
		document.body.appendChild(tempForm);
		tempForm.submit();
		document.body.removeChild(tempForm);
	}

	var u = document.location.href;
	var t = document.title;
	var c = '' + (document.getSelection ? document.getSelection()
			: document.selection.createRange().text);
	var iframec = '';
	var url = 'http://www.kaixin001.com/repaste/bshare.php?rtitle='
			+ encodeURIComponent(t) + '&rurl=' + encodeURIComponent(u)
			+ '&from=voguemate';
	var data = encodeURIComponent(c);
	openPostWindow(url, c, '_blank');
}

function checkStaticServer(staticServer, mainServer) {
	var staticServerAvail = false;

	var decide = function() {
		$.getJSON('setting.staticServer.do', {
			avail : staticServerAvail
		});
		if (!staticServerAvail) {
			var changeToMain = function() {
				$("img[src^='" + staticServer + "']").each(
						function() {
							this.src = mainServer
									+ this.src.substring(staticServer.length);
						});
			}
			if (docmentLoaded) {
				changeToMain();
			} else {
				$(function() {
					changeToMain();
				});
			}
		}
	};

	var probe = new Image();
	var probeHandler = function() {
		staticServerAvail = true;
		clearTimeout(deadline);
		decide();
		//alert('probeHandler');
	}
	$(probe).load(probeHandler);

	setTimeout(function() {
		probe.src = staticServer + 'hello.php';
	}, 0);

	deadline = setTimeout(function() {
		decide();
		$(probe).unbind('load', probeHandler);
		//alert('deadline');
	}, 3000);

	var docmentLoaded = false;
	$(function() {
		docmentLoaded = true;
	});
}
