$(document).ready(function(){

	$("input, textarea").focus(function(){this.select();});
	
	$('.menu').localScroll();
	
	$('.submenu a').click(function() {
		$('.publicationsSlider').html('<img src="http://www.willemvanschendel.com/wp-content/themes/willemvanschendel/ajax/ajax-loader.gif" width="16" height="16" alt="Loading...">');
		$('.submenu a').removeClass("selected");
		$(this).addClass("selected");
		var name = $(this).attr('title');
		if(name == 'Books') {
			$('.publicationsSlider').load("http://www.willemvanschendel.com/wp-content/themes/willemvanschendel/ajax/loadPublications.php",{cat: 1});
			$('#subPublications').html(name);
		} else if (name == 'EditedVolumes') {
			$('.publicationsSlider').load("http://www.willemvanschendel.com/wp-content/themes/willemvanschendel/ajax/loadPublications.php",{cat: 3});
			$('#subPublications').html('Edited volumes');
		} else if (name == 'Chapters') {
			$('.publicationsSlider').load("http://www.willemvanschendel.com/wp-content/themes/willemvanschendel/ajax/loadPublications.php",{cat: 4});
			$('#subPublications').html(name);
		} else if (name == 'Articles') {
			$('.publicationsSlider').load("http://www.willemvanschendel.com/wp-content/themes/willemvanschendel/ajax/loadPublications.php",{cat: 5});
			$('#subPublications').html(name);
		}
		return false;
	});
	
	$('a.readmoreButton').live('click', function(event) {
		if(jQuery.browser.msie && jQuery.browser.version <= 7) {} else {
			$("#backModal").show();
			$('#modalWindow').html('<img src="http://www.willemvanschendel.com/wp-content/themes/willemvanschendel/ajax/ajax-loader.gif" width="16" height="16" alt="Loading...">');
			var mijnUrl = $(this).attr('href');
			$('#modalWindow').load(mijnUrl).show();
			return false;
		}
	});
	
	$('.jqmClose').live('click', function(event) {
		$('#modalWindow').html('');
		$('#modalWindow').hide();
		$("#backModal").hide();
		return false;
	});
	
	$('.nextPage').live('click', function(event) {
		$('#booksContent').html('<img src="http://www.willemvanschendel.com/wp-content/themes/willemvanschendel/ajax/ajax-loader.gif" width="16" height="16" alt="Loading...">');
		$('.nextPage').attr('id','');
		$(this).attr('id','nextPageSelected');
	  	var offset = parseInt($(this).attr('name'));
	  	var cat = $(this).attr('title');
		$.ajax({
			type: "POST",
			url: 'http://www.willemvanschendel.com/wp-content/themes/willemvanschendel/ajax/get_posts.php',
			data: "cat="+cat+"&offset="+offset,
			success: function(msg){
				$('#booksContent').hide();
				$('#booksContent').html(msg).fadeIn();
			}
		});
		return false;
	});
	
	

	$("#searchForm").keypress(function(e) {if (e.which == 13) {return false;}});

	$('#searchSubmit').click(function(){
		$('.publicationsSlider').html('<img src="http://www.willemvanschendel.com/wp-content/themes/willemvanschendel/ajax/ajax-loader.gif" width="16" height="16" alt="Searching...">');
		$('.submenu a').removeClass("selected");
		var zoekterm = $('#searchText').val();
		$.ajax({
			type: "POST",
			url: 'http://www.willemvanschendel.com/wp-content/themes/willemvanschendel/ajax/search-results.php',
			data: "zoekterm="+zoekterm,
			success: function(msg){
				$('.publicationsSlider').html(msg).fadeIn('fast');
			}
		});
		return false;
	});
	
	$("#slider").easySlider({
			auto: true,
			continuous: true,
			nextId: "toRight",
			nextText: "",
			prevId: "toLeft",
			prevText: "",
			speed: 1500,
			pause: 4000
	});
	
});
