//Expand and collapse an area
function toggleBox(cur)
{
	//Close all rows
	$(".row .content:not('#" + cur + "')").hide();
	
	//Remove all versions of the video class
	$(".video").remove();
	
	//Change the open/close image of all rows
	$(".row .heading").children().removeClass();	
	$(".row .heading").children().addClass('open');	
	
	//Open our row
	$("#" + cur).show();
	
	//Change the open/close image of our row
	$("#" + cur).siblings(".heading").children().removeClass();	
	$("#" + cur).siblings(".heading").children().addClass('close');	
}


//Add a video to the target div's parent.
function showVideo(tar)
{
	var link = $(tar).attr("href");
	$.ajax({
		type: 	"GET",
		url:  	link, 
		success: function(ret)
		{
			//Remove all versions of the video class
			$(".video").remove();
			
			//Add the video div
			$(tar).parent().append("<div class='video'>" + ret + "</div>");
		}
	});
}


//When the page loads, add IDs to elements and onclicks to 
$(document).ready(function()
{
	//Add an ID to each row
	$(".row .content").each(function(index)
	{
		$(this).attr("id", index);
		$(this).siblings(".heading").click(function()
		{
			toggleBox(index);
		});
		$(this).children("div").each(function(ind)
		{
			$(this).children("a").click( function(){ showVideo(this); return false; } );
		});		
	});
	

	//Close all rows
	$(".row .content").hide();
});
