
//首页照片墙
var picWall = {
	lock : false,
	timeout: null,
	hoverEvent : function(){
		var _this=this;
		this.$box.find('li').not('.refresh').mouseover(function(e){
			clearInterval(_this.timeout);
			_this.$pop.html($(this).find('.detail').html());
		}).mouseout(function(){
			_this.autoPlay();
			_this.$pop.stop().animate({opacity:0},100,function(){$(this).hide()});
		}).mousemove(function(e){
			_this.popShow(e,this);
		});
	},
	popShow : function(e,o){
		var posY=e.pageY-this.$box.offset().top;
		var posX=e.pageX-this.$box.offset().left;
		//console.log(posX,posY);
		this.$pop.css({left:posX+10,top:posY+10,display:'block'}).stop().animate({opacity:1},100);
	},
	init : function(id){
		this.$box=$(id);
		this.$pop=$('#picWall_pop');
		this.hoverEvent();
		//this.update(picWallData,true);
		this.ajaxUpdate();
		this.autoPlay();
	},
	autoPlay:function(){
		var _this = this;
		_this.timeout = setInterval(function(){
			_this.ajaxUpdate();
		},60000);
	},
	ajaxUpdate:function(){
		if(this.lock===true) return false;
		this.lock=true;
		var _this=this;
		this.$box.find('.refresh').addClass('loading');
		$.get('/Handle/getPicWall.asp',{ac:'GetPicWall',inum:0,maxin:9999999},function(json){
			json = eval("("+json+")");
			_this.update(json.data);
		},"script");
	},
	update:function(data,noEfect){
		var _this = this;
		//
		_this.$box.find('li').not('.refresh').each(function(i){
			if(i==1||i==26){//第20和第2个交换
				i=i==1?26:1;
			}
			if(i==0||i==1){//判断是否大图
				var w = 157;
			}else{
				var w = 78;
			}
			//console.log(i)
			var actionItem = $(this).find('.mask');
			data[i]&&actionItem.append('<div class="item">'+_this.itemHTML(data[i],w)+'</div>');
			!noEfect&&setTimeout(function(){
				_this.changeItem(actionItem,w);
			},Math.floor(Math.random()*900));
		});
		//更改刷新按钮状态
		setTimeout(function(){
			_this.$box.find('.refresh').removeClass('loading');
			_this.lock=false;
		},1300);
	},
	changeItem:function(actionItem,w){
		actionItem.stop().animate({'top':actionItem.find('.item').length>1?-w:0},300,function(){
			actionItem.find('.item').length>1?actionItem.find('.item').eq(0).remove():"";
			actionItem.css('top',0);
		});
		//actionItem.find('.item').eq(0).remove();
	},
	itemHTML:function(data,w){
		var artImg=!data.isArt?picWallHost+'/fxstatic/images/index-icon-yi.png':'';
		var str ='<img width="'+w+'" height="'+w+'" src="'+data.photoPath+'" /><div class="detail"><img width="157" height="157" src="'+data.photoPath+'" /><p class="name"><img class="'+data.starIcon+' userLevelSmall" src="/images/pixel.gif" />'+(data.isArt?'<img src="'+picWallHost+'/fxstatic/images/index-icon-yi.png" />':'')+'<a href="/index.php?action=user&id='+data.userId+'" target="_blank">'+unescape(unescape(data.nickName))+'</a></p><p class="note">'+unescape(data.privateMesg).substring(0,48)+'...</p>'+(data.status==1?'<span class="live">直播</span>':'')+'</div><a href="/'+data.roomId+'" target="_blank">'+(data.status==1?'<span class="bg bg2"></span>':'<span class="bg"></span>')+'</a>';
		return str;
	}
}