/* -----------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
	
	nvd.chicodev.com
	Stylesheet: public/main.js
	Author: Brent White, Ben Green, chicowebdesign.com
	Version: December 3, 2009
	
--------------------------------------------------------------------------------------
----------------------------------------------------------------------------------- */
jQuery(function($) {


	/* -----------------------------------------------------------------------------------
	LAST CHILD / FIRST CHILD : ADD FIRST / LAST CLASSES
	----------------------------------------------------------------------------------- */
	jQuery('li:last-child').addClass('last');
    jQuery('li:first-child').addClass('first');
    
	/* -----------------------------------------------------------------------------------
	ODD CHILD / EVEN CHILD : ADD ODD / EVEN CLASSES
	----------------------------------------------------------------------------------- */
	jQuery('ul.resources li:odd').addClass('even');
	jQuery('ul.resources li:even').addClass('odd');
	
	jQuery('#banner').cycle();
	
	/* -----------------------------------------------------------------------------------
	DOCTOR SLIDER
	----------------------------------------------------------------------------------- */
	var slide_delay=3000;
	var trans_speed=1000;
	var do_dr_slide=true;
	var cur_active=1;
	var goto_next=function(){
		//move if the user hasn't moused over anything
		if(do_dr_slide){
			cur_active++;
			//loop back if past the end
			if(cur_active==8){cur_active=1;};
			//call the mouseenter function
			$("#meet_the_team li:nth-child("+cur_active+") a").mouseenter();
			//reset the mouseover flag (we didn't really use the  mouse)
			do_dr_slide=true;
			//do this again
			setTimeout(goto_next,slide_delay);
		}
	};
	setTimeout(goto_next,slide_delay);
	
	$("#meet_the_team li a").mouseenter(function(){
		//stop the auto-slide now that you're mousing on your own
		do_dr_slide=false;
		//only do anything if the active is going to change
		if($(this).parent().hasClass("active")){
		}else{
			//set the zindex of all the images down
			$(this).parent().parent().children("li").each(function(){
				$(this).children("a").children("img").css("z-index","1");
			});
			var cactive=$(this).parent().parent().children(".active");
			//set the last active image zindex up
			cactive.children("a").children("img").css("z-index","25");
			//set the current image zindex to the top
			$(this).children("img").css("z-index","26");
			//fade the current image
			$(this).children("img").fadeTo(0,0).fadeTo(trans_speed,1);
			cactive.removeClass("active");
			$(this).parent().addClass("active");
			
			//move the pointer
			var newtop=$(this).position();
			newtop=Math.ceil(newtop.top)+3;
			var pointer=$("#meet_the_team").children("img.pointer");
			pointer.stop().animate({"top":newtop+"px"},trans_speed/2);
		};
	});
});
