
	var speed = 500;
	var clientMove = 490;
	var scrollHeight = 580;
	var container ;
	var locationRequest = window.location.hash.replace('#', '');
	var recentPostWidth = 260*3;
	var currentBlock = 1;

jQuery(document).ready(function($){
	container = $('#container');
	initSite();
	//LoadLocationRequest(locationRequest);
});
		
/*********************************************************************

	Initializing site

*********************************************************************/	
function initSite(){
	
	
		/* Recent Post Navigation
		-------------------------------------------------------------------*/
		
		
		
		$('.recent-post-nav a').click(function() {
			
			var blockCount = Math.ceil($('.recent-posts ul li a').size()/3);	
			////console.log(currentBlock);
			if ($(this).hasClass("enabled")) {
				if ($(this).hasClass("next") ) {
					direction = '-=';
					recentPostWidth = 780;
					////console.log("next pressed // "+currentBlock+" - "+blockCount);	
					if (currentBlock+1 == blockCount) {
						console.log("we are at the last block");
						currentBlock = currentBlock+1;
						//recentPostWidth = 0;
					} else if (currentBlock == blockCount){	
						////console.log("can't go further");
						recentPostWidth = 0;
					} else {
						currentBlock = currentBlock+1;
					}
				} else if ($(this).hasClass("prev")){
					////console.log("prev pressed // "+currentBlock+" - "+blockCount);	
					direction = '+=';
					if (currentBlock == 1) {	
						currentBlock = 1;
						recentPostWidth = 0;
						
					} else {			
						recentPostWidth = 780;				
						currentBlock = currentBlock-1;
					}
				}
				
				var theClass = $(this).attr('class');
				
				$('.recent-posts ul').animate({
					marginLeft: direction+recentPostWidth
				  }, {
					duration: speed/2, 
					specialEasing: {
					  marginTop: 'easeInOutQuad'
					}, 
					complete: function() {
						
						//console.log(theClass+" pressed // "+currentBlock);	
					
						if (currentBlock <= blockCount && currentBlock > 1) {
							$(".recent-post-nav .prev, .recent-post-nav .next").removeClass('inactive').addClass('enabled');
						} else if (currentBlock == 1) {
							
							$(".recent-post-nav .prev").addClass('inactive').removeClass('enabled');
							$(".recent-post-nav .next").removeClass('inactive').addClass('enabled');
						}
						
						if (currentBlock == blockCount) {
							$(".recent-post-nav .next").addClass('inactive').removeClass('enabled');
						}
						
						
					}
				}); 
			
			}		
			
		}); 
		
		$(".single .screen").before($(".recent-post-nav").clone().addClass("single-post-nav").removeClass("recent-post-nav"));
		$(".single .recent-post-nav").remove();
		setPosition(getPosition());
		
		$('.single-post-nav a').bind('click',function() {

		
			if ($(this).hasClass("inactive") ) {				
				return;
			}
			if ($(this).hasClass("next") ) {
				direction = '-=';	
				$(".focus").removeClass("focus").next().addClass("focus");
				$(".prev").removeClass("inactive").addClass("enabled");
			} else {
				direction = '+=';		
				$(".focus").removeClass("focus").prev().addClass("focus");
				$(".next").removeClass("inactive").addClass("enabled");
			}
				
			//console.log("focus: "+$(".focus").index());
			var postCount = $('.recent-posts ul li').size();
			
			$(window).unbind('keydown');
			slidePosts(direction,postCount/2);
		});
		
		function slidePosts(direction,postCount) {
						$(window).bind('keydown',keyPressRelease);
			$('.recent-posts ul').animate({
				marginLeft: direction+'260'
			}, 200, function() {
				//console.log(postCount);
				if ($(".focus").index() == postCount-1) {
					console.log("focus at last post");
					$(".next").removeClass("enabled").addClass("inactive");
				} else if (!$(".focus").index()) {
					console.log("focus at first post");
					$(".prev").removeClass("enabled").addClass("inactive");
				}


			});		
		}
		
				  
		/*********************************************************************
		
			Banners on Frontpage
		
		*********************************************************************/
		$('.banner-item.past').wrapAll('<div id="older-banners" class="span-6"></div>');
		$("#older-banners").before('<div id="expand-banners"></div>');
		
		$('#expand-banners, #older-banners').wrapAll('<div id="accordion-banners"></div>');
		$( "#accordion-banners" ).accordion({
			autoHeight: false,
			header: '#expand-banners' ,
			collapsible: true,
			active: 2
		});
		$(".banner-item.current").clone().removeClass('current').addClass("active").prependTo($("#older-banners"));
		$(".banner-item.current").click(function() {
			$('#expand-banners').not(".ui-state-active").trigger('click');							 
		});
		$("#older-banners .banner-item").click(function() {
			$('.banner-item.active').removeClass("active");										
		   	$(this).addClass("active");
		  	var bannerID = $(this).find("img").attr("id");
		  	$(".banner-item.current a img").fadeOut("fast", function(){switchBanner(bannerID);});
		});
		$("#older-banners .banner-item").not(".active").hover(
			function(){$(this).fadeTo('fast', 0.7);},
			function(){$(this).fadeTo('slow', 0.25);} 
		);
		
		
		$('#expand-banners').keydown(function(e) {keyPressRelease(e);});
		$(window).keydown(function(e) {keyPressRelease(e);});
		$("#next").click(function() {
			$('.banner-item.active').next(".banner-item").addClass("active").trigger('click');
			$('.banner-item.active:last').siblings().removeClass("active");
		});
		$("#back").click(function() {
			$('.banner-item.active').prev(".banner-item").addClass("active").trigger('click').next(".banner-item").removeClass("active");
		});
		
		$("#banner .c-wrap").hover(
			function(){$(this).find(".control").fadeIn("fast")},
			function(){$(this).find(".control").fadeOut("slow")} 
		);
	
	
	$('ul li:first-child').addClass('first');
	$('ul li:last-child').addClass('last');
	

	

/* After Ajax has loaded content
-------------------------------------------------------------------*/	
		
	$(document).ajaxSuccess(function() {  
		setTimeout( function()
		{
			Cufon('#content h1, #content h2, .post-date', { fontFamily: 'Futura Light' }); // or whatever other cufon calls, really...
			Cufon('span.author', { fontFamily: 'Futura Book'});
				//Cufon('#subnav a', { fontFamily: 'Futura Book', hover:true });
	if ( $.browser.msie ) {
		
			Cufon('#subnav h3 a', { fontFamily: 'Futura Book'});
	} else {
				Cufon('#subnav a', { fontFamily: 'Futura Book', hover:true });
	}
			$( ".accordion" ).accordion({
				autoHeight: false,
				navigation: true
			});
		 
		}, 200);
	});



			
			
}
/*********************************************************************

	Functions

*********************************************************************/

/* Banner Functions
-------------------------------------------------------------------*/
function switchBanner(newBanner) {
	$(".banner-item.current a img").replaceWith($("#"+newBanner).clone());
	
	$(".banner-item.current a img").fadeIn("slow");
}
function keyPressRelease(e) {
	console.log(e.keyCode);
	if (e.keyCode == 37) { /* left arrow */
		
			$("#container > .recent-posts .prev:first").trigger('click');
	
   } else if (e.keyCode == 39){ /* right arrow */
			$("#container > .recent-posts .next:first").trigger('click');
   }	
   
}

/*-*/

function getPosition() {
	var position = $(".screen .current_page").index()+1;
	////console.log(position);
	return position;
}

function setPosition(position) {
												   
		var margin = 260*(position-2);
	
	$('.single .recent-posts ul').animate({
		marginLeft: '-='+margin
	  }, {
		duration: speed, 
		specialEasing: {
		  marginTop: 'easeInOutQuad'
		}, 
		complete: function() {
			position = position-1;
			////console.log(position);
			var postCount = ($('.recent-posts ul li').size())/2;
			//console.log(postCount);
			if (position >= 1) {
				//console.log("position: "+position+" ==> enabling .prev button... ");
				$(".prev").removeClass('inactive').addClass('enabled');
			} 
			
			if (position == postCount-1) {
				//console.log("position: "+position+" ==> enabling .prev button... ");
				$(".next").removeClass('enabled').addClass('inactive');
			}
			$(".current_page").addClass("focus");
		}
	}); 
}
