;(function($) {
	$.tvprogram = {
		switchFavorite : function(target){
		    var it = $(target);
		    var link = it.attr("href");
		    $.get(link,{ ajax : 1,rnd : Math.random() });
		    if(it.hasClass("add-fav")){
			it.addClass("del-fav").removeClass("add-fav");
			it.html("<i></i>Удалить из избранных");
			it.attr("href",link.replace(/\/add\//,"/remove/"));
		    }else{
			if(window.location.href.indexOf("favorites")>=0){
			    it.parents("li:first").replaceWith("");
			    $("ul.feed").find('li:first').addClass('first');
			    if($("ul.feed").find('li:first').length == 0){
			    	if($("#pager").length != 0)
			    		window.location.href = "http://tvprogram.uaprism.com/favorites?"
			    	else{
				    $(".def-fav").css("display","block");
			    	    $("ul.feed").replaceWith('');
				}
			    }
			}else{
			    it.addClass("add-fav").removeClass("del-fav");
			    it.html("<i></i>Добавить в избранные");
			    it.attr("href",link.replace(/\/remove\//,"/add/"));
			}
		    }
		},
		chanSelect:function(e){
		    window.location = e.value;
		}
	};
	$(document).ready(function(){
	    $(".add-fav, .del-fav").click(function(){
	        $.tvprogram.switchFavorite(this);
		return false;
	    })
	    $(".button").hover(
		    function(){
			$(this).addClass("btn-hover");
		    },function(){
		     $(this).removeClass("btn-hover");
	    });
	    $(".save .button").click(function(){
		var s = ";";
		$(".chan-list input:checkbox[@checked]").each(function(){s+=this.value+";";});
		$.post("/favorites/settings",{ajax : 1, fav:s}, function(data){window.location="/favorites";});
	    });
	});
})(jQuery);
