jQuery(document).ready(function($) {
	if($('body').hasClass('single-portfolio')){
			$('#menu-item-601').addClass('current-menu-item');
	}
	
	// login form
	if($('#loginForm').children('h2').text() ==""){
		$('#loginForm').children('h2').remove();
	}
	
	if($('#loginForm').children("div[class='login_error']").length > 0){
		$('#loginForm').children('div').show();
		$('#loginForm').children('form').show();	
	}
	$('#loginForm').children('h2').click(function(){
		$('#loginForm').children('form').toggle();
		$('#loginForm').children('div').toggle();
	});
	
	// tracking
	$('.link').children('a').click(function(){
		trackViewProject($(this).attr('href'));
	});
	$('#downloadResume').click(function(){ trackEvent('site', 'Download', 'Resume'); });
	$('#linkedInLink').click(function(){ trackEvent('site', 'Out', 'Linkedin profile'); });
	
	$("a[class='jp-play']").click(function(){ startVideoTimer(); trackVideo('play'); });
	$("a[class='jp-pause']").click(function(){ pauseVideoTimer(); trackVideo('pause'); });
	$("a[class='jp-mute']").click(function(){ trackVideo('mute'); });
	$("a[class='jp-unmute']").click(function(){ trackVideo('unmute'); });
	
	var videoTimer = "";
	var videoTimerItt = 0;
	function startVideoTimer(){
		videoTimer = setInterval(
			function(){ videoTimerItt+=1; trackVideo('Progress - ' + videoTimerItt*5 );}
			, 5000 );
	}
	
	function pauseVideoTimer(){
		clearInterval(videoTimer);
	}
	
});

(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=172633556150023";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));


function trackEvent(cat, action, label){
	_gaq.push(['_trackEvent', cat, action, label]); 
}

function trackViewProject(url){
	trackEvent('site', 'Out', url); 
}
function trackVideo(action){
	trackEvent('site', 'Video', action); 
}
