
$(document).ready(function() {
	
	/// URL parse
	var what = $.url.segment(0);
	var which = $.url.segment(1);
	if (which != null) {
		if (what == "news") {
			$("#news").addClass('showme');
		} else if (what == "project") {
			$("#project_"+which+"").parent().addClass('showme');
			$('.section-title.category').addClass('showcats');
		}
	}
	$('#thenews, #thework').nextAll().add(".category, .project, .infoitem").hide();
	show_what_you_know();
	
});

function show_what_you_know() {
	$(".showme").find("li").slideDown(200);
	$('.showcats').show(200);
}

var UNCLICKED = true;

function thework_click() {
	if (UNCLICKED) {
		$(".category, .project").slideDown(200);
	} else {
		$(".category, .project").slideUp(200);
	}
	UNCLICKED = !UNCLICKED;
	setCookie('move', document.getElementById('menu').scrollTop, 1);
}

function thelatest_click() {
	$("#menu ul").each(function() {
		$(this).find(".newsmorsel").slideToggle(200);
	});
	setCookie('move', document.getElementById('menu').scrollTop, 1);
}

function theinfo_click() {
	$("#menu ul").each(function() {
		$(this).find(".infoitem").slideToggle(200);
	});
	setCookie('move', document.getElementById('menu').scrollTop, 1);
}

function category_click(catpk) {
	$("#cat_"+catpk).nextAll().slideToggle(200);
	setCookie('move', document.getElementById('menu').scrollTop, 1);
}


///
/// copied wholesale from ndxz cookie.js
///

/*
function move_up() {
	var move = getCookie('move');
	if (move == '') {
		return false;
	}
	
	//var menu = document.getElementById('menu');
	//menu.scrollTop = move;
	$('#menu').hide().animate({
		opacity: 1.0,
		scrollTop: move
	}, {
		queue: false,
		duration: 100
	});
}


function do_click()
{
	moved = document.getElementById('menu');
	moved = moved.scrollTop;
	
	// record the cookie
	setCookie('move', moved, 1);
}

function getCookie(c_name)
{
	if (document.cookie.length > 0)
	{
		c_start = document.cookie.indexOf(c_name + "=")

		if (c_start != -1)
		{ 
			c_start = c_start + c_name.length + 1 
			c_end = document.cookie.indexOf(";", c_start)
			
			if (c_end == -1) c_end = document.cookie.length
			return unescape(document.cookie.substring(c_start, c_end))
		} 
	}
	return 0;
}

function setCookie(c_name,value,expiredays)
{
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name + "=" + escape(value) +
	((expiredays==null) ? "" : ";expires=" + exdate.toGMTString()) + '; path=/';
}


*/