var Favorite = {
	
	init: function(){
		Favorite.id='';
		Favorite.type='';
		Favorite.element='';
	},
	
	call: function(id, type, element){
		
		if(jsLoginStatus!='200'){
			LoginStatus.signIn();
			return;
		}
		
		Favorite.id=id;
		Favorite.type=type;
		Favorite.element=element;
		Favorite.elementText=element.text();
		
		Favorite.element.addClass("favorite_loading");
		Favorite.element.html("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
		
		if(element.hasClass("favorite_on")){
			Favorite.removeFavorite();
		} 
		if(element.hasClass("favorite_off")){
			Favorite.addFavorite();
		}
		
	},
	
	addFavorite: function(){
		
		jQuery.getJSON("/favorite/on/?callback=?&idFavorite="+this.id+'&type='+this.type, function(dataJSON){
			if(dataJSON.STATUS=='OK'){
				Favorite.element.removeClass("favorite_on").removeClass("favorite_off").removeClass("favorite_loading");
				if(Favorite.element.hasClass("favorite_on_tiny") || Favorite.element.hasClass("favorite_off_tiny") ){
					Favorite.element.removeClass("favorite_on_tiny").removeClass("favorite_off_tiny");
					Favorite.element.addClass("favorite_on_tiny");
				} 
				Favorite.element.addClass("favorite_on");
				Favorite.element.text(Favorite.elementText);
				Favorite.init();
			}
		});
		
	},
	
	removeFavorite: function(){
		
		jQuery.getJSON("/favorite/off/?callback=?&idFavorite="+this.id+'&type='+this.type, function(dataJSON){
			if(dataJSON.STATUS=='OK'){
				Favorite.element.removeClass("favorite_on").removeClass("favorite_off").removeClass("favorite_loading");
				if(Favorite.element.hasClass("favorite_on_tiny") || Favorite.element.hasClass("favorite_off_tiny") ){
					Favorite.element.removeClass("favorite_on_tiny").removeClass("favorite_off_tiny");
					Favorite.element.addClass("favorite_off_tiny");
				} 			
				Favorite.element.addClass("favorite_off");
				Favorite.element.text(Favorite.elementText);
				Favorite.init();
				
			}
		});	
		
	}	
}

Favorite.init();
