
$(document).ready(function() {

	if ( $("body.single .post .pro-player-container").width() > 0 ) {
		var proW = $("#single .pro-player-container").width();
		$("#wrapper").css("width", proW);
		$("#header, #footer").css("width", proW);
	} else {
		var bigImgW = $("body.single img.size-full").width();
		$("body.single #header, body.single #footer, body.single #single").width(bigImgW);
		$("body.single #wrapper").width(bigImgW);
	}
	
	$('#toggle_menu').click(function() {
		$(this).hide();
		$('#menu').toggle();
		$('#load').toggleClass('cat_on');
		return false;
	});
	
	if ($('.post img').size() < 3 ) {
		$('.backtop').hide();
	}
		
	/* if ( $("#posts_nav a").length > 0 ) {
		var strollH = $("#stroll").height();
		$("#stroll").css("height", strollH + "20px");
	} */
		
	$('body.single img, body.category img').lazyload();
	
	$('#opened').hide();
	
	$('#closed').click(function() {
		$(this).hide();
		$('#view_categories').animate({'left': 110}, 500);
		$('#catlist').animate({'left': 0}, 500);
		$('#opened').show()
		$('#load').addClass('cat_on');
		return false;
	});
	
	$('#opened').click(function() {
		$(this).hide();
		$('#catlist').animate({'left': -110}, 500);
		$('#closed').show();
		$('#view_categories').animate({'left': 0}, 500);
		$('#load').removeClass('cat_on');
		return false;
	});
	
	// Check for hash value in URL
    /*var hash = window.location.hash.substr(29);
    var href = $('#controls a').each(function(){
        var href = $(this).attr('href');
        if(hash==href.substr(34,href.length)){
            var toLoad = hash+' #content';
            $('#content').load(toLoad)
        }
    });*/
	
	/*$('#controls a').live('click', function() {
		var toLoad = $(this).attr('href')+' #content';
		$('#stroll').hide(0, loadContent());
		$('#load').show();
		window.location.hash = $(this).attr('href').substr(34,$(this).attr('href').length);
		function loadContent() {
			$('#content').load(toLoad,'',showNewContent);
		}
		function showNewContent() {
			$('#stroll').show(0);
			$('#load').hide();
		}
		function hideLoader() {
			$('#load').hide();
		}
		return false;
	});*/
	
	$('#controls a').live('click', function() {
		/*var toLoad = $(this).attr('href')+' #content';
		var name = $(this).attr('href').substr(34,$(this).attr('href').length);
		$('#stroll').append('<div class="new '+ name +'"><div id="loading"><img src="http://adventuresinspace.com/wp/wp-content/themes/naked/images/ajax-loader-2.gif" /></div></div>');
		$('#controls').remove();
		$('.'+ name).load(toLoad, '', function() {
			$(this).children('#loading').remove();
			$(this).append('<div class="current_page">'+ name +'</div>');
			$.scrollTo('.'+ name, 800);
			$('body.home #content').masonry({ columnWidth: 416, singleMode: true }, function() {
				var cH = $('#content').height();
				$('#controls').css({'top' : cH});
			});
			$('#backtotop').fadeIn(800);
			
		});
		return false;*/
	});
		
	
	//$('body.category .post:nth-child(7)').css('margin-right', '0px');
	
	var nextL = $('#controls a span').parent().attr('href');
	
	shortcut.add("Shift+H",function() {
		window.location = "http://adventuresinspace.com/"
	});
	
	shortcut.add('Shift+N',function() {
		var toLoad = $('#controls a span#next').parent().attr('href')+' #content';
		$('#stroll').hide(0, loadContent());
		$('#load').show();
		function loadContent() {
			$('#content').load(toLoad,'',showNewContent);
		}
		function showNewContent() {
			$('#stroll').show(0);
			$('#load').hide();
		}
		function hideLoader() {
			$('#load').hide();
		}
		window.location.hash = $('span#next').parent().attr('href').substr(34,$(this).length);
		return false;
	});
	
	shortcut.add('Shift+P',function() {
		var toLoad = $('#controls a span#prev').parent().attr('href')+' #content';
		$('#stroll').hide(0, loadContent());
		$('#load').show();
		function loadContent() {
			$('#content').load(toLoad,'',showNewContent);
		}
		function showNewContent() {
			$('#stroll').show(0);
			$('#load').hide();
		}
		function hideLoader() {
			$('#load').hide();
		}
		window.location.hash = $('span#prev').parent().attr('href').substr(34,$(this).length);
		return false;
	});
	
	shortcut.add('Shift+I', function() {
		$('#wrapper').toggle();
		$('#info').toggle();
		$('body').toggleClass('popped');
	});
	
	$('#open_info').live('click', function() {
		$('#wrapper, #info, body.home #view_categories, #catlist').toggle();
		$('body').toggleClass('popped').css('overflow', 'auto');
		return false;
	});
	
	$('.backtop').click(function() {
		$.scrollTo('#top', 800);
		return false;
	});
	
	$('#backtotop').click(function() {
		$.scrollTo('#top', 800);
		$(this).hide();
		return false;
	});
	
});

$(window).load(function() {
	$('body.home .post').hover(function() {
		$(this).stop(true, true).animate({'opacity': '0.8'}, 0);
	}, function() {
		$(this).stop(true, true).animate({'opacity': '1'}, 0);
	});
	
	$('body.home #content').masonry({ columnWidth: 366, singleMode: true });

//$('img').lazyload();

});
