var team = "three";
$(document).ready(function() {
	$('a[rel=external]').leaveNotice({
	siteName: 'Turner Barker Insurance',
	exitMessage: '<p><strong>You are now leaving Turner Barker Insurance.</strong></p>',
	timeOut: 0
	});

	equalHeight($(".col"));

	//$('ul.sf-menu').superfish({autoArrows:  false, dropShadows: false });

	$(".newsletter label").inFieldLabels();
	$("#contactform label").inFieldLabels();
       
        $(".images").cycle({
            fx: 'scrollLeft',
            speed: '500',
            timeout: '5000',
            before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
                var theid = $(nextSlideElement).children('img').attr('id');
                if($('.images a img#'+theid).length > 0) {
                    $('.items li').removeClass('currentslide');
                    $('.items li.'+theid).addClass('currentslide');
                    
                    myOffset = -1;
                    if ($('.items li.currentslide').hasClass('first')){
                        $('.activeBg').animate({
                            left: myOffset+'px'
                        },500);
                    } else {
                        $('.activeBg').animate({
                            left: (($('.items li.currentslide').position().left) + myOffset)+'px'
                        },500);
                    }
                    var myHref = $('.items a.'+theid).attr('href');
                    $('.images a').attr('href', myHref);
                }
            }
        });
        $('.items li').hover(function(){
            $('.images').cycle('pause');
            var myIndex = $(this).index();
            $('.images').cycle(myIndex);
        },
        function(){
            $('.images').cycle('resume');
        });

	$("div.employee").toggleClass('hidden');
	toggleTeam("three");
	
	$(".teamGallery li").click(function(){
		var nteam = $(this).attr("class");
		if(nteam != team){
			toggleTeam(team);
			toggleTeam(nteam);
			team = nteam;
		}
	});
	
		$("a.next").click(function(event){
			 event.preventDefault();
			
		var nteam = $(this).attr("class");
		nteam = nteam.replace("next ", "");
		 console.log(nteam);
		if(nteam != team){
			toggleTeam(team);
			toggleTeam(nteam);
			team = nteam;
		}
	});

});

function toggleTeam(className){
	$("li."+className).toggleClass("active");
	$("div.employee."+className).toggleClass('hidden');
}

function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
