var trunk = "";
var popup;
var lastLogo;
function toggle_search() {
	if ($("#moreoptions").is(':visible')) {
		$("#moreoptions").slideUp("normal");
		$("#optiontext").html("more search options");
	} else {
		$("#moreoptions").slideDown("normal");
		$("#optiontext").html("fewer search options");
	}
}
function get_wonk_list(url, head, pie, capt) {
	//because of IE caching idiocy...
	url = url + "&amp;uncacheme=" + Date();
	var seemore = "(<a href=\"javascript:get_wonk_list('" + url +"', '"+head+"')\">see more, if available...</a>)";
	$.ajax({
		type: "GET",
		url: url,
		global: false,
		beforeSend: function(msg){
			$("#listdisplay").fadeOut("slow");
			ajax_overlay.load();
		},
		success: function(msg){
			if (msg.length > 0) {
				if (pie) {
					pie = "<img src='http://chart.apis.google.com/chart?chf=bg,s,FDFCE8&cht=p&chs=400x125&chco=FF9900,66FF00,0066FF,00FF99&chd=t:"+pie+"'>";
					capt = "<p>" + capt;
				} else {
					pie = "";
					capt = "";						
				}
				$("#listdisplay").html("<p><i class=smalltext>" + pie + capt + "</i><p><b>" + head + "</b>" + seemore + "<p>" + msg);
			} else {
				$("#listdisplay").html("<b>No matches found!  (Or data has expired.)</b>");
			}
		},
		complete: function(msg){
			ajax_overlay.close();
			$("#listdisplay").fadeIn("slow", function () {
				wonk_highlights();
				do_highlights();
			});
		}
	});
}
function get_username(){
	$.ajax({
		type: 'GET',
		url: "/" + trunk + "user_name",
		dataType: 'html',
		success: function(html, textStatus){
			$("#signin").html("signed in as " + html + ' <a href="/' + trunk + 'logout">logout</a>');
		},
		error: function(xhr, textStatus, errorThrown){
			$("#authorize_done").css("display", "none");
			$("#signin form").enable;
		},
	});
}
function wonk_highlights() {
	$("img.youfollow").attr("title", 'You currently follow this person.');
	$("img.theyfollow").attr("title", 'This person currently follows you.');
	$("img.theydontfollow").attr("title", 'This person currently does NOT follow you.');
	$("img.youdontfollow").attr("title", 'You currently do NOT follow this person.');
}
function swap_logo() {
	if (lastLogo) {
		$("#logo").attr("src","followerwonk22b.png");
		lastLogo = 0;
	} else {
		$("#logo").attr("src","followerwonk22.png");
		lastLogo = 1;			
	}
}
function get_associates(what, url) {
	//AJAX call required the first time opening this
	var other;
	if (what == "fr") {
		other = "fl";
	} else {
		other = "fr";
	}
	if ($("#" + what +"top").length) {
		$("#" + other + "top").slideUp("slow", function() {
			$("#" + what + "top").slideDown("slow");
		});
	} else {
		//because of IE caching idiocy...
		url = url + "&uncacheme=" + Date();
		$.ajax({
			type: "GET",
			url: url,
			global: false,
			beforeSend: function(msg){
				$("#" + other + "top").slideUp("slow");
				ajax_overlay.load();
			},
			success: function(msg){
				$("#" + what + "holder").html(msg);
				$("#" + what + "holder").slideDown("slow");
			},
			complete: function(msg){
				ajax_overlay.close();
			}
		});
	}
}
$(document).ready(function () {
	$("#logo").live("mouseover", function() {
		swap_logo();
	});
	$(".tabbable").livequery("click", function() {
		$(".tabbableSelected").toggleClass("tabbable");
		$(".tabbableSelected").toggleClass("tabbableSelected");

		$(this).toggleClass("tabbable");
		$(this).toggleClass("tabbableSelected");

		var toShow = $(this).attr("id");
		$(".tabContent:visible").hide("blind", {}, "slow", function() {
			$("#tab_" + toShow).show("clip", {}, "slow");
		});
	});
	popup = shindig.oauth.popup({
		destination: $("#signin form").attr("action"),
		windowOptions: "height=400,width=780,status=1,location=1,resizable=1",
		onOpen: function(){
//			$("#authorize_done").css("display", "block");
		},
		onClose: function(){
			//var user = get_username();
			window.location = window.location;
		}
	});
	$("#signin form").submit(popup.createOpenerOnClick());
	$("#authorize_done").onclick = popup.createApprovedOnClick();
	wonk_highlights();
});

