var goodsPageInit = function(){
	seckillInit();
	//规格初始化
	var $specUl = $("div[name='goods_spec']").find("ul");
	specUlNum   = $specUl.length;
	if(specUlNum>1){
		$specUl.each(function(){
			$(this).find("li:eq(0)>a").click();
		});
	}else{
		$("div[name='goods_spec']").find("li>a").each(function(){$(this).click();});
		$specUl.find("li:eq(0)>a").click();
	};
	OW.tabSwitch({tabbar:$("#goods_tab"),container:$("#goods_tab_content"),current:1});
	//处理预订进度条
	var $bookTimeSection = $("[name='book_time_section']");
	if($bookTimeSection.find("li").length==2){
		$bookTimeSection.find("li").css("width","50%");
	};
	if(!$("#tags").find("a").length>0){$("#tags").remove();};
	if(!$("#om_related_content").find("li").length>0){$("#om_related_content").remove();};
	if(!$("#om_related_goods").find("li").length>0){$("#om_related_goods").remove();};
	if(!$("#om_latestview_goods").find("li").length>0){$("#om_latestview_goods").remove();};
	$("#om_latestview_goods").find("li").each(function(i){
		var k = i+1 ;
		if(k%3==0){
			$(this).addClass("li3");
		};
	});
	var $promotion = $("#goods_promotion");
	if($promotion.find("div[name='prom_item']").length==1 && $promotion.find("a.om-goods-coupon-list-item").length==0){
		$promotion.remove();
	};
	//积分价格
	$(".price").each(function(){
		var price = OW.parseMoney($(this).find(".money > b").html());
		if(!price>0){
			$(this).find(".point > i").hide();
		};
	});
	//**视频
	$("#video_url").click(function(){
		var webScreenWidth = OW.webScreenWidth(),
		webScreenHeight    = OW.webScreenHeight();
		if(webScreenHeight>webScreenWidth){
			var videoSize  = webScreenWidth,
			videoMarginTop = (webScreenHeight - webScreenWidth)/2;
			$("#video_inner").height(videoSize).width(videoSize).css("margin-top",videoMarginTop);
		}else{
			var videoSize   = webScreenHeight,
			videoMarginLeft = (webScreenWidth - webScreenHeight)/2;
			$("#video_inner").height(videoSize).width(videoSize).css("margin-left",videoMarginLeft);
		};
		$("#video").show();
	});
	$("#video_close").click(function(){$("#video").hide();});
	if(OW.isPriceNeedLogin && !OW.logined){
		$("div[name='book_price_section']").hide();
		$("div[name='book_time_section']").hide();
		$(".goods-price,.suit-o-amount").hide();
		$(".goods-suit-price,.suit-amount").html('<span class="price-need-login">登录后查看价格</span>');
	};
	consultationInit();
};
var seckillInit = function(){
	var $time = $("#seckill_time"),
	starttime = $time.attr("seckill_starttime"),
	endtime   = $time.attr("seckill_endtime");
	if(OW.dateDiff("s",starttime,OW.systime)<1){
		$time.html('预计 '+starttime+' 开始秒杀');
	}else{
		if(OW.dateDiff("s",endtime,OW.systime)>1){
			$time.html('秒杀活动已结束！');
		}else{
			$time.parent().prepend("距离结束：");
			OW.remainTimeOutTip($time,OW.systime,endtime,"<em>{h}</em>:<em>{m}</em>:<em>{s}</em>");
		};
	};
};
var consultationInit = function(){
	var $form = $("#consultation_post_form"),
	$vc = $("span[name='verifycode']"),
	$vv = $("input[name='verifycode_value']"),
	$submit   = $("button[name='btn_consult_submit']"),
	$author   = $form.find("input[name='consult_author']").val(OW.nickname),
	$authorT  = $form.find("span[name='t_consult_author']"),
	$content  = $form.find("textarea[name='consult_content']"),
	$contentT = $form.find("span[name='t_consult_content']");
	$author.val(OW.cookie.getCookie("nickname"));
	$content.blur(function(){
		$(this).val(OW.left(OW.trim($(this).val()),250));
	});
	OW.verifyCodeValueBlur($vv);
	OW.verifyCodeValueFocus($vv,$vc);
	OW.enterClick(function(){
		$submit.click();
	});
	$submit.click(function(){
		var valid = true,
		author    = OW.trim($author.val()),
		content   = OW.trim($content.val()),
		cstType   = OW.int($form.find("input[name='consult_type']:checked").val()),
		vn        = OW.trim($vc.find("input[name='verifycode_name']").val()),
		vv        = OW.trim($vv.val());
		if(OW.isNull(content)){
			valid = false;
			$content.addClass("textarea-err").focus();
			$contentT.addClass("t-err").html("请填写咨询内容");
		}else{
			$content.removeClass("textarea-err");
			$contentT.removeClass("t-err").html("");
		};
		if(valid){
			if(OW.isNull(author)){
				valid = false;
				$author.addClass("text-err").focus();
				$authorT.addClass("t-err").html("请填写您的称呼");
			}else{
				$author.removeClass("text-err");
				$authorT.removeClass("t-err").html("");
			};
		};
		if(valid){
			if(OW.isNull(vv)){
				valid = false;
				$vv.addClass("text-err").focus();
			}else{
				$vv.removeClass("text-err");
			};
		};
		$content.val(content);
		if(valid){
			var url = OW.sitePath +"ow-includes/ow.ajax.shop.asp?ctl=goods&act=consult_post",
			data    = "cst_type="+cstType+"&cst_author="+escape(author)+"&cst_content="+escape(content)+"&gid="+OW.gid+"&verifycode_name="+vn+"&verifycode_value="+vv;
			$dialog = OWDialog().posting().follow($content);
			OW.ajax({
				url:url,data:data,
				success:function(){
					$dialog.success("亲，恭喜，咨询提交成功，请等待客服回复。").timeout(2).removeClose(true);
					OW.delay(2300,function(){
						$content.val('').focus();
						$vc.html('');
						$vv.val('');
					});
				},
				failed:function(msg){
					$dialog.error('亲，很抱歉，咨询提交失败，请刷新页面再试试。',msg).timeout(4);
					$vv.val('').focus();
					OW.verifyCode({boxer:$vc});
				}
			});
		};
	});
};

