// JavaScript Document
todo.onload(function(){
	todo._favCookie=new Cookie('favorites');
	todo._favIds=todo._favCookie.ids?todo._favCookie.ids.split(','):[];
	todo._saveFavCookie=function(){
		todo._favCookie.ids=todo._favIds.join(',');
		todo._favCookie.store(30,'/');
	}
});
function favorites(id){
	for(var i=0;i<todo._favIds.length;i++)if(todo._favIds[i]==id){
		todo._favIds.splice(i,1);
		setFavNum(todo._favIds.length);
		todo._saveFavCookie();
		return false;
	};
	todo._favIds[todo._favIds.length]=id;
	todo._saveFavCookie();
	setFavNum(todo._favIds.length);
	return true;
};
function setFavNum(num){try{var f=todo.get('favorites');f.style.display=num?'':'none';f.getElementsByTagName('span')[0].innerHTML=num;}catch(er){}};
todo.onload(function(){
	setFavNum(todo._favIds.length);
	todo.loop(todo.get('mainbar').getElementsByTagName('a'),function(){
		if(!this.id)return;
		var res=this.id.match(/fav([0-9]+)/);
		if(!res)return;
		this.onclick=function(event){
			this._state=!this._state;
			this.className='favorites_'+(favorites(this.id.match(/fav([0-9]+)/)[1])?'on':'off');
			todo.stopPropagation(event);
		};
		for(var i=0;i<todo._favIds.length;i++)if(todo._favIds[i]==res[1])this.className='favorites_on';
	});
});
