var hostName = 'img.bip.cn';
// 商品分类:获得一级和二级分类
function sysCategorySecond(platformId,categoryIds){
		$.getJSON('/mbs/jsonSysCategorySecond.jhtml', {
			'categoryIds' : categoryIds,
			'number' : 3,
			'platformId' : platformId
		}, function(data) {
			var sysCategory = '<div class="und_platform_sysCategory_hd"><span>商品分类</span></div>' + '<div class="und_platform_sysCategory_digital"><ul id="cate" class="und_platform_sysCategory_multiclass">';
			if (data.sign != null && data.sign == "1") {// 返回的是HTML文件
				$('#und_platform_sysCategory').append(data.data);
			} else {// 返回MAP
				$.each(data, function(id, item) {
					var evenCalss;
					var childACalss;
					var childCalss;
					var parentCalss;
					if (id % 2 == 0) {
						evenCalss = 'stair_01';
						parentCalss = 'second_01';
						childCalss = 'second_01_1';
						childACalss = 'hong';
					} else {
						evenCalss = 'stair_02';
						parentCalss = 'second_02';
						childCalss = 'second_02_1';
						childACalss = 'hui';
					}
					sysCategory = sysCategory + '<li><span class="' + evenCalss + '"><a href="/goods/' + item.cateId + '-0-0-0-0-0-0-0-0-0-0-0-1-6-1.html">' + item.cateName + '</a></span><span class="'
							+ parentCalss + '">';
					$.each(item.child, function(idChild, itemChild) {
						var temp = '<span class="' + childCalss + '"> <a id="attribute2_href" href="/goods/' + itemChild.cateId + '-0-0-0-0-0-0-0-0-0-0-0-1-6-1.html" class="' + childACalss + '">'
								+ itemChild.cateName + '</a>';
						if (idChild < (item.child.length - 1)) {
							temp = temp + '&nbsp|&nbsp';
						}
						sysCategory = sysCategory + temp + '</span>';
					});
					sysCategory = sysCategory + '</span>';
				});
				$('#und_platform_sysCategory').append(sysCategory + '</li></ul></div>');
			}
		});
	}
//网店分类:获得一级和二级分类
function sysCategoryStoreSecond(platformId,categoryIds,index){
	$.getJSON('/mbs/jsonPlatformCategory.jhtml', {
		'platformId' : platformId,
		'categoryIds' : categoryIds,
		'index' : index
	}, function(data) {
			var last = data.length;
			var sb = '<div class="und_platform_sysCategory_navlist" id="und_platform_sysCategory_MBSmenuNav">';
			$.each(data, function(id, item) {
				if (item.level == 1) {
					sb = sb + '<DL><DT><a href="/mbs/listStoreInfo.jhtml?cateId='+ item.cateId +'">' + item.cateName + "</A></DT><DD><UL class='und_platform_sysCategory_sideleft'>";
					if (id == last) {
						sb = sb + "</UL></DD></DL>";
						return false;
					}
					if (data[id + 1] == null || data[id + 1].level == 1) {
						sb = sb + "</UL></DD></DL>";
						return true;
					}
				}
				if (item.level == 2) {
					sb = sb + '<LI class=und_platform_sysCategory_noline><a href="/mbs/listStoreInfo.jhtml?cateId='+ item.cateId +'"target=_blank><B>' + item.cateName + "</B></A><DIV>";
					if (id == last) {
						sb = sb + "</DIV><SPAN class=clear></SPAN></LI></UL></DD></DL>";
						return false;
					}
					if (data[id + 1] == null || data[id + 1].level == 1) {
						sb = sb + "</DIV><SPAN class=clear></SPAN></LI></UL></DD></DL>";
						return true;
					}
				}
				if (item.level == 3) {
					if (data[id + 1] == null || data[id + 1].level == 1) {
						sb = sb + "</UL></DD></DL>";
						return true;
					}
				}
			});
			$('#und_platform_sysCategory').append(sb + '</div>');
			MBSMenuNav();
		}
	);
	}

//商城自定义显示区域 推荐商品
function platformAreaRecommend(platformId){
	$.getJSON('/mbs/jsonPlatformAreaRecommend.jhtml', {
		'platformId' : platformId
	}, function(data) {
		$.each(data, function(id, item) {
			if (item.platformDisplayAreaType == "1") {// 带图片的推荐
				var recommendImg = '<h2 class="und_platform_recommendAreaPic_classifyName">' + item.areaName + '</h2><div class="und_platform_recommendAreaPic_productClassify"><a href="' + item.platformDisplayAreaUrl
				+ '" class="und_platform_recommendAreaPic_classifyImg" target="_blank"><img height="350" width="200" src="http://' + hostName + item.platformDisplayAreaPic + '" alt="' + item.areaName + '" /></a><ul>';
				$.each(item.recoDetail, function(idRec, itemRec) {
					var recommendPicUrl;
					if (itemRec.recommendPic.indexOf("http://") != -1) {
						recommendPicUrl = itemRec.recommendPic;
					} else {
						recommendPicUrl = 'http://' + hostName + itemRec.recommendPic;
					}
					recommendImg = recommendImg + '<li><span class="und_platform_recommendAreaPic_imgBorder" ><a href="' + itemRec.recommendUrl + '" target="_blank"><img class="und_platform_recommendAreaPic_newProductImg" src="' + recommendPicUrl + '" alt="' + itemRec.recommendName
					+ '" /> </a></span>';
					var title = '<a class="und_platform_recommendAreaPic_font" href="' + itemRec.recommendUrl + '" target="_blank" title="' + itemRec.recommendName + '">' + itemRec.recommendName + '</a></li>';
					
//					if (itemRec.recommendUrl.indexOf("http://") == -1 && itemRec.recommendPrice != 0) {
//						recommendImg = recommendImg + '<span class="millet-price">￥<span>' + itemRec.recommendPrice + '</span></span>' + title;
//					} else {
//						recommendImg = recommendImg + '<span class="millet-price"></span>' + title;
//					}
						recommendImg = recommendImg + title;
				});
				$('#und_platform_recommendAreaPic').append(recommendImg + '</ul>');
			} else {
				var recommendNoImg = '<h2 class="und_platform_recommendAreaNoPic_userDeName">' + item.areaName + '</h2><ul class="und_platform_recommendAreaNoPic_userDefined">';
				$.each(item.recoDetail, function(idRec, itemRec) {
					var recommendPicUrl;
					if (itemRec.recommendPic.indexOf("http://") != -1) {
						recommendPicUrl = itemRec.recommendPic;
					} else {
						recommendPicUrl = 'http://' + hostName + itemRec.recommendPic;
					}
					recommendNoImg = recommendNoImg + '<li><span class="und_platform_recommendAreaNoPic_imgBorder" ><a href="' + itemRec.recommendUrl + '" target="_blank"><img class="und_platform_recommendAreaNoPic_newProImg" src="' + recommendPicUrl + '" alt="' + itemRec.recommendName
					+ '" /> </a></span>';
					var title = '<a class="und_platform_recommendAreaNoPic_font" href="' + itemRec.recommendUrl + '" target="_blank" title="' + itemRec.recommendName + '">' + itemRec.recommendName + '</a></li>';
//					if (itemRec.recommendUrl.indexOf("http://") == -1 && itemRec.recommendPrice != 0) {
//						recommendNoImg = recommendNoImg + '<span class="millet-price">￥<span>' + itemRec.recommendPrice + '</span></span>' + title;
//						recommendNoImg = recommendNoImg + '<span class="millet-price"></span>' + title;
//					} else {
//					}
						recommendNoImg = recommendNoImg  + title;
				});
				$('#und_platform_recommendAreaNoPic').append(recommendNoImg + '</ul>');
			}
		});
	});
}

	
// 热门搜索
function platformHotSearch(platformId){
	$.getJSON('/mbs/jsonIndexPlatformHotSearch.jhtml', {
		'platformId' : platformId
	}, function(data) {
		$.each(data, function(id, item) {
			$('#hotSearch').append('<a  href="' + item.searchLink + '">' + item.searchName + '</a>');
		});
	});
}	
// 广告
function indexAd(platformId){
	$.getJSON('/mbs/jsonIndexPageAd.jhtml', {
		'platformId' : platformId
	}, function(data) {
		$.each(data, function(id, item) {
			if (item.positionId == "1") {
				$('#und_platform_contan_top_center').append('<a href="' + item.adLink + '" target="_blank"> <img src="http://' + hostName + item.adImage + '" width="505" height="250"/></a>');
			}
			if (item.positionId == "2") {
				$('#und_platform_ad2').append('<a href="' + item.adLink + '" target="_blank"> <img src="http://' + hostName + item.adImage + '" width="210" height="80"/></a>');
			}
			if (item.positionId == "3") {
				$('#und_platform_ad3').append('<a href="' + item.adLink + '" target="_blank"> <img src="http://' + hostName + item.adImage + '" width="240" height="117"/></a>');
			}
			if (item.positionId == "4") {
				$('#und_platform_ad4').append('<a href="' + item.adLink + '" target="_blank"> <img src="http://' + hostName + item.adImage + '" width="240" height="117"/></a>');
			}
			if (item.positionId == "5") {
				$('#und_platform_ad5').append('<a href="' + item.adLink + '" target="_blank"> <img src="http://' + hostName + item.adImage + '" width="240" height="117"/></a>');
			}
			if (item.positionId == "6") {
				$('#und_platform_ad6').append('<a href="' + item.adLink + '" target="_blank"> <img src="http://' + hostName + item.adImage + '" width="210" height="80"/></a>');
			}
			if (item.positionId == "7") {
				$('#und_platform_ad7').append('<a href="' + item.adLink + '" target="_blank"> <img src="http://' + hostName + item.adImage + '" width="210" height="80"/></a>');
			}
			if (item.positionId == "8") {
				$('#und_platform_ad8').append('<a href="' + item.adLink + '" target="_blank"> <img src="http://' + hostName + item.adImage + '" width="960" height="90"/></a>');
			}
			if (item.positionId == "9") {
				$('#und_platform_ad9').append('<a href="' + item.adLink + '" target="_blank"> <img src="http://' + hostName + item.adImage + '" width="210" height="300"/></a>');
			}
		});
		$.fn.cycle.defaults.speed = 900;
		$.fn.cycle.defaults.timeout = 6000;
		
		$("#und_platform_contan_top_center").KinSlideshow({
               moveStyle:"down", 		//设置切换方向为向下 [默认向左切换]
               intervalTime:8,   		//设置间隔时间为8秒  [默认为5秒]
               mouseEvent:"mouseover",		//设置鼠标事件为“鼠标滑过切换”  [默认鼠标点击时切换]
               isHasTitleBar:false,
               titleFont:{TitleFont_size:14,TitleFont_color:"#FF0000"}, //设置标题文字大小为14px，颜色：#FF0000
		       isHasBtn:true, //是否显示按钮
		       btn:{btn_bgColor:"#FFF",
		    	    btn_fontColor:"#FF0000",
		    	    btn_borderColor:"#FF0000",
		    	    btn_bgHoverColor:"#FF0000",
		    	    btn_fontHoverColor:"#FFF",
		    	    btn_borderHoverColor:"#FF0000",
		    	    btn_fontFamily:"Verdana",
		    	    btn_borderWidth:1,
		    	    btn_bgAlpha:0.7
		    	    }
        });
//		$('#contan_top_center').cycle( {
//			fx : 'fade',
//			speed : 'fast',
//			timeout : 3000,
//			pager : '#picsNav',
//			pagerEvent : 'mouseover',
//			slideExpr : 'img'
//		});
		$('#und_platform_ad2').cycle( {
			fx : 'zoom',
			delay : -3000
		});
		$('#und_platform_ad3').cycle( {
			fx : 'scrollDown',
			delay : -4000
		});
		$('#und_platform_ad4').cycle( {
			fx : 'scrollDown',
			sync : 0,
			delay : -2000
		});
		$('#und_platform_ad5').cycle( {
			fx : 'zoom',
			easing: 'easeInBounce',
			delay:  -4000 
		});
		$('#und_platform_ad6').cycle();
		$('#und_platform_ad7').cycle();
		$('#und_platform_ad8').cycle();
		$('#und_platform_ad9').cycle();
	});
}

// 导航栏
function platformNav(platformId){
	$.getJSON('/mbs/jsonPlatformNav.jhtml', {
		'platformId' : platformId
	}, function(data) {
		var navTop = '<div class="und_platform_nav_menuOuter"><div class="und_platform_nav_innerMenu"><ul><li class="und_platform_nav_selectTouch"><a href="/" class="und_platform_nav_selectMenu"><span>首页</span></a></li>';
		var navBottom = '<div class="und_platform_nav_footer_t"><ul>';
		var navAny = '<div class="und_platform_nav_headerMenu"><ul>';
		$.each(data, function(id, item) {
			var href;
			if (item.openNew == "1") {
				href = '<li><a class="und_platform_nav_cateIdHref" href="' + item.navUrl + '" target="_blank"><span>' + item.navName + '</span></a></li>';
			} else {
				href = '<li><a  class="und_platform_nav_cateIdHref"  href="' + item.navUrl + '" ><span>' + item.navName + '</span></a></li>';
			}
			if (item.navPosition == "0") {// 上导航
				navTop = navTop + href;
			}
			if (item.navPosition == "1") {// 下导航
				navBottom = navBottom + href;
			}
			if (item.navPosition == "2") {// 任意导航
				navAny = navAny + href;
			}
		});
		$('#und_platform_navTop').append(navTop + '</ul></div></div>');
		$('#und_platform_navBottom').append(navBottom + '</ul></div>');
		$('#und_platform_navAny').append(navAny + '</ul></div>');
	});
}
	
	// 友情链接
function indexPartner(platformId){
	$.getJSON('/mbs/jsonPartner.jhtml', {
		'platformId' : platformId
	}, function(data) {
		var str ='<div id="und_platform_partner_boxShop" class="und_platform_partner_boxShop"><ul class="und_platform_partner_indexLink">';
		$.each(data, function(id, item) {
			if (id < 10) {
				str = str + '<li><a href="' + item.partnerWebsite + '">'+ item.partnerName+'</a></li>';
			}
		});
		$('#und_platform_partner').append(str + '</ul></div><div id="und_platform_partner_shopBottom"></div>');
		
		var speed=15;
		var scroll_begin = document.getElementById("und_platform_partner_boxShop");
		var scroll_end = document.getElementById("und_platform_partner_shopBottom");
		var scroll_div = document.getElementById("und_platform_partner");   
		function Marquee(){ 
			if(scroll_end.offsetWidth-scroll_div.scrollLeft<=0){
				scroll_div.scrollLeft-=scroll_begin.offsetWidth;
			}else{
		     scroll_div.scrollLeft++;
		   }
		};
		
	    var MyMar=setInterval(Marquee,speed);
		scroll_div.onmouseover=function() {clearInterval(MyMar);};
		scroll_div.onmouseout=function() {
	
		       MyMar=setInterval(Marquee,speed);
		};
	});
};

//帮助、新闻、公告
function indexArticleList(platformId,noticeNumber ,helpNumber,newsNumber,textSize){
	$.getJSON('/mbs/listArticles.jhtml', {
		'platformId' : platformId
	}, function(data) {
		var i_Notice = 0;
		var i_Help = 0;
		var i_News = 0;
		var indexNotice ='';
		var indexHelp ='';
		var indexNews ='';
		var size = data.length;
		if (size > 0) {
			var pageArticleId = data[0].id;
			indexNotice = '<div class="und_platform_indexNotice_notice"><a href="/mbs/listPageArticle.jhtml?pageArticleId='+ 
			pageArticleId+'"><h3><span>'+data[0].title+'</span>'+'</h3></a><div class="und_platform_indexNotice_bd"><ul>';
			$.each(data, function(ide, item) {
				var href='';
				var articleTitle='';
				articleTitle = item.articleTitle;
				if (item.articleType == "1") {
					href = item.articleUrl;
				}else{
					href = '/helpArticle/'+item.articleId+'.html';
				}
				if (pageArticleId != item.id) {
					pageArticleId = item.id;
					if (item.positionId == "2") {
						indexHelp = '<div class="und_platform_indexHelp_contanHelp"><a href="/mbs/listPageArticle.jhtml?pageArticleId='+ 
						pageArticleId+'"><h3><span>'+item.title+'</span>'+'</h3></a><div class="und_platform_indexHelp_bd"><ul>';
					}
					if (item.positionId == "3") {
						indexNews = '<div class="und_platform_indexNews_contanNews"><a href="/mbs/listPageArticle.jhtml?pageArticleId='+ 
						pageArticleId+'"><h3><span>'+item.title+'</span>'+'</h3></a><div class="und_platform_indexNews_bd"><ul>';
					}
				}
				// 公告，最多显示七条
				if (i_Notice < noticeNumber &&item.positionId == "1") {
					indexNotice = indexNotice + '<li><a  href="' + href + '" target="_blank" >' + articleTitle + '</a></li>';
					i_Notice++;
				}
				// 帮助，最多显示11条
				if (i_Help < helpNumber && item.positionId == "2") {
					indexHelp = indexHelp + '<li><a  href="' + href + '" target="_blank" >' + articleTitle + '</a></li>';
					i_Help++;
				}
				// 新闻
				if (i_News < newsNumber && item.positionId == "3" ) {
					indexNews = indexNews + '<li><a  href="' + href + '" target="_blank" >' + articleTitle + '</a></li>';
					i_News++;
				}
			});
		}
		$('#und_platform_indexNotice').append(indexNotice+'</ul></div></div>');
		$('#und_platform_indexHelp').append(indexHelp+'</ul></div></div>');
		$('#und_platform_indexNews').append(indexNews+'</ul></div></div>');
	});
}

	
	// 热卖商品——热门供应，显示10条
function listHotGoods(platformId){
	$.getJSON('/mbs/jsonListHotGoods.jhtml', {
		'platformId' : platformId
	}, function(data) {
		var indexGoodsHot ='';
		if (data != null && data != "") {
			indexGoodsHot = '<div class="und_platform_indexGoodsHot_hotPro"><h5>热门供应</h5><div class="und_platform_indexGoodsHot_milletColor"><ul>';
		}
		$.each(data, function(id, item) {
			var goodsPicUrl='';
			var goodsLink='';
			var storePrice='';
			if (item.goodsPic.indexOf("http://") != -1) {
				goodsPicUrl = item.goodsPic;
			} else {
				goodsPicUrl = 'http://' + hostName + item.goodsPic;
			}
			if (item.goodsSource =="1" ) {
				goodsLink = item.goodsLink;
				storePrice ='&nbsp';
			} else {
				goodsLink = '/good/'+item.goodsId+'.html"';
				storePrice ='￥'+item.storePrice;
			}
			if (id < 10) {
				indexGoodsHot = indexGoodsHot +  '<li><span class="und_platform_indexGoodsHot_imgBorder"><a href="'+goodsLink+'" target="_blank"><img class="und_platform_indexGoodsHot_newProductImg" src="'+goodsPicUrl
				+'"  alt="'+item.goodsName+'"/></a></span><span class="und_platform_milletPrice" >'+storePrice+'</span><span class="und_platform_indexGoodsHot_milletHx"><a href="'+
				goodsLink+'" target="_blank" title="'+item.goodsName+'">'+item.goodsName+'</a></span></li>';
			}
		});
		$('#und_platform_indexGoodsHot').append(indexGoodsHot + '</ul></div></div>');
	});
}
	
// 最新商品——最新供应，显示10条
function indexNewGoods(platformId){
	$.getJSON('/mbs/jsonIndexNewGoods.jhtml', {
		'platformId' : platformId
	}, function(data) {
		var indexNewGoods ='';
		if (data != null && data != "") {
			indexNewGoods = '<div class="und_platform_indexNexGoods_newPro"><h5>最新供应</h5><div class="und_platform_indexNexGoods_milletColor"><ul>';
		}
		var id=0;
		$.each(data, function(id, item) {
			var goodsPicUrl='';
			var goodsLink='';
			var storePrice='';
			if (item.goodsPic.indexOf("http://") != -1) {
				goodsPicUrl = item.goodsPic;
			} else {
				goodsPicUrl = 'http://' + hostName + item.goodsPic;
			}
			if (item.goodsSource =="1" ) {
				goodsLink = item.goodsLink;
				storePrice ='&nbsp';
			} else {
				goodsLink = '/good/'+item.goodsId+'.html"';
				storePrice ='￥'+item.storePrice;
			}
			if (id < 10) {
				var idImage='idImage'+id;
				indexNewGoods = indexNewGoods +  '<li><span class="und_platform_indexNewGoods_milletImg"><a href="'+goodsLink+'" target="_blank"><p><img class="und_platform_indexNewGoods_newProductImg" src="'+goodsPicUrl
				+'"  alt="'+item.goodsName+'"/></p></a></span><span class="und_platform_milletPrice" >'+storePrice+'</span><span class="und_platform_indexNewGoods_milletHx"><a href="'+
				goodsLink+'" target="_blank" title="'+item.goodsName+'">'+item.goodsName+'</a></span></li>';
				id++;
			}
		});
		$('#und_platform_indexNewGoods').append(indexNewGoods + '</ul></div></div>');
	});
}
	
//最新求购,显示五条
function indexSupplyInfo(platformId,textSize){
	$.getJSON('/mbs/jsonIndexSupplyInfo.jhtml', {
		'platformId' : platformId
	}, function(data) {
		var indexSupplyInfo ='';
		if (data != null && data != "") {
			indexSupplyInfo = '<div class="new_shop"><h3><span>最新求购</span><a href="/supplyInfos/0-0-1-1.html">更多</a></h3><div class="box-shop"><ul class="index_link">';
		}
		$.each(data, function(id, item) {
			var supplyTitle = item.supplyTitle;
			if (id < 5) {
				indexSupplyInfo = indexSupplyInfo +  '<li><a href="/supplyInfo/'+item.supplyInfoId+'.html" target="_blank" title="'+item.supplyTitle+'"><span>'+supplyTitle+'</a></span></li>';
			}
		});
		$('#und_platform_indexSupplyInfo').append(indexSupplyInfo + '</ul></div><span class="shop_bottom"></span></div>');
	});
}
	
	//最新资讯,显示五条
function indexInformation(platformId,textSize){
	$.getJSON('/mbs/jsonIndexInformation.jhtml', {
		'platformId' : platformId
	}, function(data) {
		var indexInformation ='';
		if (data != null && data != "") {
			indexInformation = '<div class="und_platform_indexInformation_newShop"><h3><span>最新资讯</span><a href="/informations/0-0-1.html">更多</a></h3><div class="und_platform_indexInformation_boxShop"><ul class="und_platform_indexInformation_indexLink">';
		}
		$.each(data, function(id, item) {
			var title = item.title;
			if (id < 5) {
				indexInformation = indexInformation +  '<li><a href="/information/'+item.informationId+'.html" target="_blank" title="'+item.title+'"><span>'+title+'</a></span></li>';
			}
		});
		$('#und_platform_indexInformation').append(indexInformation + '</ul></div><span class="und_platform_indexInformation_shopBottom"></span></div>');
	});
}
//推荐网店,显示五条
function indexListHotStore(platformId){
	$.getJSON('/mbs/jsonListHotStore.jhtml', {
		'platformId' : platformId
	}, function(data) {
		var indexStoreHot ='';
		if (data != null && data != "") {
			indexStoreHot = '<div class="und_platform_indexStoreHot_newShop"><h3><span>推荐网店</span><a href="/mbs/listAllStore.jhtml">更多</a></h3><div class="und_platform_indexStoreHot_boxShop"><ul class="und_platform_indexStoreHot_proList">';
		}
		$.each(data, function(id, item) {
			var  storeName = item.storeName;
			if (id < 5) {
				indexStoreHot = indexStoreHot +  '<li><a href="/store/'+item.storeId+'.html" target="_blank" title="'+item.storeName+'"><span>'+storeName+'</a></span></li>';
			}
		});
		$('#und_platform_indexStoreHot').append(indexStoreHot + '</ul></div><span class="und_platform_indexStoreHot_shop_bottom"></span></div>');
	});
}

