//百度统计
	var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
	document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F2557d710fed7cc79cfee7d94e97a6363' type='text/javascript'%3E%3C/script%3E"));

$(function(){
	//得到用户名进行填充
	var arrStr = document.cookie.split(";");
	for(var i = 0;i < arrStr.length;i ++){
		var temp = arrStr[i].split("=");
		if(temp[0] == "com.clou.dooliu.content"){ 
			var name = unescape(temp[1]);
			if(name.indexOf("-") != -1){
				var names = name.split("-");
				$("input[name='account']").val(names[0]+"@" + names[1]);
			}else{
				$("input[name='account']").val(name);
			}
		}
	}
	$("#index").hover(function(){
		$(this).attr("src","/images/index-1.jpg");
	},function(){
		$(this).attr("src","/images/index.jpg");
	});
	
	$("#download").hover(function(){
		$(this).attr("src","/images/download-1.jpg");
	},function(){
		$(this).attr("src","/images/download.jpg");
	});
	
	$("#ranking").hover(function(){
		$(this).attr("src","/images/ranking-1.jpg");
	},function(){
		$(this).attr("src","/images/ranking.jpg");
	});
	
	$("#search").hover(function(){
		$(this).attr("src","/images/search-1.jpg");
	},function(){
		$(this).attr("src","/images/search.jpg");
	});

	$("#topaccount").focus(function(){
		var con = $(this);
		var v = con.val();
		if(v === '手机/邮箱'){
			$(this).val("");
		}
		$("#toperror").hide();
	});
	$("#toppassword").focus(function(){
		var con = $(this);
		var v = con.val();
		if(v === '密码'){
			$(this).val("");
		}
		$("#toperror").hide();
	});
	$("#topaccount").keydown(function(){
		$("#toperror").hide();
	});
	$("#toppassword").keydown(function(){
		$("#toperror").hide();
	});
	$("#passwordtext").focus(function(){
		$("#toperror").css("display","none");
		$(this).css("display","none");
		$("#toppassword").css("display","").focus();
	});
	$("#topaccount").blur(function(){
		var con = $(this);
		var v = con.val();
		if(v === '' || v === null){
			con.val('手机/邮箱');
		}
	});
	$("#toppassword").blur(function(){
		var con = $(this);
		var v = con.val();
		if(v === '' || v === null){
			$(this).css("display","none");
			$("#passwordtext").css("display","");
			$("#passwordtext").val('密码');
		}
	});
	$("#loginform").submit(function (){
		var ta=$("#topaccount").val();
		var tp=$("#toppassword").val();
		if(ta === ''||ta === null||ta==="手机/邮箱"){
			$("#toperror").css("display","");
			$("#toperror").html("请输入账户");
			return false;
		}
		else if(tp === ''||tp === null||tp==="密码"){
			$("#toperror").css("display","");
			$("#toperror").html("请输入密码");
			return false;
		}
		else{
			$.ajax({url:"loginAction", type:"POST", dataType:"json", data:$("#loginform").serialize(), success:function (data) {
				if(data=='success'){
					location.href="userAction";
				}else{
					$("#toperror").html(data);
					$("#toperror").css("display","");
				}
			}});
			return false;
		 }
	});
	//控制广告滚动
	(function(){
		var curr = 0;
		$("#jsNav .trigger").each(function(i){
			$(this).click(function(){
				curr = i;
				$("#js img").eq(i).fadeIn("slow").siblings("img").hide();
				$(this).siblings(".trigger").removeClass("imgSelected").end().addClass("imgSelected");
				return false;
			});
		});
		
		var pg = function(flag){
			if (flag) {
				if (curr == 0) {
					todo = 2;
				} else {
					todo = (curr - 1) % 4;
				}
			} else {
				todo = (curr + 1) % 4;
			}
			$("#jsNav .trigger").eq(todo).click();
		};
		

		$("#prev").click(function(){
			pg(true);
			return false;
		});
		

		$("#next").click(function(){
			pg(false);
			return false;
		});

		var timer = setInterval(function(){
			todo = (curr + 1) % 4;
			$("#jsNav .trigger").eq(todo).click();
		},60000);
		
		$("#jsNav a").hover(function(){
				clearInterval(timer);
			},
			function(){
				timer = setInterval(function(){
					todo = (curr + 1) % 4;
					$("#jsNav .trigger").eq(todo).click();
				},60000);			
			}
		);
	});
});
