$(document).ready(function() {

	var pages=[
		new page('ea00',980,735,'000'),
		new page('ea01',980,735,'000'),
		new page('ea02',980,735,'000'),
		new page('ea03',980,735,'000'),
		new page('ea04',980,735,'000'),
		new page('ea05',980,735,'000'),
		new page('ea06',980,735,'000'),
		new page('ea07',980,735,'000'),
		new page('ea08',980,735,'000'),
		new page('ea09',980,735,'000'),
		new page('ea10',980,735,'000'),
		new page('ea11',980,735,'000'),
		new page('ea12',980,735,'000'),
		new page('ea13',980,735,'000'),
		new page('ea14',980,735,'000'),
		new page('ea15',980,735,'000'),
		new page('ea16',980,735,'000'),
		new page('ea17',980,735,'000'),
		new page('ea18',980,735,'000'),
		new page('ea19',980,735,'000'),
		new page('ea20',980,735,'000'),
		new page('od00',980,656,'000'),
		new page('od12',980,656,'000'),
		new page('od11',980,656,'000'),
		new page('od10',980,656,'000'),
		new page('od09',980,656,'000'),
		new page('od08',980,656,'000'),
		new page('od07',980,656,'000'),
		new page('od06',980,656,'000'),
		new page('od05',980,656,'000'),
		new page('od04',980,656,'000'),
		new page('od03',980,656,'000'),
		new page('od02',980,656,'000'),
		new page('od01',980,656,'000'),
		new page('sp0',980,711,'f0f0f0'),
		new page('sp1',980,711,'f0f0f0'),
		new page('sp2',980,711,'f0f0f0'),
		new page('sp3',980,711,'f0f0f0'),
		new page('sp4',980,711,'f0f0f0'),
		new page('sp5',980,711,'f0f0f0'),
		new page('do00',980,656,'000'),
		new page('do07',980,656,'000'),
		new page('do06',980,656,'000'),
		new page('do05',980,656,'000'),
		new page('do04',980,656,'000'),
		new page('do03',980,656,'000'),
		new page('do02',980,656,'000'),
		new page('do01',980,656,'000'),
		new page('ca00',980,652,'dbdbdb'),
		new page('ca01',980,652,'dbdbdb'),
		new page('ca02',980,652,'dbdbdb'),
		new page('ca03',980,652,'dbdbdb'),
		new page('ca04',980,652,'dbdbdb'),
		new page('ca05',980,652,'dbdbdb'),
		new page('ca06',980,652,'dbdbdb'),
		new page('ca07',980,652,'dbdbdb'),
		new page('ca08',980,652,'dbdbdb'),
		new page('ca09',980,652,'dbdbdb'),
		new page('ca10',980,652,'dbdbdb'),
		new page('ca11',980,652,'dbdbdb'),
		new page('ca12',980,652,'dbdbdb'),
		new page('ca13',980,652,'dbdbdb'),
		new page('ca14',980,652,'dbdbdb'),
		new page('ca15',980,652,'dbdbdb'),
		new page('ca16',980,652,'dbdbdb')
	];
	var imgDir='img/';
	var slidePrefix='pepkarsten_';
	var slideExt='.jpg';
	var homePageNumber=0;

	function page(slide,width,height,color) {
		this.slide=slide;
		this.width=width;
		this.height=height;
		this.color=color;
	}	
	function displayPage(n) {
		if(n==0) {
			$('#intro').show();
			$('#slideshow').hide();
			$('#nav').hide();
			$('#tip').hide();
			$('#next').activateLink();
			$("#prev").deactivateLink();
			$("#home").deactivateLink();
			$.preloadImg(imgDir+slidePrefix+pages[0].slide+slideExt);
		}
		else {
			$('#intro').hide();
			$('#slideshow').show();
			$("#prev").activateLink();
			$("#home").activateLink();
			var $slide=$('#slide');
			var $photo=$('#photo img');
			var $pagenumber=$('#pagenumber');
			$slide.css({backgroundColor:'#'+pages[n-1].color});
			$photo.hide();
			$slide.css({width:pages[n-1].width,height:pages[n-1].height});
			$('#navzone').height(pages[n-1].height);
			$photo
				.attr('src','')
				.one('load',function() {
					$photo.fadeIn(250);
					$.preloadImg(imgDir+slidePrefix+pages[n-1].slide+slideExt);
					if(n<pages.length) $.preloadImg(imgDir+slidePrefix+pages[n].slide+slideExt);
					if(n>1) $.preloadImg(imgDir+slidePrefix+pages[n-2].slide+slideExt);
				})
				.attr('src',imgDir+slidePrefix+pages[n-1].slide+slideExt);
			$pagenumber.text(n+'/'+(pages.length));
			Cufon.replace($pagenumber);
			if(n==pages.length) {
				$('#next').hide().deactivateLink();
				$("#photo").deactivateLink();
				$("#navzone").deactivateLink();
			}
			else {
				$('#next').show().activateLink();
				$("#photo").activateLink();
				$("#navzone").activateLink();
			}
		}
	}

	$(window).hashchange(function() {
		if(location.hash.match(/^#\d{1,3}$/)) {
			var pn=(+location.hash.substr(1));
			(pn>=0&&pn<=pages.length)? displayPage(pn): location.hash=homePageNumber;
		}
		else location.hash=homePageNumber;
	});
	$(window).hashchange();
	$.autoMouseOverDown();
	$.blurAllLinks();
	$('#enter>a')
		.onclick(function() {location.hash=(+location.hash.substr(1))+1})
	$('#contact>a')
		.onclickEmail('info','pepkarsten.com');
	$('#facebook>a')
		.onclickOpen('http://www.facebook.com/pepkarsten');
	$('#slide')
		.hover(
			function() {$('#tip').stop(true,true).show()},
			function() {$('#tip').fadeOut(250)});
	$('#navzone')
		.hover(
			function() {$('#nav').stop(true,true).show()},
			function() {$('#nav').fadeOut(250)});
	/*$('#navzone>a')
		.mouseenter(function() {$('#next img').mouseenter(); return false;})
		.mouseleave(function() {$('#next img').mouseleave(); return false;});*/
	$('#photo>a, #navzone>a')
		.onclick(function() {location.hash=(+location.hash.substr(1))+1})
	$('#home>a')
		.onclick(function() {location.hash=homePageNumber})
		.shortcut('up');
	$('#prev>a')
		.onclick(function() {location.hash=(+location.hash.substr(1))-1})
		.shortcut('left');
	$('#next>a')
		.onclick(function() {location.hash=(+location.hash.substr(1))+1})
		.shortcut('right');
	$('').shortcut('down');
});



// JQUERY PKTOOLS PLUG-IN V1.0 - COPYRIGHT 2010 PEP KARSTEN

(function($){
	imgCache=new Array();
	$.preloadImg=function() {
		for(var i=0; i<arguments.length; i++) {
			var img=new Image();
			img.src=arguments[i];
			imgCache[img.src]=img;
		}
	}
	$.autoMouseOverDown=function(outStr,outUpStr,overStr,downStr) {
		var outStr=(typeof outStr=='undefined')?'-out.':outStr;
		var outUpStr=(typeof outUpStr=='undefined')?'-outup.':outUpStr;
		var overStr=(typeof overStr=='undefined')?'-over.':overStr;
		var downStr=(typeof downStr=='undefined')?'-down.':downStr;
		$("img[src*='"+outStr+"']")
			.each(function() {$.preloadImg(this.src.replace(outStr,overStr))})
			.hover(
				function() {this.src=this.src.replace(outStr,overStr)},
				function() {this.src=this.src.replace(overStr,outStr)});
		$("img[src*='"+outUpStr+"']")
			.each(function() {$.preloadImg(this.src.replace(outUpStr,overStr))})
			.each(function() {$.preloadImg(this.src.replace(outUpStr,downStr))})
			.hover(
				function() {this.src=this.src.replace(outUpStr,overStr)},
				function() {this.src=this.src.replace(overStr,outUpStr)})
			.mousedown(function() {this.src=this.src.replace(overStr,downStr)})
			.mouseup(function() {this.src=this.src.replace(downStr,overStr)});
	}
	$.blurAllLinks=function() {
		$('a').focusin(function() {
			this.blur();
		});
	}
	$.address=function(u,d) {
		return u+'@'+d;
	}
	$.fn.onclick=function(f) {
		var $this=this;
		this.click(function() {
			if($this.attr('href')!==undefined) f();
			return false;
		});
		return this;
	}
	$.fn.onclickOpen=function(l) {
		this.onclick(function() {
			open(l);
		});
		return this;
	}
	$.fn.onclickEmail=function(u,d,s,b) {
		var l='mailto:'+$.address(u,d);
		if(s||b) {
			l+='?';
			if(s) {
				l+='subject='+s;
				if(b) l+='&';
			}
			if(b) l+='body='+b;
		}
		this.onclickOpen(l);
		return this;
	}
	$.fn.deactivateLink=function() {
		this.children('a').removeAttr('href');
		return this;
	}
	$.fn.activateLink=function() {
		this.children('a').attr('href','');
		return this;
	}
	$.fn.shortcut=function(k) {
		var code={left:37,up:38,right:39,down:40};
		var $this=this;
		$(document).keydown(function(e) {
			if(e.keyCode==code[k]) {
				$this.click();
				return false;
			}
		});
		window.focus();
		return this;
	}
})(jQuery);



// JQUERY HASHCHANGE PLUG-IN V1.3 - COPYRIGHT 2010 BEN ALMAN

(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);



// HELVETICA NEUE BOLD FONT - COPYRIGHT 1988 ADOBE SYSTEMS INCORPORATED

Cufon.registerFont({"w":556,"face":{"font-family":"Helvetica Neue","font-weight":700,"font-stretch":"normal","units-per-em":"1000","panose-1":"2 11 8 4 2 2 2 2 2 4","ascent":"714","descent":"-286","bbox":"-11 -731 542 17","underline-thickness":"50","underline-position":"-50","stemh":"107","stemv":"142","unicode-range":"U+002F-U+0039"},"glyphs":{" ":{},"\/":{"d":"-11,17r279,-748r114,0r-279,748r-114,0","w":371},"0":{"d":"21,-353v0,-273,118,-361,256,-361v140,0,258,88,258,361v0,279,-118,367,-258,367v-138,0,-256,-88,-256,-367xm163,-353v0,79,0,250,114,250v116,0,116,-171,116,-250v0,-73,0,-244,-116,-244v-114,0,-114,171,-114,244"},"1":{"d":"392,-700r0,700r-142,0r0,-454r-176,0r0,-107v99,2,190,-32,205,-139r113,0"},"2":{"d":"173,-431r-136,0v-5,-160,86,-283,254,-283v128,0,240,82,240,219v0,105,-56,163,-125,212v-69,49,-151,89,-202,161r331,0r0,122r-514,0v1,-162,100,-231,221,-313v62,-42,146,-85,147,-171v0,-66,-44,-108,-105,-108v-84,0,-111,87,-111,161"},"3":{"d":"228,-317r0,-100v61,5,149,-7,149,-87v0,-59,-47,-93,-99,-93v-71,0,-109,53,-108,125r-135,0v5,-143,98,-242,242,-242v112,0,235,69,235,194v0,66,-33,125,-98,143r0,2v77,17,124,81,124,159v0,147,-123,230,-260,230v-157,0,-263,-94,-260,-255r135,0v3,76,41,138,123,138v64,0,114,-44,114,-110v0,-106,-93,-104,-162,-104"},"4":{"d":"312,0r0,-162r-296,0r0,-130r304,-408r127,0r0,421r93,0r0,117r-93,0r0,162r-135,0xm312,-279r0,-243r-3,0r-181,243r184,0"},"5":{"d":"500,-700r0,117r-289,0r-28,159r2,2v38,-39,82,-54,137,-54v138,0,216,107,216,238v0,144,-119,255,-260,252v-136,0,-258,-75,-260,-222r142,0v7,62,53,105,115,105v74,0,121,-65,121,-135v0,-73,-45,-131,-121,-131v-51,0,-79,18,-107,56r-128,0r69,-387r391,0"},"6":{"d":"523,-520r-135,0v-9,-47,-45,-87,-94,-87v-103,0,-130,135,-134,213r2,2v39,-55,90,-78,158,-78v60,0,121,28,161,72v37,43,54,101,54,156v0,143,-99,256,-245,256v-212,0,-269,-185,-269,-362v0,-171,76,-366,275,-366v121,0,211,71,227,194xm286,-363v-76,0,-113,61,-113,130v0,65,42,130,113,130v68,0,107,-65,107,-128v0,-66,-34,-132,-107,-132"},"7":{"d":"517,-700r0,122v-147,128,-227,391,-229,578r-152,0v16,-207,102,-408,235,-568r-332,0r0,-132r478,0"},"8":{"d":"156,-212v0,72,56,119,124,119v68,0,120,-48,120,-118v0,-67,-54,-112,-120,-112v-69,0,-124,39,-124,111xm43,-523v0,-126,122,-191,236,-191v174,0,234,120,234,188v0,69,-36,125,-102,147r0,2v83,19,131,83,131,171v0,147,-132,220,-262,220v-135,0,-266,-68,-266,-219v0,-89,50,-152,132,-172r0,-2v-68,-19,-103,-75,-103,-144xm172,-510v0,61,50,92,107,92v58,0,105,-32,105,-92v0,-36,-17,-97,-105,-97v-57,0,-107,35,-107,97"},"9":{"d":"33,-180r135,0v9,47,45,87,94,87v103,0,130,-135,134,-213r-2,-2v-39,55,-90,78,-158,78v-60,0,-121,-28,-161,-72v-37,-43,-54,-101,-54,-156v0,-143,99,-256,245,-256v212,0,269,185,269,362v0,171,-76,366,-275,366v-121,0,-211,-71,-227,-194xm270,-337v76,0,113,-61,113,-130v0,-65,-42,-130,-113,-130v-68,0,-107,65,-107,128v0,66,34,132,107,132"},"\u00a0":{}}});
