// JavaScript Document
//我看过的产品viewed ul



function writeViewedProduct(path,id){//把看过的产品信息写入cookie
	var path_id=path+"^"+id;
	var isHave=false;
	var productCookies=$.cookie('viewedProduct')!=null ? $.cookie('viewedProduct').split(',') : []
	if (productCookies.length == 0) productCookies.push(path_id);
	//检查是否存在重复的，不存在就加入，存在就不加入
	for(i=0;i<productCookies.length;i++){
		if (productCookies[i]==path_id) isHave=true;
		}
	//截取前10个
	if (productCookies.length>9 && !isHave){
		productCookies.reverse();
		productCookies=productCookies.slice(0,9)
		productCookies.reverse();
		productCookies.push(path_id)
		} 
	else if(!isHave){
		productCookies.push(path_id)
		}
	else{
		//console.log("not push")
		}

	//把数组序列化后放入cookie中
	$.cookie('viewedProduct', productCookies.toString(), { expires: 3650, path: '/'});
	}
	
	
	
function readViewdProduct(){//读出看过的产品信息
	var productCookies=$.cookie('viewedProduct')!=null ? $.cookie('viewedProduct').split(',') : []
	var $viewedList=$("div.viewed > ul");
	productCookies=productCookies.reverse()
	//<li><a href="products_series_3.html" title="产品名称"><img src="/cn/resource/images/technology_intro_relatedproduct_1.jpg" alt="产品名称" border="0" /></a></li>
	for (i=0;i<productCookies.length;i++){
		var $li=$("<li><a><img border=\"0\" /></a></li>")
		var product=productCookies[i].split('^')
		$li.find("a").attr({"href":product[0]+product[1]+".html","title":product[1]})
		$li.find("img").attr({"src":"/cn/resource/images/product/"+product[1]+"/s.jpg","alt":product[1]})
		$viewedList.append($li)
		}
	}

$(function(){
		   
		   //收藏
		   $("a.mycollection").click(function(){
											  var $this=$(this);
											  var offsetleft=$this.offset().left;
											  var offsettop=$this.offset().top+$this.innerHeight();
											  var productcode=$this.attr("productcode");
											  $.msgbox.confirmbox("收藏产品","收藏产品中...",offsetleft,offsettop);
											  $.post(
													 "/app/addCollection.do",
													 {productcode:productcode},
													 function(data){
													  	data=jQuery.trim(data);
														 if (data== "1"){
															 $.msgbox.confirmbox("收藏产品","该产品已收藏！",offsetleft,offsettop);
															 }
														else if (data== "2"){
															 $.msgbox.confirmbox("收藏产品","请先登录！",offsetleft,offsettop);
															 }
														 else{
															 $.msgbox.confirmbox("收藏产品","产品收藏成功！",offsetleft,offsettop);
															 }
														 $.msgbox.closemsgbox(1000);
														 }
													 )
											  return false
											  })
		   
		   })

