$(document).ready( onDocumentReady );

function onDocumentReady() {
	Origami.fastclick(document.body);
	weixinShare("绩效达人——医药销售管理移动应用", 
				"销量报表 客户拜访管理 辖区指标折扣 团队协作 培训视频",
				"http://localhost:8080/sfez",
				"http://localhost:8080/sfez/icon/geggee_logo.png");
	
	weixinInit();	
	weixinGuide();
	
	if (urlParam("splash") || !getAccount()) {
		showSplash();
	} else {
		showMenu();
		touchBind();
	}
}

function touchBind() {
	$(".div_menu_button").on("touchstart", touchStart);
	$(".div_menu_button").on("touchend", touchEnd);
}

function touchStart() {
	var el = $(this);
	var touchcolor = el.attr("touchcolor");		
	var bgcolor = el.css("background-color");
	el.attr("bgcolor", bgcolor);		
	el.css("background-color", touchcolor);
}

function touchEnd() {
	var bgcolor = $(this).attr("bgcolor");
	$(this).css("background-color", bgcolor);
}

function showMenu() {
	$("#page_menu").fadeIn();
}

function menuGo(feature) {
	location.href=feature+".html";
}

function showSplash() {
	$("#page_splash").fadeIn(500);
	if (isAgent("micromessenger")) {
		$(".div_version_text").html("请在浏览器中打开");		
	} else {
		$("#div_loading_progress").animate({width:"116px"},2000);
		setTimeout(hideSplash, 2500);
	}
}

function hideSplash() {
	if (!localStorage.getItem("login_token")) {
		goLogin();
		return;
	}
	var p0=$("#page_splash");
	var w0=innerWidth;
	var s0={left:"0", right:"0"};
	var s1={left:-w0+"px", right:w0+"px"};
	var s2={left:"0", right:"0", display:"none"};
	
	if (p0.is(":animated")) {
		p0.stop(true, true);
	}
	p0.css(s0);
	p0.animate(s1, 800, function(){ p0.css(s2); });
	showMenu();
}

function goIntro() {
	location.href="geggee_sfez_intro.pdf";
}

function goLogin() {
	location.href="login.html";
}