$.ajaxSetup ({
    // Disable caching of AJAX responses */
    cache: false
});

var $userVPos = 0;




Cufon.replace('h1', { fontFamily: 'MCT Quatro Beta' }); // Works without a selector engine
Cufon.replace('h2', { fontFamily: 'Aaargh' });
Cufon.replace('h3', { fontFamily: 'Aaargh' });
Cufon.replace('h4', { fontFamily: 'Aaargh' });
Cufon.replace('.about', { fontFamily: 'Aaargh' });
Cufon.replace('a.project', { fontFamily: 'Aaargh' });
//Cufon.replace('#sub1'); // Requires a selector engine for IE 6-7, see above
$("head").append("<link />");
var CSS = $("head").children(":last");
CSS.attr({
"rel": "stylesheet",
"type": "text/css",
"href": "jquery.css"
});

function cyc() {
$('.shots').before('<div id="shotsNav"><div id="shotsInner"><div id="shotsInnerPager"></div></div>') .cycle({
	fx:     'scrollLeft', 
	easing: 'easeOutCirc',
    speed:  'slow', 
    timeout: 0, 
    pager:  '#shotsInnerPager' 
	});
}

function closeProject(){
	$('#shotsClose').animate({right: '-100px'}, function(){
		$('#shotsClose').remove();
		$('#shotsNav').animate({top: '-38px'}, function(){
			$('#shotsDisplay').animate({opacity: '0'}, function(){
				$('#shotsDisplay').remove();
				$('#wrapper').css('height', 'auto');
				$(window).scrollTop($userVPos);
				$('#overlay').animate({opacity: '0'}, function(){
					$('#overlay').css('display','none');
					//$('#wrapper').css('height', 'auto');
				});
			});
		});
	});
}


function showProject(which){
	$('#overlay').css('display','block');
	$('#overlay').animate({opacity: '1'}, function(){
		$(window).scrollTop(0);
		$('body').append('<div id="shotsDisplay"></div>');
		$("#shotsDisplay").empty().load(which+" div.shots", function() {
			cyc();
			$('#shotsNav').animate({top: '0px'}, function(){
				$('#shotsInner').append('<div id="shotsClose"><a href="#home" class="projClose">x close</a></div>');
				Cufon.replace('a.projClose', { fontFamily: 'Aaargh' });
				
				var wh = $(".shots").css('height');
				$('#wrapper').css('height', wh);
				$('a.projClose').click(function(){
					closeProject();
				});
				$('#shotsClose').animate({right: '0px'});
				});
		});
	});
}


function btnChange() {
	$('a.btn').each(function(i){
	if($(this).attr("href") != "#project") {
		var tem = $(this).attr("href");
		$(this).attr("title", tem);
		$(this).attr("href", "#project");
		$(this).click(function(){
			$userVPos = $(window).scrollTop();
			showProject($(this).attr("title"));
			//alert($userVPos);
		});
	}
	//alert($(this).attr("href"))
	});
}


$(document).ready(function(){
//showProject();
	btnChange();
	
  	$(".abt").empty().load("about-andrew-broomfield.html div.aboutPage", function() {
  		Cufon.refresh('h3');
  	});
	  $("a.about").attr("href", "#");
	  $("a.about").toggle(

			function() {
	  		
				$('.abt').animate({
    			top: '108'
  			},'slow', 'easeOutCirc');
  			$('header hgroup nav a').animate({
    			top: '1'
  			},'slow', 'easeOutCirc');

	  	}, function() {
  			$('.abt').animate({
    			top: '-312'
  			},'slow', 'easeOutCirc');
  			$('header hgroup nav a').animate({
    			top: '-15'
  			},'slow', 'easeOutCirc');
  		});


	  $('#content').infinitescroll({

	    navSelector  : "div#pager",            
	                   // selector for the paged navigation (it will be hidden)
	    nextSelector : "div#pager a:first",    
	                   // selector for the NEXT link (to page 2)
	    itemSelector : "#content div.article",          
	                   // selector for all items you'll retrieve
		loadingImg   : "loading.gif",
		loadingText:"Loading more work...",
		donetext:"You have reached the end, thanks for looking."
	  },function() {
			Cufon.refresh();
			btnChange();
		});



});



