/*
 * KEYBRDR! AWESOMENESS BY MIKE HARMER
 * Version 2.0
 * Copyright (c) 2011 Mike Harmer - http://www.mikeharmer.co.uk
 *
 * License Agreement: By downloading Keybrdr,
 * you agree to that the copyright information 
 * must remain intact in the product.
 * 
 * You are not free to use, copy or sell any of the 
 * "keybrdr_main.js" (this file) code on your own
 * products without asking for permission.
 * 
 * Questions? mike@mikeharmer.co.uk
 */
 



$(document).ready(function() {
	
	
	
	
  	/* PREVENT FOUT IN FF */
  	
	var d = document, e = d.documentElement, s = d.createElement('style');
  	if (e.style.MozTransform === ''){ // gecko 1.9.1 inference
    s.textContent = 'body{visibility:hidden}';
    var r = document.getElementsByTagName('script')[0];
    r.parentNode.insertBefore(s, r);
    function f(){ s.parentNode && s.parentNode.removeChild(s); }
    addEventListener('load',f,false);
    setTimeout(f,3000); 
  	}
  	
  	
  	
  	
  	/* INFINITE SCROLL */
    
    $('#main').infinitescroll({
 
    navSelector  : ".post-navigation",
    nextSelector : "div.post-navigation div.prev a",
    itemSelector : "#main div.post",                   
	errorCallback: function(){},
	donetext	:	"That's it. That's all."
  	},function(arrayOfNewElems){
  		$('#infscr-loading').remove();
  	});
  	
  	
  	
  	
  	$('#controls').delay(1500).animate({
	    top: '50px'
	  }, 400, 'easeInOutExpo'
	);

	
	
	
	/* KEY NAV */
    
    $('#main .post:first-child').addClass('current');
    
    
    $('.key_left').fadeTo(0,0.2);
    $('.key_right').fadeTo(0,0.2);
    $('.key_up').fadeTo(0,0.2).delay(500).fadeTo(600,1);
    $('.key_down').fadeTo(0,0.2).delay(500).fadeTo(600,1);
    
    shortcut.add("down",function() {
    
    	$('.key_down').fadeTo(100,0.7).delay(100).fadeTo(100,1);
    	
    	if($('#main').children('.current').attr('ID') != $('#main').children('.post:last').attr('ID')) {
    	
    	$('#main').children('.current').next('.post:first').addClass('current');
    	$('#main').children('.current:first').removeClass('current');
    	
    	$.scrollTo( $('.current'), 400, {easing: 'easeInOutExpo'} );
    	
    	}
    	
    });
    
    shortcut.add("up",function() {
    
    	$('.key_up').fadeTo(100,0.7).delay(100).fadeTo(100,1);
    	
    	if($('#main').children('.current').attr('ID') != $('#main').children(':first').attr('ID')) {
    	
    	$('#main').children('.current').prev('.post:last').addClass('current');
    	$('#main').children('.current:last').removeClass('current');
    	
    	$.scrollTo( $('.current'), 400, {easing: 'easeInOutExpo'} );
    	
    	}
    	
    });
    
    
    
    
    /* HOVER KEY NAV */
    
    $('.key_down').mouseover(function() {
   		$('.key_down').stop().fadeTo(100,0.7);
    });
    
    $('.key_down').mouseleave(function() {
    	$('.key_down').stop().fadeTo(100,1);
    });    
    
    $('.key_up').mouseover(function() {
   		$('.key_up').stop().fadeTo(100,0.7);
    });
    
    $('.key_up').mouseleave(function() {
    	$('.key_up').stop().fadeTo(100,1);
    });
    
    $('.key_right').mouseover(function() {
   		$('.key_right').stop().fadeTo(100,0.3);
    });
    
    $('.key_right').mouseleave(function() {
    	$('.key_right').stop().fadeTo(100,0.7);
    });
    
    
    
    
    
    /* CLICK KEY NAV */
    
    $('.key_down').click(function() {
    
        if($('#main').children('.current').attr('ID') != $('#main').children('.post:last').attr('ID')) {
    	
    	$('#main').children('.current').next('.post:first').addClass('current');
    	$('#main').children('.current:first').removeClass('current');
    	
    	$.scrollTo( $('.current'), 400, {easing: 'easeInOutExpo'} );
    	
    	}
    });

    $('.key_up').click(function() {
    
        $('.key_up').fadeTo(100,0.7).delay(100).fadeTo(100,1);
    	
    	if($('#main').children('.current').attr('ID') != $('#main').children(':first').attr('ID')) {
    	
    	$('#main').children('.current').prev('.post:last').addClass('current');
    	$('#main').children('.current:last').removeClass('current');
    	
    	$.scrollTo( $('.current'), 400, {easing: 'easeInOutExpo'} );
    	
    	}
    });    
    
    
    
    
    
    /* SOCIAL MEDIA LINKS */
    
    $('.tweet, .share').fadeTo(0,0.3);
    
    $('.tweet, .share').mouseover(function() {
   		$(this).stop().fadeTo(100,1);
    });
    
    $('.tweet, .share').mouseleave(function() {
    	$(this).stop().fadeTo(100,0.3);
    });
    
     
     
     
     
    /* CONTENT FADE-IN */
     
    $('#main').fadeTo(0,0).delay(100).fadeTo(500,1);
    
         
    

});

