var hostName = 'img.bip.cn';

//商城自定义显示区域 推荐商品
function platformAreaRecommend(platformId){
	$.getJSON('/mbs/jsonPlatformAreaRecommend.jhtml', {
		'platformId' : platformId
	}, function(data) {
		var size = data.length;
		if (size==0) {
			return ;
		}
		var oneRecommend = '<ul class="user_defined">';
		$.each(data[0].recoDetail, function(idRec, itemRec) {
			var recommendPicUrl;
			if (itemRec.recommendPic.indexOf("http://") != -1) {
				recommendPicUrl = itemRec.recommendPic;
			} else {
				recommendPicUrl = 'http://' + hostName + itemRec.recommendPic;
			}
			oneRecommend = oneRecommend + '<li><span class="imgBorder" ><a href="' + itemRec.recommendUrl + '" target="_blank"><img class="new-product-img" src="' + recommendPicUrl + '" alt="' + itemRec.recommendName
			+ '" /> </a></span></li>';
			var title = '<a href="' + itemRec.recommendUrl + '" target="_blank" title="' + itemRec.recommendName + '">' + itemRec.recommendName+ '</a></li>';
		});
		if (size==1) {
			return ;
		}
		var twoRecommend = '<ul class="user_defined">';
		$.each(data[1].recoDetail, function(idRec, itemRec) {
			var recommendPicUrl;
			if (itemRec.recommendPic.indexOf("http://") != -1) {
				recommendPicUrl = itemRec.recommendPic;
			} else {
				recommendPicUrl = 'http://' + hostName + itemRec.recommendPic;
			}
			twoRecommend = twoRecommend + '<li><span class="imgBorder" ><a href="' + itemRec.recommendUrl + '" target="_blank"><img class="new-product-img" src="' + recommendPicUrl + '" alt="' + itemRec.recommendName
			+ '" /> </a></span></li>';
			var title = '<a href="' + itemRec.recommendUrl + '" target="_blank" title="' + itemRec.recommendName + '">' + itemRec.recommendName+ '</a></li>';
		});
		$('#oneRecommend').append(oneRecommend + '</ul>');
		$('#twoRecommend').append(twoRecommend + '</ul>');
	});
}
// 广告
function indexAd(platformId){
	$.getJSON('/mbs/jsonIndexPageAd.jhtml', {
		'platformId' : platformId
	}, function(data) {
		$.each(data, function(id, item) {
			if (item.positionId == "1") {
				$('#ad1').append('<a href="' + item.adLink + '" target="_blank"> <img src="http://' + hostName + item.adImage + '" width="505" height="250"/></a>');
			}
			if (item.positionId == "2") {
				$('#ad2').append('<a href="' + item.adLink + '" target="_blank"> <img src="http://' + hostName + item.adImage + '" width="210" height="80"/></a>');
			}
			if (item.positionId == "3") {
				$('#ad3').append('<a href="' + item.adLink + '" target="_blank"> <img src="http://' + hostName + item.adImage + '" width="240" height="117"/></a>');
			}
			if (item.positionId == "4") {
				$('#ad4').append('<a href="' + item.adLink + '" target="_blank"> <img src="http://' + hostName + item.adImage + '" width="240" height="117"/></a>');
			}
			if (item.positionId == "5") {
				$('#ad5').append('<a href="' + item.adLink + '" target="_blank"> <img src="http://' + hostName + item.adImage + '" width="240" height="117"/></a>');
			}
			if (item.positionId == "6") {
				$('#ad6').append('<a href="' + item.adLink + '" target="_blank"> <img src="http://' + hostName + item.adImage + '" width="210" height="80"/></a>');
			}
			if (item.positionId == "7") {
				$('#ad7').append('<a href="' + item.adLink + '" target="_blank"> <img src="http://' + hostName + item.adImage + '" width="210" height="80"/></a>');
			}
			if (item.positionId == "8") {
				$('#ad8').append('<a href="' + item.adLink + '" target="_blank"> <img src="http://' + hostName + item.adImage + '" width="960" height="90"/></a>');
			}
			if (item.positionId == "9") {
				$('#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;
		
		$("#ad1").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
		    	    }
       });
//		$('#ad1').cycle( {
//			fx : 'fade',
//			speed : 'fast',
//			timeout : 3000,
//			pager : '#picsNav',
//			pagerEvent : 'mouseover',
//			slideExpr : 'img'
//		});
		$('#ad2').cycle( {
			fx : 'zoom',
			delay : -3000
		});
		$('#ad3').cycle( {
			fx : 'scrollDown',
			delay : -4000
		});
		$('#ad4').cycle( {
			fx : 'scrollDown',
			sync : 0,
			delay : -2000
		});
		$('#ad5').cycle( {
			fx : 'scrollDown',
			sync : 0,
			delay : -2000
		});
		$('#ad6').cycle();
		$('#ad7').cycle();
		$('#ad8').cycle();
		$('#ad9').cycle();
	});
}

// 导航栏
function platformNav(platformId){
	$.getJSON('/mbs/jsonPlatformNav.jhtml', {
		'platformId' : platformId
	}, function(data) {
		var navBottom = '<div id="footer_t"><ul>';
		var last = data.length;
		$.each(data, function(id, item) {
			var href;
			if (item.openNew == "1") {
				if (data[id+1] == null || data[id+1].navPosition ==2) {
					href = '<li><a id="cateId_href" href="' + item.navUrl + '" target="_blank"><span>' + item.navName + '</span></a></li>';
				}else{
					href = '<li><a id="cateId_href" href="' + item.navUrl + '" target="_blank"><span>' + item.navName + '</span></a>|</li>';
				}
			} else {
				if (data[id+1] == null || data[id+1].navPosition ==2) {
					href = '<li><a id="cateId_href" href="' + item.navUrl + '" ><span>' + item.navName + '</span></a></li>';
				}else{
					href = '<li><a id="cateId_href" href="' + item.navUrl + '" ><span>' + item.navName + '</span></a>|</li>';
				}
			}
			if (item.navPosition == "1") {// 下导航
				navBottom = navBottom + href ;
			}
		});
		$('#navBottom').append(navBottom + '</ul></div>');
	});
}
	
	// 友情链接
function indexPartner(platformId){
	$.getJSON('/mbs/jsonPartner.jhtml', {
		'platformId' : platformId
	}, function(data) {
		var str = '<div style="margin-top:10px;" class="new_shop"><h3><span>友情链接</span></h3>' + '<div class="box-shop"><ul class="index_link">';
		$.each(data, function(id, item) {
			if (id < 10) {
				str = str + '<li><a href="' + item.partnerWebsite + '">' + item.partnerName + '</li></a>';
			}
		});
		$('#partner').append(str + '</ul></div><span class="shop_bottom"></span></div>');
	});
}
	

//帮助、新闻、公告
function indexArticleList(platformId,notice,help,news){
	$.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 id="contan_notice"><div class="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 id="contan_help"><div class="bd"><ul>';
					}
					if (item.positionId == "3") {
						indexNews = '<div id="contan_news"><div class="bd"><ul>';
					}
				}
				// 公告，最多显示七条
				if (i_Notice < notice &&item.positionId == "1") {
					indexNotice = indexNotice + '<li><a  href="' + href + '" target="_blank" >' + articleTitle + '</a></li>';
					i_Notice++;
				}
				// 帮助，最多显示11条
				if (i_Help < help && item.positionId == "2") {
					indexHelp = indexHelp + '<li><a  href="' + href + '" target="_blank" >' + articleTitle + '</a></li>';
					i_Help++;
				}
				// 新闻
				if (i_News < news && item.positionId == "3" ) {
					indexNews = indexNews + '<li><a  href="' + href + '" target="_blank" >' + articleTitle + '</a></li>';
					i_News++;
				}
			});
		}
		$('#indexNotice').append(indexNotice+'</ul></div></div>');
		$('#indexHelp').append(indexHelp+'</ul></div></div>');
		$('#indexNews').append(indexNews+'</ul></div></div>');
	});
}

	
	//最新资讯,显示五条
function indexInformation(platformId){
	$.getJSON('/mbs/jsonIndexInformation.jhtml', {
		'platformId' : platformId
	}, function(data) {
		var indexInformation ='';
		if (data != null && data != "") {
			indexInformation = '<div class="new_shop"><h3><span>最新资讯</span><a href="/informations/0-0-1.html">更多</a></h3><div class="box-shop"><ul class="index_link">';
		}
		$.each(data, function(id, item) {
			var title='';
			if (item.title.length > 12) {
				title = item.title;
			} else {
				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>';
			}
		});
		$('#indexInformation').append(indexInformation + '</ul></div><span class="shop_bottom"></span></div>');
	});
}


/*
 * 模版首页
 * 
*/
$(function() {
	var platformId = $('#platformId').val();
	var categoryIds = $('#categoryIds').val();
	platformAreaRecommend(platformId);// 自定义区域
	
	indexAd(platformId);// 广告
	
	platformNav(platformId);// 导航栏
	
//	indexPartner(platformId);// 友情链接
	// 公告、帮助、新闻(显示的个数)
	indexArticleList(platformId,12,0,12);
});

