	var selectLocation = ["Canada", "China", "France", "Germany"];
var selectLocation2 = ["China"];
$(function() {

	var selectDisciplines = [" Masterplanning"," Architecture"," Interiors", "Lighting"," Landscape"," AV & Acoustics"," MEP"," Art work & Accessories"," Graphics & Signage"," Branding"," Furniture, Lighting"];
	
	var resentlist=window.localStorage.getItem("resentlist")
	var trendinglist=[
		"Interior","Architecture","Masterplanning","Lighting"
		,"Landscape","Acoustics","MEP","Art work & Accessories",
	]
	var newestList = window.localStorage.getItem("newestList")
	
	addlistBtn(".trendinglist",trendinglist)
	if(resentlist){
		resentlist=JSON.parse(resentlist)
		addlistBtn(".resentlist",resentlist)
	}else{
		resentlist=[]
	}
	if(newestList==null){
		newestList=[...selectDisciplines]
		window.localStorage.setItem("newestList", JSON.stringify(newestList))
		
	}else{
		newestList = JSON.parse(newestList)
	}
	
	addlistNewest(".newest-list-pro",newestList)
	
	$(".newest-list-pro").on("click", '.newest-item-x', function() {
		var name=$(this).parent().find(".query").text()
		
		var k2=newestList.indexOf(name)
		
		if (k2 != -1) {
			newestList.splice(k2, 1)
		}
		
		window.localStorage.setItem("newestList", JSON.stringify(newestList))
		
		$(this).parent().remove()
		
		refreshMoreArrow();
	})
	
	$(".search-item").on("click",'.querybtnli',function(){
		
		var value=$(this).text()
		$(".landingpage_search").val(value);
		$(".querybtn").click()
	})
	$(".querybtn").click(function(){
		resentlistAdd($(".landingpage_search").val())
	})
	
	
	function resentlistAdd(name){
		if (name) {
			var k = resentlist.indexOf(name)
			var k2=newestList.indexOf(name)
			
			if (k != -1) {
				 resentlist.splice(k, 1)
			}
			if (k2 != -1) {
				newestList.splice(k2, 1)
			}
			var i = resentlist.unshift(name)
			  newestList.unshift(name)
			
			var num = 4
			if (i > num) {
				resentlist = resentlist.slice(0, num)
			}
			window.localStorage.setItem("resentlist", JSON.stringify(resentlist))
			window.localStorage.setItem("newestList", JSON.stringify(newestList))
		
		}
		addlistNewest(".newest-list-pro",newestList)
		addlistBtn(".resentlist",resentlist)
		
		$(".imguploadlist").empty();
		data=data.sort(()=>{
			return Math.random()>0.5?-1:1
		})
		const tmphtml = template("flow-photos", {
			objs: data
		});
		$(".imguploadlist").append(tmphtml);
		
	}
	addlistSelect(".selectDisciplines",selectDisciplines)
	addlistSelect(".selectLocation",selectLocation)
	
function addlistNewest(name, list) {
		$(name).empty()
		list.forEach(function(item) {
				
			var btn = $('<div class="newest-item "> <span class="query">' + item + '</span><span class="newest-item-x" >x</span></div>')
	
			$(name).append(btn)
		})
	}
	function addlistBtn(name,list){
		$(name).empty()
		list.forEach(function(item){
			var btn=$('<button class="btn btn-lg  querybtnli">'+item+'</button>')
			
			$(name).append(btn)
		})
	}
	$(".query").click(function(){
		resentlistAdd($(this).text())
	
	})
	
	var data = [
		{
		logo: "../../assets/img/SketchPngff4baa52e24274f171eff0ccc6e01f1890b55b11bafffb477ce1f23bc465c249.png",
		name: "Helen studio CHINA | interior",
		isfollow: false,
		title: "Title for the post",
		data: "2021.09.11  17:23",
		txt: "	It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).",
		list: [
			"../../assets/img/landingpage/SketchPng7d6f19699512d467d9c2c6735798214c0ad484446e64adfb3f1215fb3d1cf5bb.png",
			"../../assets/img/landingpage/SketchPng7d6f19699512d467d9c2c6735798214c0ad484446e64adfb3f1215fb3d1cf5bb.png",
			"../../assets/img/landingpage/SketchPng677c41a514ce39003ea3ad7eed2f45da074f91790561db2f64b930d36743a708.png",
			
		]
	},{
		logo: "../../assets/img/moments_add.png",
		name: "Helen studio CHINA2 | interior2",
		isfollow: true,
		title: "Title for the post22",
		data: "2022.09.11  17:23",
		txt: "	222It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).",
		list: [
			"../../assets/img/landingpage/SketchPng7d6f19699512d467d9c2c6735798214c0ad484446e64adfb3f1215fb3d1cf5bb.png",
			"../../assets/img/landingpage/SketchPng09b8d1f99fd42b318c6bc00cfecbc1aebaf6950c531649da656adbf849d84188.png",
			"../../assets/img/landingpage/SketchPng11f2551c8c79f2a1f49994d7331b917307433c1dfc9bb864ab7941f9e98dacfd.png",
			"../../assets/img/landingpage/SketchPng51f6302e0405645a754c13a5832916e57e46357a62248bba0c66a45fb3cf7e34.png",
			"../../assets/img/landingpage/SketchPng89e9554a3265a9c1f8d56f3f7dd92e7e0af6a15c8c7b8aa9fddfe992757c51a0.png",
			"../../assets/img/landingpage/SketchPng90c84aeaabbe84af30410a95aa5645e88733bd80ac3f5fa3f01f88542155891b.png",
			"../../assets/img/landingpage/SketchPng92fd1d5f74f2e41c540e2262f216f9fb69b010979d402fadb516bca3fe317bc2.png",
			"../../assets/img/landingpage/SketchPng321a6596588e6a2a48470c19b29e6164b134792adc609d7f631c7548339e50fe.png",
			"../../assets/img/landingpage/SketchPng631eafd3e8e1a7ffdc4c6e213f31b0af54b76cc064bf269f4c39fceac1e788b8.png",
			
			
			
			
		]
	},
	
	]
	var obj=window.localStorage.getItem("postmoment")
	if(obj){
		obj=JSON.parse(obj)
		obj.isedit=1;
		data=[
			obj,
			...data
		]
	}
	const tmphtml = template("flow-photos", {
		objs: data
	});
	
	$(".imguploadlist").append(tmphtml);
	$('.imguploadspan').viewer({
		url: 'data-original',
	});
	$(".Follow").click(function(){
		$(this).parent().find(".Follow").show()
		$(this).hide()
	})
	
	$(".imguploadlist").on("click",".opBtn.edit",function(){
		window.location.href=("../moments/postmoment.html?1=1");
		
	});
	
	$(".imguploadlist").on("click",".opBtn.delete",function(){
		
 		
		var successTitle = $(".head_success").val();
		var cancelTitle = $(".head_cancel").val();
		
		var warning = $(".head_tips").val();
		var warning1 = $(".signin_warning").val()
		var _this=this;
		
		zeroModal.alert({
			unique: '1',
			opacity: 0.8,
			content: warning,
			contentDetail: warning1,
			width: '300px',
			height: '280px',
			cancel:true,
			ok: true,
			cancelTitle:cancelTitle,
			okTitle:successTitle,
			okFn: function() {
				$(_this).parent() .parent().remove()
			},
			onClosed: function() {
				; //location.href='../signin/signin.html'
			},
			onComplete: function(evn) {
				console.log('onComplete')
		// 		setTimeout(function() {
		
		// 			zeroModal.close('1');
		// 		}, 3000);
			}
		})
	});
	
	
	$('.selectpicker').selectpicker({
		template:{
			caret:'<span class="sel-icon glyphicon glyphicon-menu-down"></span>'
		}
	});
	
	//trigger search by enter
	$(".landingpage_search").on("keyup",function(event){
		var e = event || window.event;
		if(e && e.keyCode==13 && this.value.length>0){ 
			resentlistAdd($(".landingpage_search").val());
			refreshMoreArrow();
		}
	});
	
	$(".newest-list .more-arrow").on("click",function(event){
		$(".newest-list-pro").prop("scrollLeft",100);
	});
	
	refreshMoreArrow();
})

function selectOnchang(obj){ 
	console.log(obj.selectedIndex)
	if(obj.selectedIndex==1){
		addlistSelect(".selectpicker.selectLocation", selectLocation2)
		
	}else{
		addlistSelect(".selectpicker.selectLocation", selectLocation)
		
	}
	$(".selectpicker.selectLocation").selectpicker('refresh');
}
function addlistSelect(name, list) {
		$(name).empty()
		list.forEach(function(item) {
			var btn = $('<option>' + item + '</option>')

			$(name).append(btn)
		})
	}
	
function refreshMoreArrow(){
	let $dom=$(".newest-list-pro");
	console.log($dom[0].scrollWidth,$dom.width());
	if($dom[0].scrollWidth>$dom.width()){
		$(".newest-list .more-arrow img").show();
	}
	else{
		$(".newest-list .more-arrow img").hide();
	}
}