/**
 * @see 首页js
 * @author weis
 */
$(document).ready(function() {
	topMessageAjax();//更新头部信息

	// 广告位切换
	 var len  = $("#idNum > li").length;
	 var index = 0;
	 showImg(index);
	 var flag = true;
	 $("#idNum li").mouseover(function(){
		index  =   $("#idNum li").index(this);
		showImg(index);
	});	
	 //滑入 停止动画，滑出开始动画.
	 $('#idTransformView').hover(function(){
			  if(MyTime){
				 clearInterval(MyTime);
			  }
	 },function(){
			  MyTime = setInterval(function(){
			    showImg(index)
				index++;
				if(index==len){index=0;}
			  } , 5000);
	 });
	 //自动开始
	 var MyTime = setInterval(function(){
	 	if(flag){
	 		showImg(1);
	 		flag = false;
	 	}else{
	 		showImg(index)
	 	}
		index++;
		if(index==len){index=0;}
	 } , 5000);
	 
	// 衣服匹配输入衣服基因号弹出框
	$("#MatchWindow").dialog({
		closeOnEscape : true,
		bgiframe : true,
		autoOpen : false,
		modal : false,
		// position: 'center',
		draggable : true,
		buttons : {
			"取消" : function() {
				$('#MatchWindow').dialog("close");
			},
			"确定" : function() {
				checkClothID();
			}

		},
		width : 300
	});
	
	// 设为主页
	$("#homePage").bind("click", function() {
		SetHomePage();
	});
	
	// 切换每日帮助
	var helpItem = new Array();
	helpItem[0] = "消费者注册成为服装基因会员，有什么用？,http://html.e1ht.com/help/126.html";
	helpItem[1] = "登录密码和身份确认码有什么区别？,http://html.e1ht.com/help/148.html";
	helpItem[2] = "如何使用逛街地图寻找店铺？,http://html.e1ht.com/help/38.html";
	helpItem[3] = "如何搜索服装？,http://html.e1ht.com/help/44.html";
	helpItem[4] = "什么是推荐搭配？,http://html.e1ht.com/help/46.html";
	helpItem[5] = "什么是服装匹配？有什么用？,http://html.e1ht.com/help/61.html";
	helpItem[6] = "什么是服装预订？有什么用？,http://html.e1ht.com/help/67.html";
	helpItem[7] = "什么是e币？,http://html.e1ht.com/help/212.html";
	helpItem[8] = "什么是资讯订阅？有什么用？,http://html.e1ht.com/help/83.html";
	helpItem[9] = "什么是代金券？,http://html.e1ht.com/help/679.html";
	helpItem[10] = "注册成为服装基因会员对服装店有什么用处？,http://html.e1ht.com/help/563.html";
	helpItem[11] = "什么是新货测试？有什么用？,http://html.e1ht.com/help/664.html";
	helpItem[12] = "什么是预订交易？,http://html.e1ht.com/help/658.html";
	helpItem[13] = "什么是还价管理？有什么用？,http://html.e1ht.com/help/79.html";
	helpItem[14] = "如何创建店铺？,http://html.e1ht.com/help/586.html";
	helpItem[15] = "什么是积分？,http://html.e1ht.com/help/213.html";
	helpItem[16] = "如何上传店铺照片？,http://html.e1ht.com/help/596.html";
	helpItem[17] = "开通会员吸纳服务有什么用？,http://html.e1ht.com/help/647.html";
	helpItem[18] = "哪些情况需要知道消费者的基因号和身份确认码？,http://html.e1ht.com/help/655.html";
	helpItem[19] = "什么是广告竞拍？,http://html.e1ht.com/help/344.html";
	var helpCount = parseInt(Math.random()*20)
	var currHelp = helpItem[helpCount];
	$("#currHelp").html(currHelp.split(",")[0]);
	$("#currHelp").attr("href",currHelp.split(",")[1]);
	$("#helpR").click(function (){
		helpCount = helpCount-1;
		if(helpCount<0){
			helpCount=19;
		}
		currHelp = helpItem[helpCount];
		$("#currHelp").html(currHelp.split(",")[0]);
		$("#currHelp").attr("href",currHelp.split(",")[1]);
	});
	$("#helpL").click(function (){
		helpCount = helpCount+1;
		if(helpCount>19){
			helpCount=0;
		}
		currHelp = helpItem[helpCount];
		$("#currHelp").html(currHelp.split(",")[0]);
		$("#currHelp").attr("href",currHelp.split(",")[1]);
	});
	// 搜衣服搜店
	$("#searchShop").mouseover(function (){
		$("#searchClothes").attr("class","fzdnaindexcer230301a");
		$(this).attr("class","fzdnaindexcer230301hover");
		$("#searchClothesDiv").hide();
		$("#searchShopDiv").show();
	});
	$("#searchClothes").mouseover(function (){
		$("#searchShop").attr("class","fzdnaindexcer230301a");
		$(this).attr("class","fzdnaindexcer230301hover");
		$("#searchShopDiv").hide();
		$("#searchClothesDiv").show();
	});
	// 店探密报图片滚动
	$("#change_infoPic li").eq(0).find("a").attr("class","fzdnaindexcer012101hover");
    $("#change_infoPic li").mouseover(function(){
    		$("#change_infoPic li").find("a").attr("class","fzdnaindexcer012101a");
    		$(this).find("a").attr("class","fzdnaindexcer012101hover");
    		$("#chanagePictrue img").attr("src",$(this).find("img").attr("src"));
    		$("#currTitle").html($.trim($(this).find("#title").val())).attr("title",$.trim($(this).find("#title").val()));
    		$("#currArticleInfo").html($.trim($(this).find("#articleInfo").val())).attr("title",$.trim($(this).find("#articleInfo").val()));
    		$("#currArticleInfo").attr("href",$(this).find("#url").val());
    		$("#currLink").attr("href",$(this).find("#url").val());
    		$("#currTitle").attr("href",$(this).find("#url").val());
    });
    	$.ajax({
			url : 'index/loginReg.jsp',
			type : 'get',
			dataType : "html",
			success : function(text) {
				$("#loginReg").html(text);
			}
		});
		$.ajax ({
			url : "index/userInfo.jsp",
			type : "get",
			dataType : "html",
			cache:false,
			success : function(html) {
				var infoItem = $("#userInfoDiv");
				infoItem.after(html);
				infoItem.remove();
			}
		});
    
});

// 首页上衣服匹配弹出框触发
function toMatch() {
	$("#matchClothidError").html("&nbsp;");
	$('#MatchWindow').dialog("open");
}
// 验证服装基因号
function checkClothID() {
	var mclothid = $("#matchClothid").val();
	if (mclothid == "") {
		$("#matchClothidError").html("请输入服装基因号！");
		return;
	}
	var patter = /^(0|[1-9][0-9]*)$/;
	if (!patter.test(mclothid)) {
		$("#matchClothidError").html("服装基因号只能为数字！");
		return;
	}
	// 验证衣服基因号
	$.ajax({
		url : 'isExitClothes.do?clothescode=' + mclothid,
		type : 'get',
		cache : 'false',
		dataType : "text",
		success : function(text) {
			if (text == "N") {
				$("#matchClothidError").html("此服装基因号不存在！");
				return false;
			} else {
				window.open("clothes/" + mclothid, "_blank");
				$('#MatchWindow').dialog("close");
				return true;
			}
		}
	});
}
// 广告位：通过控制top ，来显示不通的幻灯片
function showImg(i){
		$("#idSlider").stop(true,false).animate({top: -180*i},800);
		 $("#idNum li").eq(i).addClass("on").siblings().removeClass("on");
}

// 更新头部信息
function topMessageAjax(){
	$.ajax ({
		dataType : "text",
		type : "get",
		url : $("#path").val()+"/common/top/topMessage.jsp",
		cache:false,
		success : function(html) {
			$("#loginMessage").html($(html).find("#toLoginMessage").html());
			jQuery.getScript("http://"+$("#e1htUrl").val()+"/setRemoteSid.do?sid="+$(html).find("#sidHide").val());
		}
	});	
}

