if(code404 == undefined) var code404 = new Object();

code404.absUrl = 'http://code404.net';
code404.shortcutsDisabled = false;

code404.nextItem = function(href){
	if(href != undefined){
			jQuery('#content').hide();
			jQuery('#content').load(href, function(){
				code404.retrigger();
				jQuery('#content').fadeIn('fast');				
			});

			return false;		
	}
}

code404.previousItem = function(href){
	if(href != undefined){
			jQuery('#content').hide();
			jQuery('#content').load(href, function(){
				code404.retrigger()
				jQuery('#content').fadeIn('fast');				
			});

			return false;		
	}
}
code404.retrigger = function(){
	jQuery('div#container div#content .post .details').css('display', 'none');
	jQuery('.alignleft a:first').click(function(){
		var href = this.href;
		code404.nextItem(href);
		return false;		
	});

	jQuery('.alignright a:first').click(function(){
		var href = this.href;
		code404.previousItem(href)
		return false;		
	});

	jQuery('div#container div#content .post .showDetails').click(function(){
		jQuery('div#container div#content .post .details').fadeIn('slow');
	});
}

jQuery(document).ready(function() { 
	code404.retrigger();
	
	jQuery('#s').attr('value', 'Suchbegriff');
	jQuery('#s').blur(function(){
		jQuery('#s').css('background','#cecece')
		if(this.value == ''){
			this.value = 'Suchbegriff';
		}
	});
	jQuery('#s').focus(function(){
		jQuery('#s').css('background','#fff')
		if(this.value == 'Suchbegriff'){
			this.value = '';
		}
	});
	
	jQuery(document).keydown(function(e){
		var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
		switch(key){
			case 37:
			if(code404.shortcutsDisabled == false){
				var href = jQuery('.alignleft a:first').attr('href');
				code404.nextItem(href);
				return false;
			}
			break;
			case 39:
			if(code404.shortcutsDisabled == false){
				var href = jQuery('.alignright a:first').attr('href');
				code404.previousItem(href)
				return false;
			}
			break;
		}
	});

	jQuery('a[rel="Search"]').click(function(){
		jQuery('#s').trigger('focus');
		window.scrollBy(0, 100000);
		return false;
	});
	
	jQuery('input').focus(function(){
		code404.shortcutsDisabled = true;
	});
	
	jQuery('input').blur(function(){
		code404.shortcutsDisabled = false;
	});
	
	jQuery('textarea').focus(function(){
		code404.shortcutsDisabled = true;
	});
	
	jQuery('textarea').blur(function(){
		code404.shortcutsDisabled = false;
	});
	
});
