(function($){  
	$(document).ready(function() {

		//arrays containing tile coordinates
		var arrX = [42,42,42,42,42,72,72,72,72,72,104,104,136,136,167,167,197,197,197,197,197,
					227,227,227,227,227,258,258,258,258,258,385,385,385,385,385,415,415,415,
					415,415,
					25,57,88,118,150,182,214,245,275,308,340,372,402,433,
					402,372,340,308,275,245,214,182,150,118,88,57,
					57,101,134,167,198,229,259,292,325,355,386,
					374,343,311,279,249,217,186,154,121,57,
					157,186,217,249,279,311,343,
					311,279,249,217,186,
					217,249,279,
					249];
		var arrY = [41,71,100,130,160,41,71,100,130,160,41,71,41,71,41,71,41,71,100,130,160,41,
					71,100,130,160,41,71,100,130,160,41,71,100,130,160,41,71,100,130,160,
					190,190,190,190,190,190,190,190,190,190,190,190,190,190,
					219,219,219,219,219,219,219,219,219,219,219,219,
					249,249,249,249,249,249,249,249,249,249,249,
					278,278,278,278,278,278,278,278,278,278,
					308,308,308,308,308,308,308,
					338,338,338,338,338,
					368,368,368,
					398]  
		
		$('#jq-nav-shadow').css('opacity',0);
		$('#jq-nav img').css('opacity',0).each(function(i) {
			if (i < 104) {
			$(this).delay(20*i).css({'left': arrX[i]}).animate({'opacity': 1, 'bottom': arrY[i++]}, 1500, function () { if (i == 104) { houseBuilt();} });
			}
		})
		$('#jq-nav a').live('click', function(event) {
  		    event.preventDefault();
			navClick(event, event.currentTarget);
		});

		$('#jq-toHome a').live('click', function(event) {
  		    event.preventDefault();
			homeClick(event);
		});
  		
		$('.jq-content-photo a').live('click', function(event) {
  		    event.preventDefault();
			pagerClick(event, event.currentTarget);
		});
		
		function houseBuilt() {
			$('#jq-nav img').animate({opacity: 0.3}, 800, function() {$('#jq-nav-shadow img').css({opacity: 1});})
			$('#jq-nav a img').animate({opacity: 1}, 800, function() { addHover(); });
			$('#jq-nav-shadow').animate({opacity: 1}, 800);
			$('#jq-content').slideDown(2000);
		}
		
		function addHover() {
			$('#jq-nav a').live('mouseenter mouseleave', function(event) {
				var index = $(event.target).attr('src');
				index = index.substring(index.length-7, index.length-4);
				index = index - 1;
				
				if (event.type == 'mouseenter') {
				
				var btm = arrY[index] - 20;
				var lft = arrX[index] - 20;
					
				// do grow on mouseover
				$(event.target).clearQueue().delay(100).css({'z-index': '10'}).animate({
						height: '73px',
						width: '73px',
						'bottom': btm,
						'left':  lft
					},200);
			  } else {				
				var btm = arrY[index];
				var lft = arrX[index];
				// do shrink on mouseout
				$(event.target).clearQueue().delay(100).animate({
						height: '21px',
						width: '21px',
						'bottom': btm,
						'left':  lft
					},200).css({'z-index': '5'});
			  }
			});
	    }
		
		function navClick(event, myLink) {
			//hide the home content
			$('#jq-nav').hide();
			$('#home').hide();
			$('#jq-toHome').show();
			
			//determine which story was clicked and show its content
		  	var str = myLink.toString()
			str = str.substring(str.indexOf('#'), str.length);
			$(str).show();
		}
		
		function homeClick(event) {
			$('#jq-nav').show();
			$('#jq-content div').hide();
			$('#home').show();
		}
		
		function pagerClick(event, myLink) {
			//determine which link was clicked
		  	var str = myLink.toString()
			str = str.substring(str.indexOf('#')+1, str.length);
			
			//determine which story is active
			var storyNum = $(event.target).closest('div').attr('id');
				storyNum = storyNum.substring(storyNum.indexOf('y')+1, storyNum.length);

			//hide the current story
			$('#' + $(event.target).closest('div').attr('id')).hide();
			
			if(str == "previous") {				
				storyNum = (storyNum * 1) - 1; 
				if(storyNum == 0) {
					$('#story11').show();	
				} else {
					$('#story'+storyNum).show();	
				}
			} else { 
				storyNum = (storyNum * 1) + 1; 
				
				if(storyNum == 12) {
					$('#story1').show();	
				} else {
					$('#story'+storyNum).show();	
				}
			}

		}

	});  
})(jQuery);  


