var _gaq = _gaq || [];
	  _gaq.push(['_setAccount', 'UA-19615317-1']);
	  _gaq.push(['_setSiteSpeedSampleRate', 10]);
	  _gaq.push(['_trackPageview']);
	  (function() {
	    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	  })();

$(document).ready(function(){

	$('#content, #article_background').hide();
	$('#navbar').css({"margin-right":"-165px"}).delay(300).animate({"margin-right":"0px"}, 250, "easeOutQuart");
	$('#logo').addClass('loader');
	
});

$(window).load(function(){

	function contentIntro() {
		document.title = $('#page_title').text();
		
		var featureHeight = $('#home_feature').outerHeight(true);
		$('#home_feature').css({"margin-top":"-"+featureHeight+"px","opacity":"0"}).delay(1200).animate({"margin-top":"0px","opacity":"1"}, 800, "easeOutQuart");
		
	    var rightHeight = $('#right').outerHeight(true);
	    $('#right').css({"margin-top":"-"+rightHeight+"px","opacity":"0"}).delay(200).animate({"margin-top":"0px","opacity":"1"}, 800, "easeOutQuart", function() {
	    	if ($('#next_page').length) { 
	    	 	$('#next_page').hide();
	    	     var nextLoad = $('#next_page a').attr('href')+' #thumbnails';
	    	     $("<div>").load(nextLoad, function(response, status, xhr) {
	    	     	$("#thumbnails").append($(this).children().html());
	    	     	$('#next_page').remove();
	    	     });
	    	   }
	    });
	     		
	    var infoHeight = $('#left').outerHeight(true);
	    $('#left').css({"margin-top":"-"+infoHeight+"px","opacity":"0"}).animate({"margin-top":"0px","opacity":"1"}, 500, "easeOutQuart");
	    
	};
	
	function bgShow() {
		var bgArray = $('#bg_array').text();
		if ($('#bg_array').length) {
			$('#article_background').hide().css({"background-image":"url(" + bgArray + ")"}).delay(1000).fadeIn(500);
		}
	}
	
	$('#logo').delay(200).removeClass('loader');
	$('#content').delay(500).show(0, function() {
		bgShow();
		contentIntro();
	});
	
	
	$("#right article.thumb").live({
	  mouseover: function() {
	  	$('.info', this).stop().animate({"margin-left":"0px"}, 250, "easeOutQuart");
	  },
	  mouseout: function() {
	  	$('.info', this).stop().animate({"margin-left":"-290px"}, 100, "easeInQuart");
	  },
	  mouseup: function() {
	  	$('.info', this).stop().animate({"margin-left":"290px"}, 100, "easeInQuart");
	  }
	}).stop();
	
	$("a[href^='http:']:not([href*='" + window.location.host + "'][target='_blank'])").live('click', function(){
	  $(this).attr('target','_blank'); 
	}); 
  
  	var siteURL = "http://danielhritzkiv.com"
  	var $internalLinks = $("a[href^='"+siteURL+"']:not([href*='file_download']), a[href^='/'], a[href^='./'], a[href^='../']");
	$internalLinks.live("click", function() {
		var toLoad = $(this).attr('href')+' #content';
		//history.pushState(toLoad, $('#page_title').text(), $(this).attr('href'));
		history.replaceState(toLoad, $('#page_title').text(), $(this).attr('href'));
		
		$('#logo').addClass('loader');
		$('#content').animate({"margin-top":"800px","opacity":"0"}, 500, "easeInExpo", function() {
			$('#content').remove();
			$('#article_background').fadeOut(500, function() {
				$(this).css({"background-image":""});
			});
			$("<div>").load(toLoad, function(response, status, xhr) {
				if (status == "error") {
					$('body').append('<section id="content"></section>');
					$('#content').html('<h1>'+xhr.status + " " + xhr.statusText+'</h1><p class="error-msg">The requested resource was not found.</p>');
					$('#logo').delay(200).removeClass('loader');
				}
				if (status == "success") {
					$("body").append($(this).html());
					bgShow();
					$("#content").show(0, function(){
						$('#content').hide().delay(500).show(0, function() {
							$('#logo').delay(200).removeClass('loader');
							contentIntro();
						});
					});
				}
			});
		});
		return false;
	});
	
	
	
	$('#navbar li a').live("click",function() {
	  	$('#navbar li.selected').removeClass("selected");
	  	$(this).parents().addClass("selected");
	});
	  
	$("a[href^='"+siteURL+"/work'], a[href^='/work'], a[href^='./work'], a[href^='../work']").live("click",function() {
	  	$('#navbar li.selected').removeClass("selected");
	  	$('#navbar li.work').addClass("selected");
	});
	
	$("a[href^='"+siteURL+"/about'], a[href^='/about'], a[href^='./about'], a[href^='../about']").live("click",function() {
	  	$('#navbar li.selected').removeClass("selected");
	  	$('#navbar li.about').addClass("selected");
	});
	
	$("a[href^='"+siteURL+"/contact'], a[href^='/contact'], a[href^='./contact'], a[href^='../contact']").live("click",function() {
	  	$('#navbar li.selected').removeClass("selected");
	  	$('#navbar li.contact').addClass("selected");
	});
   
});
