$(document).ready(function(){

	// Load the initial Favorites Tab
	$("#View_News").load("ajax/asendfeed.php?cat=Favorites");
	
	// Handle the tabs, loading the appropriate categories
	$(".ui-tabs-nav li>a").click(function(){
		$("#View_News").load($(this).attr("href"));
		$(".ui-tabs-nav li").each(function () {
			$(this).removeClass("ui-tabs-selected");
		});
		$(this).parent().addClass("ui-tabs-selected");
		return false;
	});
	
	// Handle Login Link
	$("a.login").click(function(){
		$(".hquote").toggle();
		$("#loginbox").toggle();
		return false;
	});
	
	// Save site as a favorite
	$("a.afav").livequery('click', function(){
		//ajax to save...then hide
		hidebox = $(this).parent();
		current = $(this);
		$.ajax({
			type: "GET",
			contentType: "application/json; charset=utf-8",
			dataType: "json",
			data: "s=" + $(this).attr("name") + "&a=s",
			url: "ajax/apin.php",
			success: function(json){
					json = eval(json);
						if(json.status == "added"){
							hidebox.hide("slow");
						} else if(json.status == "overlimit"){
							current.parent().parent().prepend("<span class='error'>" +json.error+ "</span>");
						}
			}
		});
		return false;
	});
	
	// Remove site from favorites
	$("a.dfav").livequery('click', function(){
		//ajax to delete...then hide
		hidebox = $(this).parent();
		$.ajax({
			type: "GET",
			contentType: "application/json; charset=utf-8",
			dataType: "json",
			data: "s=" + $(this).attr("name") + "&a=d",
			url: "ajax/apin.php",
			success: function(json){
				json = eval(json);
				if(json.status == "deleted"){
					hidebox.hide("slow");
				}
			}
		});
		return false;
	});
	
	//Swap feed box class on mouse in/out
	$("#View_News > div").livequery(function(){
			$(this).hover(function(){
				url = "url(/images/site/logos/" + $(this).attr("id") + ".png) 0 -50px no-repeat";
				$(this).removeClass("inactivesite");
				$(this).addClass("sitebox");
				$("#"+ $(this).attr("id") +" > h3").css("background", url);
				$(".sitebox a").tipTip();
			}, function(){
				url = "url(/images/site/logos/" + $(this).attr("id") + ".png) 0 0px no-repeat";
				$(this).removeClass("sitebox");
				$(this).addClass("inactivesite");
				$("#"+ $(this).attr("id") +" > h3").css("background", url);
		});
		},function(){
			$(this).unbind("mouseover");
			$(this).unbind("mouseout");
	});
	
	// Set Site Image when the feeds arrive
	$("div.inactivesite > h3").livequery(function(){
		url = "url(/images/site/logos/" + $(this).parent().attr("id") + ".png) 0 0px no-repeat";
		$(this).css("background", url);
		//$(this).text("");
	});
	
	// Add hover tooltips
	$(".today a").tipTip();
	$(".week a").tipTip();
		


// End JS
});
