//feed
feed = {
	aGroup : new Array(),
	/*
	*	获取贴墙动态(用户个人,以及其他用户在个人上的动态)
	*	@param uid: 被访问对象用户
	*	@param type: 1-全部， 2-自己，3-别人 4-留言
	*	@param id: 显示feed数据的对象id
	*/
	getFeedForWall : function (uid, type, id)
	{
		var oSel = $("feed_"+type);
		if(oSel)
		{
			oSel.className = "selected";
			var oParent = oSel.parentNode;
			if(oParent)
			{
				var oLi = oParent.getElementsByTagName('li');
				for(var i=0;i<oLi.length;i++)
				{
					if(oLi[i].id != "feed_"+type)
						oLi[i].className = "";	
				}
			}
		}
		
		var url = "/yqfeed/index.php";
		var paras = "tab=getfeedforwall&uid="+uid+"&walltype="+type;
		var feedAjax = new Ajax.Updater(id,url,
		{
			method: 'post',
			parameters: paras,
			onCreate: feed.loading(id),
			evalScripts: true
			//onComplete: function(originalRequest){feed.setFeedData(originalRequest, id)}
		}
		);
	},
	/*
	*	获取朋友、参加的群组、活动动态
	*	@param aConditoin
			   datatype  应用类型 photo blog etc
			   scenetype 场景类型 group event
			   sceneid   场景id 	 group event id
	*	@param id: 显示feed数据的对象id
	*	@param callback 显示feed数据后的回调函数
	*/
	getFeedForCity : function (id, aConditoin, callback)
	{
		var datatype  = "";
		var scenetype = "";
		var sceneid   = "";
		var count     = "";
		if(typeof(aConditoin) == "object" && aConditoin.length > 0)
		{
			datatype  = aConditoin[0];
			scenetype = aConditoin[1];
			sceneid   = aConditoin[2];
			count     = aConditoin[3];
		}
		var url = "/yqfeed/index.php";
		var paras = "tab=getfeedforcity&datatype="+datatype+"&scenetype="+scenetype+"&sceneid=" + sceneid + "&count=" + count;
		var feedAjax = new Ajax.Updater(
		id,url,
		{
			method: 'post',
			parameters: paras,
			onCreate: feed.loading(id),
			evalScripts: true,
			onComplete: function(originalRequest){feed.setFeedData(originalRequest, id, callback)}
		}
		);
	},
	getGFeedForOpen : function (id, aConditoin, callback)
	{
		var datatype  = "";
		var scenetype = "";
		var sceneid   = "";
		var count     = "";
		if(typeof(aConditoin) == "object" && aConditoin.length > 0)
		{
			datatype  = aConditoin[0];
			scenetype = aConditoin[1];
			sceneid   = aConditoin[2];
			count     = aConditoin[3];
			adminuid     = aConditoin[4];
		}
		var url = "/yqfeed/index.php";
		var paras = "tab=getfeedforcity&datatype="+datatype+"&scenetype="+scenetype+"&sceneid=" + sceneid + "&count=" + count + "&adminuid=" + adminuid;
		var feedAjax = new Ajax.Updater(
		id,url,
		{
			method: 'post',
			parameters: paras,
			onCreate: feed.loading(id),
			evalScripts: true,
			onComplete: function(originalRequest){feed.setFeedData(originalRequest, id, callback)}
		}
		);
	},
	setFeedData : function(originalRequest, id, callback)
	{
		var obj=$(id);
		if (obj){
			obj.innerHTML = originalRequest.responseText;
			if(trim(originalRequest.responseText) == '')
			{
				obj.style.display = 'none';
			}
			if (callback)
			{
				window.setTimeout(callback, 10);
			}
		}
	},
	/*
	*	用户删除一条feed
	*	@param fids feed数据主健，多个以逗号分割例如：1,2,3
	*	@param id 	要删除的feedhtml对象的id，为了效果才有此参数，否则无用
	*/
	delFeed: function(fids,id)
	{
		if(!confirm("确定执行该操作吗?"))   return false;
		var type = 1;
		var oType = $("deltype");
		if(oType)
		type = oType.value;
		var url = "/yqfeed/index.php";
		var paras = "tab=delfeed&fids="+fids+"&type="+type;
		var feedAjax = new Ajax.Request(
		url,
		{
			method: 'post',
			parameters: paras,
			onComplete: function(originalRequest){feed.setDel(originalRequest,id)}
		}
		);
	},
	setDel : function (originalRequest, id)
	{
		cdelpublc.delApp(id);
	},
	expandFeed : function(id)
	{
		var oFeed = $("unfold" + id);
		var oImg = $("pic" + id);
		if(oFeed && oImg)
		{
			if(oFeed.style.display == '')
			{
				oFeed.style.display = 'none';
				oImg.className = 'expand fr';
				oImg.title = "展开";
			}
			else
			{
				oFeed.style.display = '';
				oImg.className = 'fold fr';
				oImg.title = "折叠";
			}
		}
	},
	loading : function(id)
	{
		if($("css_path"))
		{
			var cssPath = $("css_path").value;
			var imgPath   =  cssPath + "/images/icon/loading.gif";
			var oId = document.getElementById(id);
			if(oId){
				oId.innerHTML= "<table width='100%' height='100'><tr><td align='center'><img class='bd0' src='" +imgPath+"'></td></tr></table>";
			}
		}
	},
	showGroupFeed : function(elem,event,id)
	{
		var target = this.getTarget(event)
		if(target)
		{
			if(this.is_node(target,'a')||(target.parentNode && this.is_node(target.parentNode,'a')))
			{
				return;
			}
		}
		this.expandGroupFeed(id);
		var inArray = false;
		for(var i=0;i<this.aGroup.length;i++)
		{
			if(this.aGroup[i] == id)
			{
				inArray = true;
				break;
			}
		}
		if (!inArray)
		{
			feed.aGroup.push(id);
			var divId = "ufeed_"+id;
			var aConditoin = new Array('','group',id,'4');
			this.getFeedForCity(divId, aConditoin);
		}
		var divId = "ufeed_"+id;
	},
	expandGroupFeed : function(id)
	{
		var oImg = $('uimg_'+id);
		var oInfo = $('uinfo_'+id);
		var oFeed = $('ufeed_'+id);
		var oLine = $('uline_'+id);
		var picurl = oImg.getAttribute("src");
		var picrel = oImg.getAttribute("rel");
		var oBtn = $('expand_'+id);
		if(oInfo.style.display == '')
		{
			oInfo.style.display = 'none';
			oFeed.style.display = 'none';
			oLine.style.display = 'none';
			oImg.setAttribute("src",picrel);
			oImg.setAttribute("rel",picurl);
			oBtn.title = "展开";
			oBtn.className = 'fold fr mousep';
		}
		else
		{
			oInfo.style.display = '';
			if(oFeed.innerHTML != ''){
				oFeed.style.display = '';
			}
			var oLi = oFeed.getElementsByTagName('li');
			if(oLi.length>0)
			{
				oLine.style.display = '';
			}
			oImg.setAttribute("src",picrel);
			oImg.setAttribute("rel",picurl);
			oBtn.title = "折叠";
			oBtn.className = 'expand fr mousep';
		}
	},
	getTarget : function(e)
	{
	    var target = window.event ? window.event.srcElement : e ? e.target : null;
	    if (!target){return false;}
	    while(target.nodeType!=1 && target.nodeName.toLowerCase()!='body'){
	        target=target.parentNode;
	    }
	    return target;
	},
	is_node : function(o,of_type)
	{
		var Node = null;
		try{if(!o||!((Node!=undefined&&o instanceof Node)||o.nodeName))
		{return false;}}
		catch(ignored){return false;}
		if(typeof(of_type)!=="undefined")
		{if(!(of_type instanceof Array)){of_type=[of_type];}
		var name;
		try{name=new String(o.nodeName).toUpperCase();}
		catch(ignored){return false;}
		for(var ii=0;ii<of_type.length;ii++)
		{try{if(name==of_type[ii].toUpperCase()){return true;}}catch(ignored){}}
		return false;
		}
		return true;
	}
};
function processphoto(obj)
{
	if(obj)
	{
		if(obj.width > 80)
		{
			obj.width = 80;
		}
		if(obj.height > 75)
		{
			obj.height = 75;
		}
	}
}