	$(document).ready(function() {
		$("table.tabtable td.reg").hover(
			function() {
				$(this).addClass("tabon");
			},
			function() {
				$(this).removeClass("tabon");
			}
		);

		$(".clickable").each(function(data) {
			if ( $(this).is("tr") ) {
				//alert("found a tr that is clickable");
			} else {
				$(this).css("cursor","pointer");
				var link = $(this).attr("link");
				$(this).bind("click",function() {
					location.href = link;
				});
				$(this).bind("mouseover",function() {
					$(this).addClass("clickableHover");
				});
				$(this).bind("mouseout",function() {
					$(this).removeClass("clickableHover");
				});
			}		
		});
		$("tr.clickable td").each(function(data) {
			var link = $(this).parent().attr("link");
			if ( $(this).hasClass("useful") || $(this).hasClass("waiting") ) {
				$(this).bind("click",function() {
					dummy();
				});
			} else {
				$(this).css("cursor","pointer");
				$(this).bind("click",function() {
					location.href = link;
				});
			}
			$(this).bind("mouseover",function() {
				$(this).parent().addClass("clickableHover");
			});
			$(this).bind("mouseout",function() {
				$(this).parent().removeClass("clickableHover");
			});
		
		});
		$("tr.clickable th").each(function(data) {
			var link = $(this).parent().attr("link");
			if ( $(this).hasClass("useful") || $(this).hasClass("waiting") ) {
				$(this).bind("click",function() {
					dummy();
				});
			} else {
				$(this).css("cursor","pointer");
				$(this).bind("click",function() {
					location.href = link;
				});
			}
			$(this).bind("mouseover",function() {
				$(this).parent().addClass("clickableHover");
			});
			$(this).bind("mouseout",function() {
				$(this).parent().removeClass("clickableHover");
			});
		
		});
		$("#fader").css("height", $(document).height()).css("width", $(document).width())
	});

	function dummy() {
		// do nothing
	}
	
	function doUseful(id, use, type) {
		$("#uses" + id).html("thank you<br /><span class=\"muted\">we will update our info</span>");
		sendUseful(id,use,type);
	}
	
	function sendUseful(id,use,type) {
		$.post(
			"/axj/",
			{
				action: "isUseful",
				type: type,
				id: id, 
				use: use
			},
			function (data) {
				//alert("here");
			},
			"json"
		);
	}

	function isUseful(id, use) {
		doUseful(id, use, "alt");
	}

	function isItUseful(id, use) {
		doUseful(id, use, "biz");
	}

	function showFader() {
		$("#fader").show();
	}
	
	function hideAll() {
		$("#fader").hide();
		$("div.popin").hide();
	}

	function doAnchor(item, anchor, orient) {
	        var offset = $("#" + anchor).offset();
	        var newTop = offset.top + $("#" + anchor).outerHeight() + 3;
	        var newLeft = offset.left;
	        if ( orient == "right" ) {
	        	newTop = offset.top - 40;
		        newLeft = offset.left + $("#" + anchor).outerWidth() + 3;
	        } else if ( orient == "leftunder" ) {
	        	//newTop = offset.top + $(";
		        //var newRight = offset.left + $("#" + anchor).width();
		        newLeft = offset.left - 300;
		        if ( newLeft < 10 ) {
		        	newLeft = 10;
		        }
		        newTop = offset.top + 10;
		        //alert("anchor has left of: " + offset.left + " and is " + $("#" + anchor).width() + " wide, so newright is: " + newRight);
		        //$("#" + item).css("position","absolute").css("top", newTop + "px").css("left","").css("right", newRight + "px");
		        //return;
	        }
	        $("#" + item).css("position","absolute").css("top", newTop + "px").css("left", newLeft + "px").css("right","");
	}

	function showLoading() {
		var ani = "";
		ani += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="100" id="gethuman" align="middle">';
		ani += '<param name="allowScriptAccess" value="sameDomain" />';
		ani += '<param name="movie" value="/logo/gethuman.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="/logo/gethuman.swf" quality="high" bgcolor="#ffffff" width="100" height="100" name="gethuman" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		ani += '</object>';
		return ani;
	}

	function isFF() {
		if ( navigator.userAgent.indexOf("irefox") >= 0 ) {
			return true;
		}
		return false;
	}

	function startPop(anchor, orient) {
		if ( isFF() ) {
			showFader();
		}
		doAnchor("gpop",anchor,orient);
		$("#gpop").html('<div class="loadanim" id="loadanim"></div><div class="loading" id="loading">loading...</div>');
		$("#loadanim").html(showLoading());
		$("#gpop").show();
	}
	
	function formLoaded() {
		$("#gpop input:first").focus();
		$("#gpop .focus:first").focus();
		$("#gpop .bad:first").focus();

	        var offset = $("#gpop").offset();
	        var right = offset.left + $("#gpop").width();
		if ( right > 990 ) {
			try {
				var diff = parseInt(right) - 990;
				var l = parseInt($("#gpop").css("left"));
				$("#gpop").css("right","").css("left",(l - diff));
			} catch (ignored) {}
		} else if (offset.left < 10 ) {
			$("#gpop").css("right","").css("left","10px");
		}
	}
	
	function addRecaptcha() {
		$("tr.recaptcha").show();
		Recaptcha.create("6LdhiQgAAAAAAB-2PKvUI_YTKzmgeVMOyMZ9PtC_",
			"recap",
			{
				theme: "custom",
				//callback: Recaptcha.focus_response_field
				callback: dummy
			}
		);
	}

	function addContact(anchor, bizId, altId, type, orient) {
		startPop(anchor,orient);
		loadAddContact(bizId, altId, type);
	}

	function loadAddContact(bizId, altId, type) {
		$("#gpop").load("/axj/addContact.html", "bizId=" + bizId + "&altId=" + altId + "&type=" + type, dummy);
	}
	
	function updateContact(anchor, bizId, altId, type, orient) {
		startPop(anchor,orient);
		loadUpdateContact(bizId, altId, type);
	}
		
	function loadUpdateContact(bizId, altId, type) {
		$("#gpop").load("/axj/updateContact.html", "bizId=" + bizId + "&altId=" + altId + "&type=" + type, dummy);
	}
	
	function doProblems(anchor, bizId, altId, type, orient) {
		startPop(anchor,orient);
		$("#gpop").load("/axj/doProblems.html", "bizId=" + bizId + "&altId=" + altId + "&type=" + type, dummy);
	}

	function doUseless(anchor, bizId, altId, type, orient) {
		sendUseful(altId, 'useless', 'alt');
		doProblems(anchor, bizId, altId, type, orient);
	}
	
	function addRating(anchor, bizId, altId, type, orient) {
		startPop(anchor,orient);
		loadAddRating(bizId, altId, type);
	}

	function loadAddRating(bizId, altId, type) {
		$("#gpop").load("/axj/addRating.html", "bizId=" + bizId + "&altId=" + altId + "&type=" + type, dummy);
	}
	
	function addTip(anchor, bizId, altId, type, orient) {
		startPop(anchor,orient);
		loadAddTip(bizId, altId, type);
	}
	
	function loadAddTip(bizId, altId, type) {
		$("#gpop").load("/axj/addTip.html", "bizId=" + bizId + "&altId=" + altId + "&type=" + type, dummy);
	}
	
	function showCopyLink(link) {
		$("#linktopage").toggle();
		$("#currenturl").focus();
		$("#currenturl").select();
	}
