var tags="";
var providerpath = "/applications/appnotes/provider.php";
$(document).ready(function() {
	//start off by loading a bunch of appnotes
	$("#displayarea").load(providerpath+"?max=10", PrepareAppnotes);
	
	// navigation
	$("a.appnavtitle").click(function () {
		// adjust checks
		$(this).parents("li").children("ul").children("li").children("a").children("img").attr("src", "/images/check_half.png");
		
		// adjust tags
		updatetags();
		
		// adjust content
		$("#displayarea").load(providerpath+"?tags="+tags, PrepareAppnotes);
	});
	
	
	$("a.appnavtag").click(function () {
		// adjust checks
		var thischeck = $(this).children("img").attr("src");
		
		if(thischeck == "/images/check_full.png")
		{				
			$(this).parents("li").siblings("li").children("a").children("img").attr("src", "/images/check_half.png");
			$(this).children("img").attr("src", "/images/check_half.png");
		}
		else
		{
			$(this).parents("li").siblings("li").children("a").children("img").attr("src", "/images/check_none.png");
			$(this).children("img").attr("src", "/images/check_full.png");
		}	
		
		// adjust tags
		updatetags();
		
		// adjust content
		$("#displayarea").load(providerpath+"?tags="+tags, PrepareAppnotes);
	});
	
	function updatetags() {
		tags = "";
		$("img[src$='check_full.png']").each( function () {
			tags += $(this).parent().text() + ", ";
		});
		
		tags = escape(tags);
	}
	
	function PrepareAppnotes() {
		$('.appnote').corner('10px');
		
		$('.appnote').click(function() {
			var url = $(this).children("a:first").attr("href");
			url = url.substring(url.indexOf('/applications/')); // IE<8 will mangle the href attribute to include
																// the full url even if it wasn't given in the html document.
																// this consistantly grabs starting with /applications/
			if(url !== undefined) {
				pageTracker._trackPageview(url);
				setTimeout("document.location='"+url+"'", 100);
				return false;
			}
		});
	}
});
