		var flippedBlog = 0, flippedProgramming = 0, flippedPhoto = 0, flippedCooking = 0;
		var cacheReturn = 1;
		var img = 0;
		
		setInterval(function() 
		{
			if (flippedPhoto != 1)
			{
				$("#photo").flip({
					direction: "tb",
					color: "#1AA1E2",
					content: "<h2>photo-a-day</h2><img src='randomPicture.php?id=" + img++ + "' align='left' style='margin-top: -50px; margin-left: -50px;' name='camerawolf'>",
					speed: 200
				})
			}
		}, 7000);
		
		function navigateToPage(url)
		{
			window.location = url;
		}

		function flipBlog()
		{
			flippedBlog = 1;
			$("#blog").flip({
				direction: "rl",
				color: "#000000",
				content: "&nbsp;", //(new Date()).getTime(),
				speed: 200,
				//onBefore: function(){$(".revert").show()}
				onEnd: function() { 
					if (cacheReturn == 1 && flippedBlog == 1) 
					{ 
						setTimeout(function(){$("#blog").revertFlip();},200); 
						flippedBlog = 0;
					} 
				}
			})		
		}
		
		function flipProgramming()
		{
			flippedProgramming = 1;
			$("#programming").flip({
				direction: "rl",
				color: "#000000",
				content: "&nbsp;", //(new Date()).getTime(),
				speed: 220,
				//onBefore: function(){$(".revert").show()}
				onEnd: function() { 
					if (cacheReturn == 1 && flippedProgramming == 1) 
					{ 
						setTimeout(function(){$("#programming").revertFlip();},300); 
						flippedProgramming = 0;
					} 
				}
			})
		}
		
		function flipPhoto()
		{
			flippedPhoto = 1;
			$("#photo").flip({
				direction: "rl",
				color: "#000000",
				content: "&nbsp;", //(new Date()).getTime(),
				speed: 240,
				//onBefore: function(){$(".revert").show()}
				onEnd: function() { 
					if (cacheReturn == 1 && flippedPhoto == 1) 
					{ 
						setTimeout(function(){$("#photo").revertFlip();},400); 
						flippedPhoto = 0;
					} 
				}

			})
		}
		
		function flipCooking()
		{
			flippedCooking = 1;
			$("#cooking").flip({
				direction: "rl",
				color: "#000000",
				content: "&nbsp;", //(new Date()).getTime(),
				speed: 260,
				//onBefore: function(){$(".revert").show()}
				onEnd: function() { 
					if (cacheReturn == 1 && flippedCooking == 1) 
					{ 
						setTimeout(function(){$("#cooking").revertFlip();},500); 
						flippedCooking = 0;
					} 
				}

			})
		}

		//window.unload(function(){ });
		//jQuery(window).bind("unload", function() { } );
		//jQuery(window).bind("load", function(){ alert("loaded"); } );
	
		$(function(){
			
			$("#flipPad div:not(.footer)").bind("click",function(){
				var $this = $(this);
				
				if ($this.attr("id") != "blog")
				{
					flippedBlog = 1;
					flipBlog();
				}
				
				
				
				if ($this.attr("id") != "programming")
				{
					flippedProgramming = 1;
					flipProgramming();
				}

				if ($this.attr("id") != "photo")
				{
					flippedPhoto = 1;
					flipPhoto();
				}

				if ($this.attr("id") != "cooking")
				{
					flippedCooking = 1;
					flipCooking();
				}

				cacheReturn = 0;
				return false;
			});			
		});
		
		function pageShown(evt)
    	{
        	if (evt.persisted)
			{
				//alert("pageshow event handler called.  The page was just restored from the Page Cache. " + flippedBlog);
				//location.reload();
				cacheReturn = 1;
				
				
				if (flippedBlog == 1)
				{
					//$("#blog").delay(300).revertFlip();
					setTimeout(function(){$("#blog").revertFlip();},300);
					flippedBlog = 0;
				}
				if (flippedProgramming == 1)
				{
					//$("#blog").delay(300).revertFlip();
					setTimeout(function(){$("#programming").revertFlip();},300);
					flippedProgramming = 0;
				}
				if (flippedPhoto == 1)
				{
					//$("#blog").delay(300).revertFlip();
					setTimeout(function(){$("#photo").revertFlip();},300);
					flippedPhoto = 0;
				}
				if (flippedCooking == 1)
				{
					//$("#blog").delay(300).revertFlip();
					setTimeout(function(){$("#cooking").revertFlip();},300);
					flippedCooking = 0;
				}
				
			}
			//else
			//	alert("pageshow event handler called for the initial load.  This is the same as the load event.");
		}

		window.addEventListener("pageshow", pageShown, false);

