var Vevo=window.Vevo||{};Vevo.Favorites=(function(){var SERVICE=Vevo.Proxy.Favorites;function getFavorites($nodes){var favorites={video:[],artist:[],playlist:[],channel:[]};
$nodes.each(function(i,nodeObj){var rel=$(nodeObj).attr("rel").split(":"),fav=favorites[rel[0]];if(typeof fav!=="undefined"){var idx=fav.length,id=rel[1];if($.inArray(id,fav)<0){fav.push(id)
}}});if(favorites.video.length>0){SERVICE.getFavorites(favorites.video,"video")}if(favorites.artist.length>0){SERVICE.getFavorites(favorites.artist,"artist")}if(favorites.playlist.length>0){SERVICE.getFavorites(favorites.playlist,"playlist")
}if(favorites.channel.length>0){SERVICE.getFavorites(favorites.channel,"channel")}}function hoverOn(ev){var t=$(this);t.find(".favorData").addClass("ui-hide");if(t.hasClass("un-favoritable")){t.find(".favorClear").removeClass("ui-hide")
}else{t.find(".favorTip").removeClass("ui-hide")}}function hoverOff(ev){var t=$(this);t.find(".favorData").removeClass("ui-hide");t.find(".favorTip, .favorClear").addClass("ui-hide")
}return{init:function(e,user){var $favoritable=$(".favoritable").hover(hoverOn,hoverOff);$favoritable.find(".favorData").each(function(){$(this).text(Vevo.Util.formatNum($(this).text(),true))
});if(Vevo.user.isLoggedIn){getFavorites($favoritable);$(Vevo).bind("updatedFavorite",function(e,obj){var $this=obj.$node;$this.each(function(i,t){var $t=$(t);$t.toggleClass("un-favoritable");
var fav;if($t.hasClass("un-favoritable")){$t.attr("title",$t.attr("title").replace("favor","unfavor"));fav=1}else{$t.attr("title",$t.attr("title").replace("unfavor","favor"));
fav=-1}var $favData=$t.find(".favorData").removeClass("ui-hide");$t.find(".favorTip, .favorClear").addClass("ui-hide");$favData.text(Vevo.Util.formatNum(Math.max(0,Number(Vevo.Util.formatNum($favData.text(),false))+fav),true))
})})}$favoritable.live("click",function(e){e.preventDefault();e.stopPropagation();if(Vevo.user.isLoggedIn){SERVICE.toggleFavorite(this)}else{Vevo.messageButNotLoggedIn.show("Favorites and Recommendations","You will need to be signed in to favorite or get recommendations.")
}})}}})();