var currentPage = 1;
var minusOne = 1;
var windowWidth = 1;
var width = 1;




$(window).bind('resize', function() {
 width = document.body.offsetWidth;
 windowWidth = "translate("+width+"px"+",0px)";
 negativeWindowWidth = "translate("+width*-1+"px"+",0px)";
 $(".section").hide();
 $(".section:eq("+minusOne+")").show();
 
});



$(document).ready(function(){ 
  
	width = document.body.offsetWidth;
	windowWidth = "translate("+width+"px"+",0px)";
	negativeWindowWidth = "translate("+width*-1+"px"+",0px)";
	//Get the navItem colors from CSS
	var navItemColor = $('#nav a').css('color');
	var navItemSelectedColor = $('.nav-item-selected').css('color');
	//Hide the content until address is Initialized
	$('.wrapper').hide();
	//Close button actions for about page
	$(".close").hover(
	  function () {
	    $(".profile").css("opacity", .4);
	  }, 
	  function () {
	     $(".profile").css("opacity", 1);
	  }
	);

	// Initialize the Address plugin (which is main navigation for site)
 	$.address.init(function(event) {
 		        $('#nav a').address();
        $('.people a').address();
        $('.wrapper').show();
        }).change(function(event) {
					section = event.value;
					if (section == '/'){
						//Define the section the homepage should default to
						section = "/latest";	
					}

	       handlePrimary(section.substr(1)); 	
	        	
   		});                         

	function handlePrimary(targetSection){
		var sectionName = targetSection.split("-", 2);

		
		switch(sectionName[0])
			{
			case "latest":
			  sectionNum = 1
			  break;
			case "services":
			  sectionNum = 2
			  break;
			case "about":
			  sectionNum = 3
			  if (!smirkSmart){
			  startSmirk()
			  console.log(smirkSmart)}
			  break;
			default:
			  sectionNum = 1
			}
			
		
		minusOne = parseInt(sectionNum)-1;


		$(".section:gt("+minusOne+")").css("display" , "none");
		$(".section:lt("+minusOne+")").css("display" , "none");
		$(".section:eq("+minusOne+")").css("display" , "block");
		
		console.log($(".section:eq("+minusOne+")").css("display"))		

/* 		Animation disabled */		
		/*
if ($.browser.webkit) {
    	$(".section").show();
			$(".section:gt("+minusOne+")").css("-webkit-transform" , windowWidth);
			$(".section:lt("+minusOne+")").css("-webkit-transform" , negativeWindowWidth);
			$(".section:eq("+minusOne+")").css("-webkit-transform" , "translate(0%,0)");
 		}	else {
 			$(".section:gt("+minusOne+")").css("display" , "none");
			$(".section:lt("+minusOne+")").css("display" , "none");
			$(".section:eq("+minusOne+")").css("display" , "block");
 		}
		
*/
		$('#nav a').css('color',navItemColor);
		$('#'+sectionName[0]).css('color', navItemSelectedColor); 
		

			handleSubSelection(sectionName[0],sectionName[1]);

		

		currentPage = sectionNum;
				
  };
  
 	function handleSubSelection (primarySection, subSection){
		
		if (subSection == undefined){
			$(".profile").height(0);
			
			$(".profile").css("margin-bottom", "0px");
			$(".profile").css("opacity",0);
			$(".smirktacular").removeClass("smirktacular-clicked");
			$(".person-profile").removeClass("show");
		} else {
			if (primarySection == "about") {
				var descriptionHeight = $("#"+subSection+"-profile .profile-description").height();
				
				$(".profile").height(descriptionHeight+36);
				$(".profile").css("opacity",1);
				$(".profile").css("margin-bottom", "26px");
				$('html, body').animate({scrollTop:0}, 1);
				
				$(".person-profile").removeClass("show");
				$("#"+subSection+"-profile").addClass ("show");

				$(".smirktacular").removeClass("smirktacular-clicked");
				$("#"+subSection+" .smirktacular").addClass("smirktacular-clicked");
			}
		}
		
 	}
 	

 	
});

