function getPathStr(len,string){
	if(len>1){
		str = "";
		for(var i=2;i<len;i++){
			str+="&nbsp;&nbsp;┊";
		}
		return str+"&nbsp;&nbsp;┗"+string+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	}else{
		return string;
	}
}


function getAreaChoose(containerStr,lurl,callback){
	var container = $("#"+containerStr)
	container.append('<select style="width:100px; overflow:hidden;" id="'+containerStr+'_shengfen"></select>')
	container.append('<select style="width:100px; overflow:hidden;" id="'+containerStr+'_shi"></select>')
	container.append('<select style="width:100px; overflow:hidden;" id="'+containerStr+'_qu"></select>')
	var shengfen = $("#"+containerStr+"_shengfen")
	var shi = $("#"+containerStr+"_shi")
	var qu = $("#"+containerStr+"_qu")
	var d //ajax载入的地区数据
	function shenfenChangeHandle(e) {
		shi.remove()
		qu.remove()
		container.append('<select style="width:100px; overflow:hidden;" id="'+containerStr+'_shi"></select>')
		container.append('<select style="width:100px; overflow:hidden;" id="'+containerStr+'_qu"></select>')
		shi = $("#"+containerStr+"_shi")
		qu = $("#"+containerStr+"_qu")
		shi.change(shiChangeHandle);
		qu.change(quChangeHandle);
		shi.append('<option selected="selected" value="不限">不限</option>')
		qu.append('<option selected="selected" value="不限">不限</option>')
		$(d).find("Province[name="+shengfen.attr("value")+"]>State").each(function(index, element) {
			shi.append('<option value="'+$(this).attr("name")+'">'+$(this).attr("name")+'</option>')
		})
		container.attr("val",shengfen.val())
	}
	function shiChangeHandle(e) {
		qu.remove()
		container.append('<select style="width:100px; overflow:hidden;" id="'+containerStr+'_qu"></select>')
		qu = $("#"+containerStr+"_qu")
		qu.change(quChangeHandle);
		qu.append('<option selected="selected" value="不限">不限</option>')
		$(d).find("State[name="+shi.attr("value")+"]>City").each(function(index, element) {
			qu.append('<option value="'+$(this).attr("name")+'">'+$(this).attr("name")+'</option>')
		})
		if(shi.val()!="不限"){
			container.attr("val",shengfen.val()+"-"+shi.val())
		}else{
			container.attr("val",shengfen.val())
		}
	}
	function quChangeHandle(e) {
		if(qu.val()!="不限"){
			container.attr("val",shengfen.val()+"-"+shi.val()+"-"+qu.val())
		}else{
			container.attr("val",shengfen.val()+"-"+shi.val())
		}
	}
	$.get(lurl,{},function(dx){
		d = dx;
		function updateProvince(){
			var tempN = ""
			for(var i=0;i<provinceList.length;i++){
				var norStr = provinceList[i].toString().split("-")[1]
				var keyStr = provinceList[i].toString().split("-")[0]
				if(tempN!=keyStr){
					tempN = keyStr
					keyStr+="-"
					if(keyStr=="特1-" || keyStr=="特2-"){
						keyStr="&nbsp;&nbsp;"
					}
				}else{
					keyStr="&nbsp;&nbsp;"
				}
				if(i ==0){
					shengfen.append('<option selected="selected" value="'+provinceList[i].toString().split("-")[1]+'">'+keyStr+norStr+'</option>')
				}else{
					shengfen.append('<option value="'+provinceList[i].toString().split("-")[1]+'">'+keyStr+norStr+'</option>')
				}
			}
		}
		shengfen.change(shenfenChangeHandle);
		shi.change(shiChangeHandle);
		qu.change(quChangeHandle);
		var provinceList = []
		$(d).find("Province").each(function(index, element) {
			provinceList.push($(this).attr("s")+"-"+$(this).attr("name"))
        });
		provinceList.sort(); 
		updateProvince()
		shenfenChangeHandle()
		shiChangeHandle()
		if(callback)callback(d,shenfenChangeHandle,shiChangeHandle,quChangeHandle)
	})
	return container;
}

/*
滚动条分页加载
*/
function scrollKuaibaoList(opts,callBack){
	if(!opts || !opts.url){alert("scrollKuaibaoList 参数错误,没有配置URL.");return;}
	else if(!opts.el){alert("scrollKuaibaoList 参数错误,没有配置el容器名.");return;}
	else if(!opts.pageSize){opts.pageSize=3;}
	else if(!opts.inID){opts.inID  = eval($("#"+opts.el).attr("inID"));}
	if(opts.inID.length == 0){$("#"+opts.el).html('<div style="padding:25px; text-align:center;">没有数据哦...</div>');return;}
	var iHeight = 0;  
	var iTop = 0;  
	var clientHeight = 0;  
	var iIntervalId = null;  
	var pageNo = 1;   // 当前页数，默认设为第 1 页  
	var pageSize = opts.pageSize; // 每页显示的数量  
	function getPageHeight() {  
	  if(document.body.clientHeight && document.documentElement.clientHeight) {    
		clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;            
	  } else {    
		clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;        
	  }  
	  iHeight = Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);  
	}
	
	function _onScroll() {
		if(iHeight==0){
			iTop = document.documentElement.scrollTop + document.body.scrollTop;  
			getPageHeight(); 
			if(((iTop+clientHeight)>parseInt(iHeight*0.5)) || $("#"+opts.el).height()<clientHeight) {  
				if(pageNo >= pageSize) {  
				  clearInterval(iIntervalId);
				  if(opts.pageBar)$("#"+opts.pageBar).show()
				  return;  
				}
				if(opts.pageBar)$("#"+opts.pageBar).hide()
				show();
			}else{
				iHeight=0
			}
		}
	}
	var key=Math.floor(Math.random()*10000)
	var pageCount = Math.round(opts.inID.length/pageSize);
	if(pageCount<20)pageCount=20
	function loadPageContent(href){
		if(!href){
			href = opts.url
		}
		var inIDarr
		if(opts.inID.length>10){
			inIDarr = opts.inID.splice(0,pageCount+2)
		}else{
			inIDarr = opts.inID;
		}
		$("#"+opts.el).load(href,{
				inID:inIDarr.toString(),
				timekey:key
			},function(event){
			window.scroll(0,0)
			clearInterval(iIntervalId);
			if(inIDarr != opts.inID){
				if(opts.pageBar)$("#"+opts.pageBar).hide()
				iIntervalId = setInterval(_onScroll, 200);
			}else{
				if(opts.pageBar)$("#"+opts.pageBar).show()
				$("#loading_pageBar").remove()
			}
			if(callBack)callBack()
			pageNo=1;
			iHeight=0
		});	
	}
	loadPageContent(null)
	function show() {
		pageNo++;
		//opts.inID.toString()
		var inIDarr = opts.inID.splice(0,pageCount)
		if(inIDarr.length>0){
			$.post(opts.url,{
					timekey:key,
					inID:inIDarr.toString()
				},function(data){
					$("#loading_pageBar").remove()
					$("#"+opts.el).append(data);
					if(pageNo >= pageSize) {
						$("#loading_pageBar").remove()
					}
					if(callBack)callBack();
					iHeight=0
			});
		}else{
			if(opts.pageBar)$("#"+opts.pageBar).show()
			$("#loading_pageBar").remove()
		}
	}
}


function showArtBigImg(owner){
	var bigURL = owner.attr("src")
	var p = /\+(\d+)\-(\d+)\+/
	var m = bigURL.match(p)
	var r = m[1] / m[2]
	var w = owner.attr("maxWidth")?owner.attr("maxWidth"):450;
	if(parseInt(m[1]) > w){
		owner.width(w)
		owner.height(w/r)
		owner.bind("click",function(){
			window.open(bigURL)
		}).css("cursor","pointer")
	}else{
		owner.width(m[1])
		owner.height(m[2])
	}
}
function removeLinkForSearch(index, element){
	$(this).attr("href",$(this).attr("href").replace("/forSearchLink",""))
}

//缩放浏览器时,重新排列板块
var getTotalWidthDefault
function page_e234sBoxResize(e) {
	if($(window).width()<=1200){
		getTotalWidthDefault = 960
	}else{
		getTotalWidthDefault = 1200
	}
	switchStylestyle("w_"+getTotalWidthDefault)
	if(pageResize)pageResize();
}
function switchStylestyle(styleName){
  $('link[@rel*=style][title]').each(function(i)
  {
	 this.disabled = true;
	 if (this.getAttribute('title') == styleName) this.disabled = false;
  });
}
page_e234sBoxResize(null);

var pageResize=null;//定义窗口缩放,页面的处理函数.
$(this).resize(page_e234sBoxResize);
$(document).ready(function() {
	windowScroll()
	$(".pagebarinner select").bind("change",function(){
		window.location.href=$(this).val();
	});
	$(".forSearchLink").each(removeLinkForSearch);
});

//滚动到顶部的按钮句柄
function windowScroll(){
	$(window).scroll(function(){
		if($(this).scrollTop()==0){
			$("#backToTop").hide()
		}else{
			$("#backToTop").show()
		}
	});
	$("#backToTop").hover(function(){
		$(this).css("background-position","left bottom")	
	},function(){
		$(this).css("background-position","left top")
	}).bind("click",function(){
		$('html, body').animate({scrollTop:0}, 'slow');
			return false;
	})
}

