if (window["console"] === undefined)
{
    window["console"] = function() {};
    console.log = function() {};
}




// Show and Hide Functions
$(function(){
	var showContent = function(handle, content, callback) {

		$(content).slideDown("slow", function(){
			$(content).focus();
			if (callback) {
				callback();
			}
		});
		$(handle).addClass('active');
	};

	var hideContent = function(handle, content, callback) {
		console.log("hideContent");
		$(content).slideUp("slow", function(){
			if (callback) {
				callback();
			}
		});
		$(handle).removeClass('active');
	};
	
	// Open First Tab on load
		var activeHandleFirst = $("#menuWrapper a:first");
		var activeContentFirst = $(activeHandleFirst).next(".content");
		console.log(["First content", $(activeContentFirst).length]);
		showContent(activeHandleFirst, activeContentFirst);
		
		
	// Click Event 
	$("#menuWrapper a.handle").click(function(e){
		var handle = $(this);
		var content = $(handle).next(".content");
		
		if ($(content).is(":visible")) {
			hideContent(handle, content);
		}
		else {
			console.log(["length", $("#menuWrapper a.active").length]);
			if ($("#menuWrapper a.active").length > 0) {
				var activeHandle = $("#menuWrapper a.active:first");
				var activeContent = $(activeHandle).next(".content");
				hideContent(activeHandle, activeContent, function(){
					showContent(handle, content);
				});
			}
			else {
				showContent(handle, content);
			}
		}
	
		return e.stopPropagation();
	});
});