
function initAlbumPhoto() {
	var showBImg={}, bimgSwiper, typeSwiper;;
	showBImg.html=function(){
		var shopBigScrollBox=$('.shopBigScrollBox');
		var scrollCon=$('.lp-bunner ul').clone(true);
		shopBigScrollBox.html('');
		scrollCon.appendTo(shopBigScrollBox);

	};
	showBImg.count=function(){
		var $li=$('.shopBigScrollBox .swiper-wrapper .swiper-slide-active');
		var classname=$('#JsClassName');
		var index=$('#JsIndex');
		var sum=$('#JsSum');
		var $type = $("li", "#classNames").filter("[data-index=" + $li.attr('data-class') + "]");
		$type.addClass('on').siblings().removeClass('on');
		classname.text($type.text());
		index.text($li.attr('data-index'));
		sum.text($li.attr('data-sum'));
		$("#totalIndex").text($li.data("totalindex"));
		typeSwiper.slideTo(+$type.index(), 500, true);
	};

	$(function() {
		var swiper = new Swiper('.lp-bunner',{
			preloadImages: false, lazyLoading: true, lazyLoadingOnTransitionStart: true,
			onTransitionEnd: function(swiper){
				$('.lp-index').text(swiper.activeIndex+1);
			},
			onInit: function(swiper){
				$('.lp-index').text(swiper.activeIndex+1);
				$('.lp-sum').text(swiper.imagesToLoad.length || swiper.imagesLoaded || $('img', '.lp-bunner').size());
			},
			onClick:function(swiper){
				$('.shopBigBox').show();
				if ( ! bimgSwiper) {
					bimgSwiper = new Swiper('.shopBigScrollBox',{
						preloadImages: false, lazyLoading: true, lazyLoadingOnTransitionStart: true,
						initialSlide:swiper.activeIndex,
						onTransitionEnd:function(/*swiper*/){
							showBImg.count();
						},
						onInit:function(){
							showBImg.count();
						}
					});
				}
			}
		});
		var liWidth = $('.showBigClass li').click(function(){
			$(this).addClass('on').siblings().removeClass('on');
			var albumType = $(this).attr('data-index');
			var $li = $(".shopBigBox .swiper-wrapper").find("[data-class=" + albumType +"]:first");
			bimgSwiper.slideTo(+$li.data("totalindex") - 1, 500, true);
		}).width();
		typeSwiper = new Swiper('.showBigClass',{
			width: liWidth ? liWidth : 52.5
		});
		showBImg.html();


	});
}

// 根据内容滚动固定 Tab
function initBoxScrollFixed() {
	var $head = $("body>.head"), boxConditions = [];
	$(".main .box.scrollFixed").each(function(ind, box) {
		var $box = $(box),
			$tab = $box.find(">.box-tit"),
			$lis, liConList = [];
		if ( ! $tab[0]) {
			$tab = $box.find(">.tab");
			if ( ! $tab[0]) return;
			// 这是一个 tab 注册其余事件
			$lis = $tab.find("ul>li");
			var $curTabLi = $lis.removeClass("active").filter(":first").addClass("active");
			$("#" + $curTabLi.attr("id") + "-con").show();

			$lis.click(function() {
				var conId = $(this).attr("id");
				if ( !! conId) {
					$lis.removeClass("active");
					$(this).addClass("active");
					$("div.tab-con>*", $box).hide();

					var $con = $("#" + conId + "-con").show();
					$("html,body").stop(true).animate({
						scrollTop: $con.offset().top - $tab.height() * 2
					}, 500);
				}
			});
		}

		var criticalPoint = $box.offset().top - $head.height() + 14,
			condition = {
				$box: $box,
				$tab: $tab,
				criticalPoint: criticalPoint,
				minCriticalPoint: criticalPoint + $box.height() - $tab.height() * 4
			};
		if (criticalPoint <= 0) return;

		if (liConList && liConList.length > 0) {
			// 降序排序
			liConList = liConList.sort(function(a, b) {
				return a.criticalPoint < b.criticalPoint;
			});
			condition.callback = function() {
				$.each(liConList, function(ind, licon) {
					if (window.scrollY >= licon.criticalPoint) {
						$lis.removeClass("active");
						licon.$li.addClass("active");
						return false;
					}
				});
			};
		}

		boxConditions.push(condition);
	});
	boxConditions = boxConditions.sort(function(a, b) {
		return a.criticalPoint < b.criticalPoint;
	});
	if (boxConditions.length > 0) {
		$(window).scroll(function() {
			var fixed = false;
			for (var i = 0; i < boxConditions.length; ++i) {
				var c = boxConditions[i];
				// 重新计算临近点
				c.criticalPoint = c.$box.offset().top - $head.height() + 14;
				c.minCriticalPoint = c.criticalPoint + c.$box.height() - c.$tab.height() * 4;
				if (!fixed && window.scrollY >= c.criticalPoint) {
					if (window.scrollY >= c.minCriticalPoint) {
						c.$tab.removeClass("fixed-top");
					} else {
						fixed = true;
						c.$tab.addClass("fixed-top");
						if (typeof c.callback === "function") {
							c.callback.call(this);
						}
					}
				} else {
					c.$tab.removeClass("fixed-top");
				}
			}
		});
	}
}

window.initAlbumPhoto = initAlbumPhoto;
window.initBoxScrollFixed = initBoxScrollFixed;


function get_li_item(index,index1,row,sum,img){

	return '<li class="swiper-slide" data-index="'+index+'" data-totalindex="'+index1+'" data-class="'+row+'" data-sum="'+sum+'">'
		+'<a>'
		+'<img class="swiper-lazy swiper-lazy-loaded" src="'+ServerHost+'/houseImg/'+img+'" alt="">'
		+'</a>'
		+'</li>';
}
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
	var str = url.substr(1);
	strs = str.split("&");
	for(var i = 0; i < strs.length; i ++) {
		theRequest[strs[i].split("=")[0]]=decodeURI(strs[i].split("=")[1]);
	}
}
_id=theRequest.id;
$.ajax({
	url: "/app.php/app/getShopDetails",
	data: {
		"id":_id
	},
	type:"POST",
	dataType:"text",
	beforeSend:function(){},
	success:function(responseText){

		var arr=responseText.split("||");
		var data1=eval("("+arr[0]+")");
		//账号类型
		var data3=eval("("+arr[2]+")");
		var data2=eval("("+arr[1]+")");
		//最新动态标题
		var data4 = eval("("+arr[3]+")");
		//动态新闻id
		var data5 = eval("("+arr[4]+")");

		var image_0="";
		var image_4_1="";

		var image_1="";//效果图
		var image_2="";//实景图
		var image_3="";//样板图
		var image_4="";//户型图
		var image_5="";//交通图
		var image_4_num=0;

		//每种图数量
		var sum_img_1=0;
		var sum_img_2=0;
		var sum_img_3=0;
		var sum_img_4=0;
		var sum_img_5=0;

		//index
		var index_item_1=0;
		var index_item_2=0;
		var index_item_3=0;
		var index_item_4=0;
		var index_item_5=0;
		var index_item_all=0;


		$.each(data2, function(i, item) {
			image_0+='<div class="swiper-slide">'
			+'<img src="'+ServerHost+'/houseImg/'+item.Houseimg["imagename"]+'"/>'
			+'</div>';
			index_item_all++;
			switch (parseInt(item.Houseimg["imgtype"])){
				case 1:{
					sum_img_1++;
					index_item_1++;
					image_1+=get_li_item(index_item_1,index_item_all,101,"sum_img_1",item.Houseimg["imagename"]);
					break;
				}
				case 2:{
					sum_img_2++;
					index_item_2++;
					image_2+=get_li_item(index_item_2,index_item_all,102,"sum_img_2",item.Houseimg["imagename"]);
					break;
				}
				case 3:{
					sum_img_3++;
					index_item_3++;
					image_3+=get_li_item(index_item_3,index_item_all,103,"sum_img_3",item.Houseimg["imagename"]);
					break;
					break;
				}
				case 4:{
					image_4_1 += '<li class="m_ping1">'
					+ '<a href="imagebody.html?img_name='+item.Houseimg["imagename"] + '&name=' + item.Houseimg["img_title"] + '&address=1"><img src="'+ServerHost+'/houseImg/small_' + item.Houseimg["imagename"] + '" /></a>'
					+ '</li>';
					image_4_num++;
					//tab
					sum_img_4++;
					image_4+=get_li_item(index_item_4,index_item_all,104,"sum_img_4",item.Houseimg["imagename"]);
					break;

					break;
				}
				case 5:{
					sum_img_5++;
					index_item_5++;
					image_5+=get_li_item(index_item_5,index_item_all,105,"sum_img_5",item.Houseimg["imagename"]);
					break;
					break;
				}
			}
		});
		image_1 = image_1.replace(new RegExp("sum_img_1",'gm'),sum_img_1);
		image_2 = image_2.replace(new RegExp("sum_img_2",'gm'),sum_img_2);
		image_3 = image_3.replace(new RegExp("sum_img_3",'gm'),sum_img_3);
		image_4 = image_4.replace(new RegExp("sum_img_4",'gm'),sum_img_4);
		image_5 = image_5.replace(new RegExp("sum_img_5",'gm'),sum_img_5);

		//正式加载，不成功
		$("#img_item_ul").html(image_1+image_2+image_3+image_4+image_5);
		initAlbumPhoto();
		initBoxScrollFixed();

		if(sum_img_1==0){
			$("#handle_img_1").hide();
		}
		if(sum_img_2==0){
			$("#handle_img_2").hide();
		}
		if(sum_img_3==0){
			$("#handle_img_3").hide();
		}
		if(sum_img_4==0){
			$("#handle_img_4").hide();
		}
		if(sum_img_5==0){
			$("#handle_img_5").hide();
		}



		//$("#image_4_1_title").html('住宅'+image_4_num+'个户型');
		$("#image_4_1").html(image_4_1);
		$("#allimgs").html(image_0);
		//设置大图展示总数
		$("#totalIndex").next().html($(".lp-sum").html());
	},
	error:function(){}
});
