var maxnum=10;
var subboxwidth=200;
var subboxheight=90;
var wg=5;
var hg=3;
bodong=1;
var mybox=new Array(); 

function SetRandom(n){
   randomNum=Math.floor(Math.random()*n-n/2);
   return randomNum;
};
function showAuto(newid){
	if(newid>=l){newid=0;}
	
	var num=$("#mybox div span").length;
	k=Math.sqrt(Math.sqrt(Math.random()));
	ceilw=bodong*w*k;
	ceilh=bodong*h*k;
	var zuo = w/2+ SetRandom(ceilw);
	var sh =  h/2+ SetRandom(ceilh);


	$("#sub_"+newid).fadeOut(500,function(){
		$(this).css({left:zuo, top:sh ,"z-index":l+900}).html(newbox).fadeIn(900).siblings().each(function(){
			thisz=$(this).css("z-index");
			$(this).css("z-index",thisz-1);
		});
		newid+=1;
		window.setTimeout("showAuto("+newid+")",2000);
	});
	$.get("index.php?ac=showfeed&newtime="+newtime,function(data){
		 show=$.parseJSON(data);
		if(show!=null){
			for(var i=0;i<show.length;i++){
				image='<a class="img" href="space.php?uid='+show[i].uid+'"><img width="86" height="86" src="'+show[i].avatar+'" onerror="this.onerror=null;this.src=\''+show[i].UC_API+'/images/noavatar_middle.gif\'"/></a>';
				mybox[newid+i]=image+'<p><span class="sl"></span><span class="sc">'+show[i].message+'</span><span class="sr"></span></p>';
				newtime=show[i].newtime;
			}
		}
	});
	newbox=mybox[newid];
		
};

$(function(){
	
	for(var i=0;i<showfeed.length;i++){
		image='<a class="img" href="space.php?uid='+showfeed[i].uid+'"><img width="86" height="86" src="'+showfeed[i].avatar+'" onerror="this.onerror=null;this.src=\''+showfeed[i].UC_API+'/images/noavatar_middle.gif\'"/></a>';
		if(showfeed[i].title){mybox[i]=image+'<span class="sl"></span><p>'+showfeed[i].title+'</p>';}else if(showfeed[i].message){mybox[i]=image+'<span class="sl"></span><p>'+showfeed[i].message+'</p>';}else{mybox[i]=image+'<span class="sl"></span><p>'+showfeed[i].title_template+'</p>';}
			
	}
	var box_w=parseInt($("#mybox").css("width"));
	var box_h=parseInt($("#mybox").css("height"));
	w=box_w-subboxwidth;
	h=box_h-subboxheight;
	l=mybox.length;
	for(var i=0;i<mybox.length;i++){
		k=Math.sqrt(Math.sqrt(Math.random()));
		ceilw=bodong*w*k;
		ceilh=bodong*h*k;
		var zuo = w/2+ SetRandom(ceilw);
		var sh =  h/2+ SetRandom(ceilh);
		$("#mybox div").append("<span id='sub_"+i+"' class='sp'>"+mybox[i]+"</span>");
		$("#sub_"+i).animate({left:"+="+zuo,top:"+="+sh});
	}
	$("#mybox div span").live({mousemove:function(){
		//$(this).find("p").css("display","block");
		$(this).css("z-index",mybox.length+900).parent().siblings().each(function(){
			thisz=$(this).css("z-index");
			$(this).css("z-index",thisz-1);
		});
	}
	});
	var newid=0;
	window.setTimeout("showAuto("+newid+")",2000);
});
