function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
$(function(){
	var themes = ["white", "yellow", "blue"],
		fonts = ['Helvetica', 'Georgia', 'Verdana'],
		markup = [], i = 0, u=0;
		markup.push('<ul class="theme-picker">');
		while(i<themes.length){
			markup.push('<li class="'+themes[i]+'"><span>'+themes[i]+'</span></li>');
			i++;
		}
		markup.push('</ul><ul class="font-picker">');	                
		while(u<fonts.length){
			markup.push('<li class="'+fonts[u]+'"><span>'+fonts[u]+'</span></li>');
			u++;
		}
		markup.push('</ul>');	                
		
	$('<div>').attr('id', 'designer').html(markup.join('')).appendTo('#bookshelf');
	$('.theme-picker li').click(function(ev){    
		document.cookie = "color="+$(this).attr('class')+"; path=/";
		$(this).siblings().removeClass('selected');
		$(this).addClass('selected');
		$('body').removeAttr('class').addClass($(this).attr('class')+' '+$('.font-picker li.selected').attr('class'));
	}); 
	$('.font-picker li').click(function(ev){    
		document.cookie = "font="+$(this).attr('class')+"; path=/";
		$(this).siblings().removeClass('selected');
		$(this).addClass('selected');
		$('body').removeAttr('class').addClass($(this).attr('class')+' '+$('.theme-picker li.selected').attr('class'));;
	}); 

		topics = [];
	    topics.push('<ul class="topic-list">');
	$('#content_container').find('.project_title').each(function(k,v){
		var link = $(v).text().replace(/\s/g,'_'),
			name = $(v).text()
		$(v).attr('id', link);
		topics.push('<li><a href="#'+link+'">'+name+'</a></li>');
	})
	topics.push('</ul>');
	$('#bookshelf').prepend(topics.join(''));   
   if(readCookie('color')){
		$('.theme-picker li.'+readCookie('color')).trigger('click');
	} 
   if(readCookie('font')){
		$('.font-picker li.'+readCookie('color')).trigger('click');
	} 
	
});