var file_name;
var xmlhttp;

/**
 * Get the list of years
 */
function get_list_years() {
	
	
	if (window.XMLHttpRequest) {
		//alert("Inside the if statement for the get_list_years method");

		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	//alert("now about to bind the handler");
	// bind the change in state event to the event using an anomomous function
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			//Insert response text into the html document
			var r=xmlhttp.responseText;
			$("#reviews_short").html(r);
			bind_review_year_click();
		} ;
	}
		//alert("about to open the connection");

	xmlhttp.open("GET", "includes/build_reviews.php?m=8", true);
		//alert("about to send the request");

	xmlhttp.send();
}

/**
 * Read the current URL and set the link to the class that identifys
 * the current page item.
 */
function set_current_page_item(path) {
	// strip out the path, get just the file name
	var folders = path.split("/");
	file_name = folders[folders.length-1];

	// Get the list of navigation items
	$("#menu a").each( function() {
		if(file_name == $(this).attr("href") || (file_name == "" && $(this).attr("href") == "index.php")) {
			return $(this).addClass("current_page_item");
		}
	});
}

function set_the_review(list_element){
	
}

/**
 * Bind event handlers to the click events for each list item
 */
function bind_review_year_click(){


	//alert($("#reviews_short").html());
//	$("#reviews_short li.year").each(function(){
		//alert("Binding the review - should have a review year: " + $(this).attr("href") );
		// bind the click event
//		$(this).click(function(){
//			alert($(this).html());
			// Start here  Need to make the script to handle this
			//$(this).load("");
//			$(this).append("<ul><li class=\"month\">test 1</li><li class=\"month\">test 2</li></ul>");
//			bind_review_month_click();
//		});
//	})
}

/**
 * Bind event handlers to the click events for each list item
 */
function bind_review_month_click(){
	//alert($("#reviews_short").html());
	$("#reviews_short li.month").each(function(){
		//alert("Binding the review - should have a review year: " + $(this).attr("href") );
		// bind the click event
		$(this).click(function(){
			alert($(this).html());
			// Start here  Need to make the script to handle this
			//$(this).load("");
			$(this).append("<ul><li class=\"entry\">test Month 1</li><li class=\"entry\">test Month 2</li></ul>");
		});
	})
}
/**
 * initialization of the javascript
 */
$(document).ready( 
	function() {
		set_current_page_item(window.location.pathname);
	
		// if we are on the review page, get a list of the years
		// from the db and display them
		if(file_name == "review.php") {
			//get_list_years();
			//$('#reviews_short').load("includes/build_reviews.php?m=8");
			
			//$('#reviews a').addClass('jqcNode');
			
		//	$("#the_header").css("visibility","visible");
			
			// set up the collapsable list 
			$('#review_summary').jqcollapse({	
			   slide: true,
			   speed: 1000,
			   easing: 'easeOutCubic'
			});
			
		/*	*/
		}
		//else{
			//$("#the_header").css("visibility","hidden");
		//}
		
})
