var currentVid = '';



$(function(){
	
	var prevDiv = null;
	var prevID = null;
	
	var leftNavDiv = $('#careersFilterNav').children();
	
	$.each(leftNavDiv, function(i){
		$(this).attr("id",'lNav'+i)
	});
	
	
	$('#careersFilterNav h2').click(function(){
		
		var list = $(this).parent().children('ul');
		var curID =$(this).parent().attr("id")
		
		if(prevID == curID){

			
			list.stop().slideToggle("fast");
			
			
			prevDiv = null;
			prevID = null
			
		}else{		
			
			if(prevDiv == null ){
				list.stop().slideToggle("fast");
				console.log("null")
			}
			
			if(prevDiv != null){
				console.log("not null")
				prevDiv.slideToggle(function(){
					list.stop().slideToggle("fast");
				});
			}
			
			prevDiv = list;
			prevID = $(this).parent().attr("id");
		}

		
		
		
		_gaq.push(['_trackEvent', 'Careers', 'Left Nav', $(this).text() ]);
	});
	
	
	
	
	$('.contact-numbers h3').click(function(){
		
		var list = $(this).parent().children(".contact-details");
		var curID =$(this).parent().attr("id")
		console.log(list,curID)
		if(prevID == curID){

			
			list.stop().slideToggle("fast");
			
			
			prevDiv = null;
			prevID = null
			
		}else{		
			
			if(prevDiv == null ){
				list.stop().slideToggle("fast");
				console.log("null")
			}
			
			if(prevDiv != null){
				console.log("not null")
				prevDiv.slideToggle(function(){
					list.stop().slideToggle("fast");
				});
			}
			
			prevDiv = list;
			prevID = $(this).parent().attr("id");
		}

		
		
		
	//	_gaq.push(['_trackEvent', 'Careers', 'Left Nav', $(this).text() ]);
	});
	
	
	
	
	$('#cultureOverlay .blocker').click(function(){
		$("#cultureOverlay").hide();
		$("body").append($("#cultureOverlay"));
		
	});
	
	$('#reelOverlay .blocker').click(function(){
		$("#reelOverlay").hide();
		$("body").append($("#reelOverlay"));
		
	});
	
	$('#zappOverlay .blocker').click(function(){
		$("#zappOverlay").hide();
		$("body").append($("#zappOverlay"));
		
	});
	
	
	$('.vOver .close').click(function(){
		$(currentVid).hide();
		$("body").append($(currentVid));
		
	});
	
	
	
});


$(window).load(function() {
   var url = "http://twitter.com/status/user_timeline/zaazagency.json?count=3&callback=?";
 
    $.getJSON(url,
        function(data){
            $.each(data, function(i, item) {
            	
            	var status = item.text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
			      return '<a href="'+url+'" target="_blank">'+url+'</a>';
			    }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
			      return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
			    });
			    
            	$("#twitter_update_list").append("<li>"+status+"</li>");
            	
            	$("#loadImg").hide();
        });
    });




});
function closeVideo(){

	$(currentVid).hide();
	$("body").append($(currentVid));
	currentVid = null;
	
}


function displayOverlay(div,mthis){
	
	var videoTarget = $(mthis).attr('href')
	var theDiv = $(div)
	
	$('.hero').prepend(theDiv)
	$(theDiv).show();
	


	if($('html').hasClass("no-canvas")){
		
		
	}else{
		
		$(videoTarget+"Video").get(0).play();
	}
	
	
	currentVid = div;

	

	
	var whichVideo = $(mthis).attr('href');
	
	if(whichVideo == "#reel"){
		
		_gaq.push(['_trackEvent', 'Video', 'Play', 'Reel']);
	}else if(whichVideo == "#culture") {
		
		_gaq.push(['_trackEvent', 'Video', 'Play', 'Culture']);
	}else if(whichVideo == "#zapp") {
		
		_gaq.push(['_trackEvent', 'Video', 'Play', 'Z-App']);
	}
	
}

function displayPopup(div,mthis){
	
	if ($(div).hasClass("init")) {
   	 $(div).overlay().load();
	}
	else {
	    $(div).addClass("init");
	    $(div).overlay({ 
	     mask: { color: '#111',
	         loadSpeed: 1000,
	         opacity: 0.8
	     },
	     
	     closeOnClick: true,
	     load: true
	    });
	}
	
	
}

function track(num , team, title ){
	if(num == 0){
		_gaq.push(['_trackEvent', 'Video', 'Tab', 'Reel']);
		if(currentVid != null){
		closeVideo();
		}
	}
	if(num == 1){
		_gaq.push(['_trackEvent', 'Video', 'Tab', 'Culture']);
		if(currentVid != null){
		closeVideo();
		}
	}
	if(num == 2){
		_gaq.push(['_trackEvent', 'Video', 'Tab', 'Z-app']);
		if(currentVid != null){
		closeVideo();
		}
	}
	if(num == "careersLink"){
		_gaq.push(['_trackEvent', 'Careers', 'Top Nav', 'Click']);
	}
	
	if(num == "Facebook" || num == "Vimeo" || num == "Twitter" || num == "LinkedIn"){
		_gaq.push(['_trackEvent', 'Social Media', num , 'Latest']);
	}
	if(num == "directionsLink"){
		_gaq.push(['_trackEvent', 'Contact', 'Directions', 'Map']);
	}
	
	if(num == "article"){
		_gaq.push(['_trackEvent', 'Publications', 'AWA Book', 'View Article']);
	}
	if(num == "pdf1"){
		_gaq.push(['_trackEvent', 'Publications', 'PDF', 'Digital Privacy']);
	}
	if(num == "pdf2"){
		_gaq.push(['_trackEvent', 'Publications', 'PDF', 'Mobile Search']);
	}
	
	var full = team+': '+title;
	if(num == "career"){
		
	    _gaq.push(['_trackEvent', 'Careers', 'Home', full]);
	}
	if(num == "careerdetail"){

		_gaq.push(['_trackEvent', 'Careers', 'Left Nav', full]);
	}
	if(num == "resume"){
		_gaq.push(['_trackEvent', 'Careers', 'Send Resume', full]);
	}
	
	if(num == "amazon"){
		_gaq.push(['_trackEvent', 'Publications', 'AWA Book', 'Order on Amazon']);
	}
	
	
}

