	$(document).ready(function() {
	
		$('#navigation a, .logo-link').click(function(e){
			if ($(this).hasClass('call')||$(this).hasClass('email')||$(this).hasClass('locate')){
			}else {
				e.preventDefault();
			}
		});
		
		$('#who-link').click(function(){
			_gaq.push(['_trackEvent', 'Followed_Links', 'Who We Are']);
		});
		$('#work-link').click(function(){
			_gaq.push(['_trackEvent', 'Followed_Links', 'Interactive Work']);
		});
		$('#awards-link').click(function(){
			_gaq.push(['_trackEvent', 'Followed_Links', 'Awards']);
		});
		$('.call').click(function(){
			_gaq.push(['_trackEvent', 'Contact_Links', 'Call AT']);
		});
		$('.email').click(function(){
			_gaq.push(['_trackEvent', 'Contact_Links', 'Email Us']);
		});
		$('.locate').click(function(){
			_gaq.push(['_trackEvent', 'Contact_Links', 'Locate Us']);
		});
		
		var windowWidth = $(window).width();
		var windowHeight = $(window).height();

			var myintroHt = $("div#intro").height();
			var mywhoHt = $("div#who").height();
			var myworkHt = $("div#work").height();
			var myawardsHt = $("div#awards").height();
			var myTtl = myintroHt + mywhoHt + myworkHt + myawardsHt;
			
		function updateWindowDimensions() {
			windowWidth = $(window).width();
			windowHeight = $(window).height();		
		
			 // $("div#content").css({"width": windowWidth, "height": windowHeight, "position":"fixed"});
			$("div#navigation").css({"position":"absolute","z-index":"200","width":"320","left":"0","margin-top":windowHeight/4+60});
			$("div#home-button").css({"position":"absolute","z-index":"200","width":"92","right":"30px","top":"30px"});
			
			if(windowWidth == "768") {
				// portrait view
				$("#portrait_styles").remove();
				$("#landscape_styles").remove();
				$("head").append('<link rel="stylesheet" id="portrait_styles" type="text/css" href="portrait_especial.css" />');
				$("div#intro").css({"width":windowWidth, "height":windowHeight});
				$("div#who").css({"width":windowWidth, "height":windowHeight});
				$("div#work").css({"width":windowWidth, "height":windowHeight});
				$("div#awards").css({"width":windowWidth, "height":windowHeight});
			} else {
				// landscape view
				$("#portrait_styles").remove();
				$("#landscape_styles").remove();
				$("head").append('<link rel="stylesheet" id="lanscape_styles" type="text/css" href="landscape_especial.css" />');
				$("div#intro").css({"width":windowWidth, "min-height":windowHeight});
				$("div#who").css({"width":windowWidth, "min-height":windowHeight});
				$("div#work").css({"width":windowWidth, "min-height":windowHeight});
				$("div#awards").css({"width":windowWidth, "min-height":windowHeight});
			}
			
			myintroHt = $("div#intro").height();
			mywhoHt = $("div#who").height();
			myworkHt = $("div#work").height();
			myawardsHt = $("div#awards").height();
			myTtl = myintroHt + mywhoHt + myworkHt + myawardsHt;	
			
			$("div#content").css({"min-height":myTtl});
			
		}
		
		// body width/height assignments
			windowWidth = $(window).width();
			windowHeight = $(window).height();
			
			$("div#navigation").css({"position":"absolute","z-index":"200","width":"320","left":"0","margin-top":windowHeight/4+60});
			$("div#home-button").css({"position":"absolute","z-index":"200","width":"92","right":"30px","top":"30px"});
			
			if(windowWidth == "768") {
				// portrait view
				$("#portrait_styles").remove();
				$("#landscape_styles").remove();
				$("head").append('<link rel="stylesheet" id="portrait_styles" type="text/css" href="portrait_especial.css" />');
				$("div#intro").css({"width":windowWidth, "height":windowHeight});
				$("div#who").css({"width":windowWidth, "height":windowHeight});
				$("div#work").css({"width":windowWidth, "height":windowHeight});
				$("div#awards").css({"width":windowWidth, "height":windowHeight});
			} else {
				// landscape view
				$("#portrait_styles").remove();
				$("#landscape_styles").remove();
				$("head").append('<link rel="stylesheet" id="lanscape_styles" type="text/css" href="landscape_especial.css" />');
				$("div#intro").css({"width":windowWidth, "min-height":windowHeight});
				$("div#who").css({"width":windowWidth, "min-height":windowHeight});
				$("div#work").css({"width":windowWidth, "min-height":windowHeight});
				$("div#awards").css({"width":windowWidth, "min-height":windowHeight});
			}
			myintroHt = $("div#intro").height();
			mywhoHt = $("div#who").height();
			myworkHt = $("div#work").height();
			myawardsHt = $("div#awards").height();
			myTtl = myintroHt + mywhoHt + myworkHt + myawardsHt;	
			
			$("div#content").css({"min-height":myTtl});
			
		window.onorientationchange = updateWindowDimensions;
		
		updateWindowDimensions();
		
		
		function scrollToClosestAd() {

			var firstOffset = $("div#content").scrollY - $("div#intro").offset().top;
			var secondOffset = $("div#content").scrollY - $("div#who").offset().top;
			var thirdOffset = $("div#content").scrollY - $("div#work").offset().top;
			var fourthOffset = $("div#content").scrollY - $("div#awards").offset().top;
			var fifthOffset = $("div#content").scrollY - $("div#menu").offset().top;

			var offsetValues = [firstOffset, secondOffset, thirdOffset, fourthOffset, fifthOffset];
			var offsetNegatives = []; // open new empty array for all the negatives to go into.
			for (var i = offsetValues.length - 1; i >= 0; --i) { // loop through values (positives and negatives at this point)
				if (offsetValues[i] < 0) { // if the number is negative...
					offsetValues[i] = offsetValues[i] * -1; // multiply it by negative 1 to make it positive
					offsetNegatives.push(offsetValues[i]); // push that new positive number into that new array (the one that was empty)
					offsetValues.splice(offsetValues[i], 1); // remove that number from the original array
				}
			}

			offsetValues.sort(function (a, b) { return a - b }); // sort numbers according to their value
			offsetNegatives.sort(function (a, b) { return a - b }); // sort numbers according to their value

			if (offsetNegatives.length == 0) {
				$("#content").animate({ scrollTop: window.scrollY - offsetValues[0] }, 500);
			} else {

				if (offsetValues[0] < offsetNegatives[0]) { // if the smallest number was a positive integer that means that the closest div is above the current y...
					$("#content").animate({ scrollTop: $("div#content").scrollY - offsetValues[0] }, 500);
				} else { // if it is a negative number, that means the closest div is below the current windows y position...
					$("#content").animate({ scrollTop: $("div#content").scrollY + offsetNegatives[0] }, 500);
				}
			}
		}

	});
	
	
