﻿$(function(){
//jQuey 
externallinks;
//会员状态
var userName = GetCookie("usernameJS");
var userKey = GetCookie("userKeyJS");
var userFromType = GetCookie("userFromType");
if (userName) {
	$(".loginStat .m1").html('<strong class="userName">'+ userName +'</strong> | <a class="a_color" href="/members/" rel="blank">会员中心</a>&nbsp; <a class="a_color" href="/members/logout.aspx">退出</a>');
} 

//卡片
if ($(".win_head:has(ul.card)")) {
	$(".win_head:has(ul.card)").each(function(){
		$(this).siblings(".win_body").children(".ibody").hide();
		$(this).siblings(".win_body").children("."+$(this).find("li.on>a").attr("rel")).show();
	});
}

if ($(".win_head ul.card a[rel]")) {
$(".win_head ul.card a[rel]").mouseover(function(){
	$(this).parent().attr("class","on");
	$(this).parent().siblings("li").attr("class","");
	var bodyN = "."+ $(this).attr("rel"); //alert(bodyN);
	var win_body = $(this).parents(".win_head").siblings(".win_body");
	win_body.children(".ibody").hide();
	win_body.children(bodyN).show();//fadeIn("normal",function(){});
	return false;
});
$(".win_head ul.card a[rel][rev]").unbind().click(function(){
	$(this).parent().attr("class","on");
	$(this).parent().siblings("li").attr("class","");
	var bodyN = "."+ $(this).attr("rel"); //alert(bodyN);
	var win_body = $(this).parents(".win_head").siblings(".win_body");
	win_body.children(".ibody").hide();
	win_body.children(bodyN).fadeIn("normal",function(){});
	return false;
});
}

$(".showInDialog").each(function(){
	$(this).click(function(){$('<div style="margin:0;"><div style="width:516px; height:400px; overflow:auto; overflow-x:hidden; overflow-y:auto;"><iframe class="dialogiframe" frameborder="0" marginheight="0" marginwidth="0" width="516" scrolling="auto" onload="javascript:this.height=this.contentWindow.document.body.scrollHeight;" src="'+ $(this).attr("href") +'"></iframe></div></div>').dialog({bgiframe:true, 
	modal:true, title:"详情", height:'auto', width:520, height:470,
	buttons:{"关闭": function(){$(this).dialog('close');}},
	open: function(){ $(this).dialog('moveToTop');},
	close: function(){ $(this).dialog('destroy');}
	});
	return false;
	});
});


//表格鼠标效果
$("table.tableTrOn tr").not(".head").mouseover(function(){
	$(this).css({'background':'#F7FFE8'});
}).mouseout(function(){
	$(this).css({'background':'none'});
});


//Cards Digg
$(".diggs>.diggIt>.diggCard").click(function(){
	doVote('card',Number($(this).attr("rel")),1);
	$(this).siblings(".number").html( Number($(this).siblings(".number").html())+1 );
	$(this).unbind('click').click(function(){alert('只能投票一次');});
	return false;
});
function doVote(kind,ID,N){ //N = 1 / -1
	var cents = N;
	if (cents>0) {cents=1;} else if (cents<0) {cents=-1;} else { return; }
	$.get("/include/ajax.aspx?act=vote&kind="+ kind +"&ID="+ ID +"&cents="+ cents +"",function(data){
		//alert(data);
	});
	return false;
}



//栏目收起
$(".win_head .close").each(function(){
	$(this).parents(".win_head").toggle(function(){
		$(this).siblings(".win_body").slideUp();
		$(this).find(".close").css("background","url(../images/icn_doShow.gif) no-repeat center");
	},function(){
		$(this).siblings(".win_body").slideDown();
		$(this).find(".close").css("background","url(../images/icn_doHide.gif) no-repeat center");
	});
});
$(".win_head .close2").each(function(){
	$(this).parents(".win_head").toggle(function(){
		$(this).siblings(".win_body").slideDown();
		$(this).find(".close").css("background","url(../images/icn_doHide.gif) no-repeat center");
	},function(){
		$(this).siblings(".win_body").slideUp();
		$(this).find(".close").css("background","url(../images/icn_doShow.gif) no-repeat center");
	});
});


//目录点击展开#category
function showHideMenu(jObj) { //jObj:list1
	var catStatus = jObj.children("a.aNext").children("div").attr("class");
	if (catStatus=="catNextOpen"){
		jObj.children("a.aNext").children("div").attr("class","catNextClose");
		jObj.css("background-color","#F5F5F5");
		jObj.siblings(".list2").slideUp("fast");
	} else {
		jObj.children("a.aNext").children("div").attr("class","catNextOpen");
		jObj.css("background-color","#FBFFEA");
		jObj.siblings(".list2").slideDown("fast");
	}
}
$(".list1").each(function(){
	if ($(this).find("a.aNext").length>0) {
		$(this).click(function(){
			showHideMenu($(this));
			return false;
		});
	}
});
$(".list2 a").click(function(){
	$(this).parent(".list2").addClass("listOn");
	$(this).parent(".list2").siblings(".list2").removeClass("listOn");
});
//默认关闭的子目录[-]
$(".catNextClose").each(function(){
	$(this).parents(".list1").siblings(".list2").hide();
	$(this).parents(".list1").css("background-color","#F5F5F5");
});
$(".catNextOpen").each(function(){
	$(this).parents(".list1").css("background-color","#FBFFEA");
});


//商品new hot
if ($(".gList").length>0) {
	$(".gList .goods").mouseover(function(){
		$(this).addClass("on");
		$(this).css("position","relative");
		if ($(this).find(".new").length>0) {
			$(this).find(".newhot").append("<img src='/images/new.gif' alt='' />");
		}
		if ($(this).find(".hot").length>0) {
			$(this).find(".newhot").append("<img src='/images/hot.gif' alt='' />");
		}
	}).mouseout(function(){
		$(this).removeClass("on");
		$(this).css("position","static");
		$(this).find(".newhot").empty();
	});
}

$(".sQ").each(function(){
	if ($(this).val()=='搜索商家、特价商品，如：女装') {
		$(this).addClass("sblur").removeClass("sfoc");
	} else {
		$(this).addClass("sfoc").removeClass("sblur");
	}
});

$(".sQ").focus(function(){
	if ($(this).val()=='搜索商家、特价商品，如：女装') {
		$(this).val("");
		$(this).addClass("sfoc").removeClass("sblur");
	}	
}).blur(function(){
	if ($(this).val()=='') {
		$(this).val("搜索商家、特价商品，如：女装");
		$(this).addClass("sblur").removeClass("sfoc");
	}	
});

if (userFromType=="taobao" && $(".mainLeftLoginTB").length>0 && userName) {
	$(".mainLeftLoginHeadTB").html('淘宝用户 ('+ userName +')');
	$.get("/members/include/memberMenu.htm",function(data){
		if (data) $(".mainLeftLoginTB").html(data);
	});
	$(".left5F").hide();
} else if ($(".mainLeftLogin").length>0 && userName) {
	$(".mainLeftLoginHead").html('我的最Buy ('+ userName +')');
	$.get("/members/include/memberMenu.htm",function(data){
		if (data) $(".mainLeftLogin").html(data);
	});
	$(".leftTB").hide();
	$(".left5F").css({"margin-top":0});
}

//缩放图片 最好放在最后执行
function doImgResize(){
	$(".imgResize").each(function(i){
		var imgObj = $(this).find("img").get(0);
		if (!imgObj || imgObj.length==0) return;
		var width = $(this).css("width").replace("px","");
		var height = $(this).css("height").replace("px","");
		if (!width && $(imgObj).attr("title")) {
			var midNum = $(imgObj).attr("title").indexOf("*");
			width = $(imgObj).attr("title").substr(0,midNum); 
			height = $(imgObj).attr("title").substr(midNum+1);
		}
		if(imgObj.complete || imgObj.readyState =="complete") { DrawImage(imgObj,width,height);}
		else {
			$(imgObj).css({"width":width, "height":"auto"});
		}
	});
	$(".imgResize2").each(function(i){
		var imgObj = $(this).find("img").get(0);
		if (!imgObj || imgObj.length==0) return;
		var width = $(this).css("width").replace("px","");
		var height = $(this).css("height").replace("px","");
		if (!width && $(imgObj).attr("title")) {
			var midNum = $(imgObj).attr("title").indexOf("*");
			width = $(imgObj).attr("title").substr(0,midNum); 
			height = $(imgObj).attr("title").substr(midNum+1);
		}
		if(imgObj.complete || imgObj.readyState =="complete") { DrawImage2(imgObj,width,height);}
		else {
			$(imgObj).css({"width":width, "height":"auto"});
		}
	});
}
setTimeout(doImgResize, 1800);

$(".ImgFloatR").each(function(){
	$(this).find("img").each(function(i){
		if (i==0) {
			var obj2 = $(this).clone();
			obj2.prependTo($(this).parents(".ImgFloatR"));
			objDom = obj2.get(0);
			$(this).remove();
			obj2.css({"float":"right", "border":"#CCC solid 2px", "margin":"4px"});
			if(objDom.complete || objDom.readyState =="complete") { DrawImage(objDom,120,60);}
			else {
				$(objDom).css({"width":"auto", "height":60});
				//$(objDom).parents(".ImgFloatR").css({"height":96});
				objDom.onreadystatechange = function(){ 
					if(this.complete || this.readyState =="complete") { DrawImage(this,120,60); }
				}
			}
		} else {$(this).hide();}
	});
	
});


//jQuey End
});

