



	/**
	 * add _r to all functions just so that there is no confusion. javascript can be nasty.
	 */

$(document).ready(function(){
	$("div.tree").toggle(
			function(ev){openTree(ev);},
			function(ev){closeTree(ev);});
	
	function openTree(ev) {
		var id = ev.currentTarget.id; 
		 $("#" + id).addClass("open");
		 if ($("#" + id + "-children").length > 0) {
			 $("#" + id + "-children").show();
		 } else {
			 var oid = id.split("-")[2];
			 var elId = id + "-children"
			 $("#" + id + "-container").append("<div id='" + elId + "'><img src='/images/wait.gif'></div>");
			 $.get("/ajax/subcat.r/" + oid, null,  function(data){displayContents("#" + elId, data);}, "html");
		 }
	}

	function closeTree(ev) {
		var id = ev.currentTarget.id;
		$("#" + id).removeClass("open");
		$("#" + id + "-children").hide();
	}
	
	function displayContents(selector, contents) {
		$(selector).html(contents);
		$(selector + " div.tree").toggle(
				function(ev){openTree(ev);},
				function(ev){closeTree(ev);});
	}
	
	

	
});

(function($) {

	return;

	var t;
	var timer_is_on=0;
	
	function getImage() {
		$.getJSON("/comments/cmt1/", 
		//$.post("/comments/cmt1/", {thread_id:"1234"},	
		        function(data){
		          $.each(data.items, function(i,item){
		            $("<div/>").html(item.msg).appendTo(".bobob");
		            if ( i == 3 ) return false;
		          });
		        });
	}
	
	
	/**
	 * For now I'm using a timer to poll every 10 seconds. Ultimately we want to do
	 * something more along the lines of what meebo does - hold open the connection
	 * on the server side and push. 
	 */
	function getLatestComments() {
		$.post("/comments/cmt1/", {thread_id:"1234"},
				function(data) {
					$(".bobob").html(data);
					t=setTimeout("$.fn.timedCount()",10000);
				}
			);
	}

	$.fn.timedCount = function() {
		getLatestComments();
	}

	function doTimer() {
		if (!timer_is_on) {
			timer_is_on=1;
			$.fn.timedCount();
		}
	}

	$.fn.getComments_r = function() {
		//doTimer();
		getImage();
	};
	
	
		
	
	
})(jQuery);	