		var pages = new Array("Me","Works","Contact");
			var startPage = 'Me';
			var subpages = new Array("Web","Mobile","Graphic","Photo","Writing");
			var startSub = 'Web';
			var flipperCurrent = 1;
			
			function showPage(newpage){
				var oldpage = location.hash.substring(1).split('=')[0];
			  	if(oldpage == 'Works') $("#submenu").slideUp(300);
				$.each(pages, function(i,v){ $("#nav" + v).removeClass("activeNav");});				
				$("#nav" + newpage).addClass("activeNav");
				if($.inArray(oldpage,pages) < 0) oldpage = startPage;
				
			  	$("#_" + oldpage).stop(true, true).hide();
				$("#_" + newpage).fadeIn(1000);
				if(newpage == 'Works'){ 
					$("#submenu").slideDown(1000);
					showSubPage('Works',startSub)					
				}
			}
			
			function showSubPage(page,newsub){
				var oldsub = location.hash.substring(1).split('=')[1];
				flipperCurrent = 1;
				$.each(subpages, function(i,v){ $("#nav" + v).removeClass("active");});				
				$("#nav" + newsub).addClass("active");
			  	$("#_Sub" + page).stop(true, true).hide();
				$("#load").fadeIn(100);
				if($.inArray(subpages,newsub) < 0){
					$("#_Sub" + page).load('subs/' + newsub + '.html', function() {
					  	$("#load").css("display", "none");																	
						$("#_Sub" + page).fadeIn(1000);
					});
				}
			}			
			
			function flip(tile){
				$("#tile" + tile + " > div").fadeToggle(300);	
			}


			function phoneFallback(){
				$('#phonefallback').slideDown(1000, function(){
					 $('#phonelink').attr('href', 'tel:+4791814458');
					$('#phonelink span:first').html('Call now');				
					$('#phonelink span:first').css('background','#e000c8');								
					$('#phonelink span:first').css('color','#fff');								
															 });
			}

			function closeMe(div){
				$('#' + div).slideUp(300);	
			}

			function flipper(page,num,action){
				if(action == 'next') flipperCurrent++;
				else flipperCurrent--;
				if(flipperCurrent == 0) flipperCurrent = num;
				if(flipperCurrent > num) flipperCurrent = 1;			
				//alert(flipperCurrent );
				$("#flip" + page + flipperCurrent).css('height','60%');
				$("div.flipperTile:visible").fadeOut(100, function(){				
					$("#flip" + page + flipperCurrent).animate({opacity:'toggle', height: '100%'},500); 
				});
			}

			$(document).ready(function() {

				// Handle page navigation thingies
				$.each(pages, function(i,v){ $("#_" + v).hide();});
				var currentpage = location.hash.substring(1).split('=')[0];			
				var currentsub = location.hash.substring(1).split('=')[1];							
				if($.inArray(currentpage,pages) < 0) currentpage = startPage;
				$("#nav" + currentpage).addClass("activeNav");								
				if(currentpage == 'Works'){ 
	 				$("#_" + currentpage).show();						
					$("#submenu").slideDown(500, function(){
						if(currentsub == null) currentsub = startSub;
						showSubPage('Works',currentsub);
					});
				} else {
	 				$("#_" + currentpage).fadeIn(1000);		
				}

				// Fetch twitter update
				var username = 'spispeas';
	    		$.getScript('http://twitter.com/statuses/user_timeline/' + username + '.json?callback=twitterCallback2&count=1');

				// Starts slideshow
				// source: http://www.sohtanaka.com/web-design/automatic-image-slider-w-css-jquery/
				$(".paging").show();
				$(".paging a:first").addClass("active");
				imageWidth = $(".slides").width();
				imageSum = $(".image_reel img").size();
				imageReelWidth = imageWidth * imageSum;
				$(".image_reel").css({'width' : imageReelWidth});
				rotateSwitch(); //Run function on launch
				//On Hover
				$(".image_reel a").hover(function() {
					clearInterval(play); //Stop the rotation
				}, function() {
					rotateSwitch(); //Resume rotation timer
				});	
				
				//On Click
				$(".paging a").click(function() {
					$active = $(this); //Activate the clicked paging
					//Reset Timer
					clearInterval(play); //Stop the rotation
					rotate(); //Trigger rotation immediately
					rotateSwitch(); // Resume rotation timer
					return false; //Prevent browser jump to link anchor
				});				

            });
