    			$(document).ready(function(){
				
				$(".flipAbout").click(function(e){
                    e.preventDefault();
					refreshPage("about");
					$(this).addClass('nav_on');   
				});
				$(".flipNews").click(function(e){
                    e.preventDefault();                
					refreshPage("news");                    
				});
				$(".flipMerch").click(function(e){
                    e.preventDefault();
					refreshPage("merch");                    
				});
				$(".flipTour").click(function(e){
                    e.preventDefault();
                    refreshPage("tour");
				});
				$(".flipContact").click(function(e){
                    e.preventDefault();
                    refreshPage("contact");
				});
				$(".flipExcerpt").click(function(e){
                    e.preventDefault();
                    refreshPage("excerpt");
				});
				
				$(".flipWebComic").click(function(e){
                    e.preventDefault();
                    refreshPage("webcomic");
				});									
				
				/*$("ul#nav li a").click(function(e){
					e.preventDefault();
					$("ul#nav li a").removeClass('on');
					var thePageID = $(this).attr("class");
					thePageID = thePageID.split("flip");
					$(this).addClass('nav_on');
                    refreshPage(thePageID[1].toLowerCase());
				});
				*/
				
				//QR Box			
				$(".qrWin").click(function(e){
					theQRWinDivId = $(this).attr('id');
					$("#" + theQRWinDivId + "Div").show();
					e.preventDefault();
				});
				
				//Get QS variable
				if (getQueryVariable("w").length > 0){
					refreshPage(getQueryVariable("w"));
				}
				else {
					refreshPage("dashboard"); 
				}
				
				//generic close			
				$("a.close").click(function(e){
					$(this).parent().parent().parent().hide();
					e.preventDefault();
				});

				                													
			});
            
            function hideAll(){
                $("#flipBox div").hide();
            }
            
            function chkLength(evt,len){
         		var str = document.getElementById(evt.id);
         			if(str.value.length < len){return true;}
        			else{return false;}
			}
			function refreshPage(page){
					var pageExt = (page == "news" || page == "tour" || page == "webcomic" || page == "webcomiclist" || page == "dashboard" || page == "webcomictag") || (page == "ipad")? ".php" : ".html";
					var QS = ""
					
					if (page == "dirty"){
						page = "dirrty";
					}
					
					if (page == "webcomic"){						
						if (getQueryVariable("c").length > 0){
						QS = "?w=webcomic&c=" + getQueryVariable("c");
						$("#tmButton").show();
						$("#fbButton").show();						
						}
					}
					else{$("#tmButton").hide();
						 $("#fbButton").hide();
						}
					
					if (page == "webcomictag"){						
						if (getQueryVariable("t").length > 0){
						QS = "?w=webcomictag&t=" + getQueryVariable("t");					
						}
					}
						
                    $.ajax({
					  url: page + pageExt + QS,
					  cache: false,
					  success: function(html){
					    $("#flipBox").html(html);
					  }
					});
					$("#flipBox").flip({
						direction: 'tb',
						color: '#FFF',
						speed: 600
					});	
					
					if ((page == "about")||(page == "news")||(page == "merch")||(page == "tour")||(page == "contact")||(page == "excerpt")||(page == "webcomic")||(page == "webcomiclist")){
						var pageName = page.substr(0, 1).toUpperCase() + page.substr(1);
						if(pageName == "tour"){pageName = "Events";}
						if(pageName == "webcomic"){pageName = "Web Comic";}
						$("title").text("48 days in harajuku, tokyo: " + pageName);	
					}	
					
					if ((page == "excerpt") || (page == "dashboard") || (page == "ipad")){$("#flipBox").height(1000);}
					else if (page == "merch"){$("#flipBox").height(900);}
					else if (page == "webcomic"){$("#flipBox").height(2000);}
					else if ((page == "webcomiclist")||(page == "webcomictag")){$("#flipBox").height(1125);}
					else if (page == "designfesta"){$("#flipBox").height(1300);}
					else{$("#flipBox").height(600);}	
			}
			
			function getQueryVariable(variable) { //GET QUERYSTRING JS VERSION
				var query = window.location.search.substring(1);
				query = query.replace("&amp;",";AMP;")
				var vars = query.split("&");
				for (var i=0;i<vars.length;i++) {
				var pair = vars[i].split("=");
					if (pair[0] == variable) {
					return pair[1];
					}
				}
				return "dashboard";
			} 
