jQuery.fn.rotate_arrow = function(the_html, sub_ul, o){
	// this evaluates the current position of the arrow.  simply if it is down,
	// present the arrow to the left and vice versa.
	if(the_html.html() == '▼&nbsp;'){
		// &#9658;&#160; left arrow
		the_html.html('&#9658;&#160;');
	}else{
		// &#96560&#160; down arrow
		the_html.html('&#9660;&#160;');
	}	
	
	// go ahead and display or hide the matched elements w/ a sliding motion
	sub_ul.slideToggle(o.speed, o.easing);
};

jQuery.fn.jqcollapse = function(o) {
 
 // Defaults
 var o = jQuery.extend( {
   slide: true,
   speed: 300,
   easing: ''
 },o);
var the_content = $(this).find('#content .post');

$(this).each(function(){
	 
	 var e = $(this).attr('id');	// This will set review_summary as the id selector
	 
	 // This will select all ul element selectors whose parent is a li.  This is restricted
	 // 	only to ul items in the review_summary list.
	 $('#'+e+' li > ul').each(function(i) { // Now iterate through each item
	    var parent_li = $(this).parent('li'); // get the parent list item to the ul currently evaluating
	    var sub_ul = $(this).remove(); 	// remove the child ul from the current DOM
    	// Get the info we need from the click event for populating the content area
	    
	    // isolate the arrow so that I can change its orientation and expand/collapse the list
        var the_arrow = parent_li.find('a.arrow span');
    	the_arrow.click(function(){jQuery.fn.rotate_arrow(the_arrow, sub_ul, o)});
    	
    	/** 
    	*   find the class data in the anchor tag for the parent list item, then
    	*	add the class jqcNode, change the cursor to a pointer, then 
    	*		1. add an event handler to the click event for the anchor tag,
    	* 		2. Parse the data in href attribute so that I can pass it to the server for qry processing
    	* 		3. Display the content items in the content id section
    	*/
	    parent_li.find('a.data').addClass('jqcNode').css('cursor','pointer').click(function() {
	        // check to see if the easing extension is true
        	jQuery.fn.rotate_arrow(the_arrow, sub_ul, o);
        	
        	// set up the variables I'll need to pass the url string
	    	var month_number = -1;
	    	var review_year = 0;
	    	var review_lang = "english"
	    	var month_name = "";
	    	
	    	// This var takes the content of the href attrib because it holds the data that I
	    	//	will be passing to the server: pattern is: #year || #month#year
        	var data_href=$(this).attr('href').split('#');
        	
        	// if only two elements in the array, I know that only the year was queried (#year)
        	// otherwise the month was queried along with the year (#month#year)
        	if (data_href.length==2) {
        		review_year=data_href[1];
         	} else{
        		month_number=data_href[1];
        		review_year=data_href[2];
        		month_name = $(this).html();
        	};
        	
	    	// make the call to the server and insert the value returned into 
	    	// the html - specifically the #content .post portion of the page 
 	 		$('#content .post').load("includes/build_reviews.php?num_month="+month_number+
				"&text_month="+month_name+"&rev_year="+review_year+
				"&rev_lang="+review_lang+"&r_id=-1");
	   		
	   	}); 	// end the event handler for a.data

	    // put the sub_ul elements back in the DOM after manipulation
	    parent_li.append(sub_ul);
	});
	
	/**
	 * Now get the leaf nodes of the list.  These items will be displayed signularly in the content 
	 * window.  
	 */
	$('a.leaf').click(function(){
		// Get the review id from the url so that can pass it to server
		var rev_id = $(this).attr('href').split('#'); 
    				
    	// make the call to the server and insert the value returned into 
    	// the html - specifically the #content .post portion of the page 
    	$('#content .post').load("includes/build_reviews.php?num_month=-1&"+
    		"text_month=\"\"&rev_year=-1&rev_lang=\"english\"&r_id="+rev_id[1]);
	});
    
	//Hide all sub-lists when the page is first loaded
	 $('#'+e+' ul').hide();
 });
};

