function moveDwarves(){
	$('img.dwarf').each(function(){
		
		offset = $(this).offset();
		
		if ( $(this).data('xc') && $(this).data('yc') ){
			
			if ( 
					( offset.left >= $(this).data('xc') - 20 && offset.left <= $(this).data('xc') + 20 )
				&& 
					( offset.top >= $(this).data('yc') - 20 && offset.top <= $(this).data('yc') + 20 )
			 ){
			
				$(this).removeData();
				
			} else {
			
				switch(Math.floor(Math.random()*2)){
					case 0:
						console.log('xdest: '+$(this).data('xc')+', x: '+offset.left);
						if ( $(this).data('xc') > offset.left ){
							move = offset.left + 8;
							$(this).css('left', move+'px');
						} else {
							move = offset.left - 8;
							$(this).css('left', move+'px');
						}
						break;
					case 1:
						console.log('ydest: '+$(this).data('yc')+', y: '+offset.top);
						if ( $(this).data('yc') > offset.top ){
							move = offset.top + 12;
							$(this).css('top', move+'px');
						} else {
							move = offset.top - 12;
							$(this).css('top', move+'px');
						}
						break;
					default:
						return false;
				}
				
			}
			
		} else {
		
			//Decide to move or loiter
			switch(Math.floor(Math.random()*2)){
				case 0:
					//pick a random spot to walk to
					$(this).data( 'xc', Math.floor(Math.random()*$(document).width()) );
					$(this).data( 'yc', Math.floor(Math.random()*$(document).height()) );
					break;
				case 1:
					//Loiter
					switch(Math.floor(Math.random()*4)){
						case 0:
							move = offset.top - 12;
							if ( move > 0 ){
								$(this).css('top',move+'px');
							}
							break;
						case 1:
							move = offset.left + 8;
							if ( move > 0 ){
								$(this).css('left',move+'px');
							}
							break;
						case 2:
							move = offset.top + 12;
							if ( move > 0 ){
								$(this).css('top',move+'px');
							}
							break;
						case 3:
							move = offset.left - 8;
							if ( move > 0 ){
								$(this).css('left',move+'px');
							}
							break;
						default:
							return false;
					}
					break;
				default:
					return false;
			}
			
		}
		
	});
}

$(function(){
	
	$('ol#work').cycle({
		timeout: 8000
	});
	
/*
	$('ul#testimonials').cycle({
		fx: 'scrollLeft',
		timeout: 0,
		next: '.next_quote'
	});
*/
	
	konami = new Konami()
	konami.code = function() {
		
		$('body').addClass('df');
		for (i=1;i<=13;i++){
			$('body').append('<img src="interface/images/dwarf'+i+'.png" alt="A Dwarf" class="dwarf" />');
		}
		$('img.dwarf').each(function(){
			$(this).offset({top: Math.floor(Math.random()*$(document).height()), left: Math.floor(Math.random()*$(document).width())});
		});
		setInterval("moveDwarves()",500);
		
	}

	konami.load()
	
});
