/*

- Sparrow House Counseling
- http://sparrowhousecounseling.com/
- designed by Switch Creative Group
- http://www.groupswitch.com

*/

/* ! ---- Site Functions ---- */
/* ---------------------------------------------------- */
	
	$(document).ready(function(){
		
		
		/* ! Book Image | Width for Outer Glow */
		/* ---------------------------------------- */
			book_shadows();
			
		
		/* ! Meet the Team | colour roll overs */
		/* ---------------------------------------- */
			// meet_the_team();		
			meet_the_team2();
		
		
		/* ! Practice Areas | list columns */
		/* ---------------------------------------- */
			// list_columns();
			
		
		/* ! Practice Areas | colour roll overs */
		/* ---------------------------------------- */
			practice_areas();
				
		
		/* ! Main Nav | colour roll overs */
		/* ---------------------------------------- */
			
			// create end position array
			var colour_pos = new Array( -100,		// home
																	-65,		// about
																	-5,			// practice
																	-10,		// team
																	-45,		// resources
																	 -70);	// contact
			
			// find which position to move it to
			function find_movement(parent) {
				
				switch(parent) {
					
					case "mn_home": 			
						return colour_pos[0];
						break;
					case "mn_about": 			
						return colour_pos[1];
						break;
					case "mn_practice": 	
						return colour_pos[2];
						break;
					case "mn_team": 			
						return colour_pos[3];
					  break;
					case "mn_resources":	
						return colour_pos[4];
					  break;
					case "mn_contact":		
						return colour_pos[5];
					  break;
					}
				
			}
			
			// create movement of rollover
			$('#mn_list > li').not('#li_active').hover(
			
					function(){
						var parent = $(this).attr('id');
						$(this).find('.colour')
							.stop(true, false)
							.animate({ left: find_movement(parent) + 'px' }, 'slow', 
									function(){
										$(this).prev().addClass('active'); 
										});
					},
					
					function(){
						var colour = $(this).find('.colour');
						
						if (!colour.hasClass('c_active')) {
							$(this).find('.colour')
							.stop(true, false)
							.animate({ left: '-205px' }, 'slow').prev().removeClass('active');
						}
						
					});


			// use bind and unbind to turn off navigation when it is active
			function main_nav_click() {
			
				$(this).unbind('click', main_nav_click);
				
				if($('#mn_list .li_active').length >= 1) {
					
					var old = $('#mn_list .li_active');
					old.find('a:eq(0)').removeClass('active').bind('click', main_nav_click)
						.next().animate({ left: '-205px' }, 'slow').removeClass('c_active')
						.next().slideToggle('slow');
					window.setTimeout(function(){
						old.removeClass('li_active');
						}, 750);

				}
				
				$(this).addClass('active');
				$(this).parent().addClass('li_active');
				$(this).next().addClass('c_active');
				
				if (sub = $(this).next().next()) {
					sub.slideToggle('slow');
				}
				
				return false;	
			
			}
			
			
			// bind eveything to the main_nav_click() function at the beginning
			$('#mn_list li > a').bind('click', main_nav_click);
			$('#mn_home > a, #logo > a, .mn_sub a').unbind('click', main_nav_click);
			
			
			// change links out for localScroll			
			$('#mn_home > a, #logo > a').attr('href','#home');
			$('#mn_about > a').attr('href','#about-us');
			$('#mn_practice > a').attr('href','#practice-areas');
			$('#mn_team > a').attr('href','#meet-the-team');
			$('#mn_resources > a').attr('href','#resources');
			$('#mns_books > a').attr('href','#books');
			$('#mn_contact > a').attr('href','#contact');
			
			$.localScroll({
				hash: true,
				duration: 750
				});
			
			
			// use this to find out which sub nav is either being hovered or clicked
			function find_clicked(clicked) {
				switch(clicked) {
					case "mns_individual": 			
						return 'ph_indiv';
						break;
					case "mns_family": 			
						return 'ph_family';
						break;
					case "mns_marriage": 			
						return 'ph_marriage';
						break;
					case "mns_teen": 			
						return 'ph_teen';
						break;
					case "mns_buja": 			
						return 'tl_buja';
						break;
					case "mns_page": 			
						return 'tl_page';
						break;
					case "mns_lytle": 			
						return 'tl_lytle';
						break;
					case "mns_miller": 			
						return 'tl_miller';
						break;
					case "mns_sevadjian": 			
						return 'tl_sevadjian';
						break;
					case "mns_clark": 			
						return 'tl_clark';
						break;
					case "mns_students": 			
						return 'tl_students';
						break;
				}
			}
			
			// create actions for sub nav to match Practice Areas and Meet the Team sub nav
			$('.mn_sub a').click(function(){

				$(this).parent().parent().find('.active').removeClass('active');
				$(this).addClass('active');
				
				var clicked = find_clicked($(this).parent().attr('id'));
				$('#' + clicked + ' a').trigger('click');
				
				return false;
				
			});
			
			
			$('.mn_sub a').hover(
				function(){
					var clicked = find_clicked($(this).parent().attr('id'));
					$('#' + clicked + ' a').trigger('mouseover');
				}, 
				function(){
					var clicked = find_clicked($(this).parent().attr('id'));
					$('#' + clicked + ' a').trigger('mouseout');
				}
			);
		
	
	});
	
	
	/* ! Book Image | Width for Outer Glow */
	/* ---------------------------------------- */
	function book_shadows() {
		$('.book_img').each(function(){
			var height 	= $(this).find('img').height();
			var width		= $(this).find('img').width();
			$(this).css({ 'height':height+'px', 
										'width':width+'px',
										'margin':'15px auto' });
		});
	}
	
	
	/* ! Practice Areas | list columns */
	/* ---------------------------------------- */
	function list_columns() {
		$('.list_columns').each(function(){
			$(this).makeacolumnlists({cols:2,colWidth:225,equalHeight:false,startN:1});
		});
	}
	
	
	/* ! Meet the Team | colour roll overs */
	/* ---------------------------------------- 
	function meet_the_team() {
	
		$('#th_list a').hover(
			function(){
				$(this).next().stop(true, false).animate({
					height: '82px',
					bottom: '19px'
				}, 'slow');
			},
			function(){
				if($(this).hasClass('th_selected') == false) {
					$(this).next().stop(true, false).animate({
						height: '360px',
						bottom: '0'
					}, 'slow');
				}
			});
		
		$('#th_buja .img_colour').css({ 'height': '82px', 'bottom': '19px' }).prev().addClass('th_selected');
		
		
		// turn on and off the right pages
		$('#angie-knight-buja').addClass('th_visible');
		$('#becky-page, #steven-k-lytle, #wendy-miller, #cristina-sevadjian').hide();
		
		
		// create the navigation for each page
		$('#th_list a').click(function(e){
			
			$.scrollTo($('#meet-the-team'), {duration:750});
			
			$('#th_list a.th_selected').removeClass('th_selected').next().stop(true, false).animate({
						height: '360px',
						bottom: '0'
					}, 'slow');
			$(this).addClass('th_selected');
			
			$('#meet-the-team .th_visible').hide().removeClass('.th_visible');
			
			if($(this).parent().attr('id') == 'th_buja') {
				$('#angie-knight-buja').fadeIn('slow').addClass('th_visible');
			}
			
			if($(this).parent().attr('id') == 'th_page') {
				$('#becky-page').fadeIn('slow').addClass('th_visible');
			}
			
			if($(this).parent().attr('id') == 'th_lytle') {
				$('#steven-k-lytle').fadeIn('slow').addClass('th_visible');
			}
			
			if($(this).parent().attr('id') == 'th_miller') {
				$('#wendy-miller').fadeIn('slow').addClass('th_visible');
			}
			
			if($(this).parent().attr('id') == 'th_sevadjian') {
				$('#cristina-sevadjian').fadeIn('slow').addClass('th_visible');
			}

			e.preventDefault();
			
		});
	
	}
	*/
	
	/* ! NEW ! */
	/* ! Meet the Team | colour roll overs */
	/* ---------------------------------------- */
	function meet_the_team2() {
	
		$('#team_list a').hover(
			function(){
				
				$(this).next().not('.active').css('opacity',0);
				$(this).next().not('.active').stop().animate({
														opacity: 1,
														width:'690px',
														}, 1000);
														
			},
			function(){
		
				$(this).next().not('.active').stop().animate({
														opacity: 0,
														width:'0',
														}, 1000);
			});
		
		
		// turn on and off the right pages to get started
		$('#angie-knight-buja').addClass('th_visible');
		$('#becky-page, #steven-k-lytle, #wendy-miller, #cristina-sevadjian, #will-clark, #practicum-students').hide();
			
		$('#team_list a').click(function(){
			
			// init some vars
			var parent = $(this).parent();
			var parentid = parent.attr('id');
			var teamheader = $('#team_header');
			
			// show and hide the color for active pages
			teamheader.find('.active').removeClass('active').addClass('old');
			$(this).next().addClass('active');
			teamheader.find('.old').animate({
																	opacity: 0,
																	width:'0',
																	}, 1000, function(){ $(this).removeClass('old'); });
			
			// show the correct background &&
			// change to active state in main navigation
			$('#mn_team ul').find('.active').removeClass('active');
			
			if ( parentid == "tl_buja" ) {
				teamheader.animate({ backgroundPositionY:0 }, 1000);
				$('#mns_buja a').addClass('active');
			} else if ( parentid == "tl_clark" ) {
				teamheader.animate({ backgroundPositionY:"-360px" }, 1000);
				$('#mns_clark a').addClass('active');
			} else if ( parentid == "tl_lytle" ) {
				teamheader.animate({ backgroundPositionY:"-720px" }, 1000);
				$('#mns_lytle a').addClass('active');
			} else if ( parentid == "tl_miller" ) {
				teamheader.animate({ backgroundPositionY:"-1080px" }, 1000);
				$('#mns_miller a').addClass('active');
			} else if ( parentid == "tl_page" ) {
				teamheader.animate({ backgroundPositionY:"-1440px" }, 1000);
				$('#mns_page a').addClass('active');
			} else if ( parentid == "tl_sevadjian" ) {
				teamheader.animate({ backgroundPositionY:"-1800px" }, 1000);
				$('#mns_sevadjian a').addClass('active');
			} else if ( parentid == "tl_students" ) {
				teamheader.animate({ backgroundPositionY:"-2160px" }, 1000);
				$('#mns_students a').addClass('active');
			}
			
			 
			
			// make nav change pages
			$.scrollTo($('#meet-the-team'), {duration:750});
			
			$('#meet-the-team .th_visible').hide().removeClass('.th_visible');
			
			if(parentid == 'tl_buja') {
				$('#angie-knight-buja').fadeIn('slow').addClass('th_visible');
			}
			
			if(parentid == 'tl_page') {
				$('#becky-page').fadeIn('slow').addClass('th_visible');
			}
			
			if(parentid == 'tl_lytle') {
				$('#steven-k-lytle').fadeIn('slow').addClass('th_visible');
			}
			
			if(parentid == 'tl_miller') {
				$('#wendy-miller').fadeIn('slow').addClass('th_visible');
			}
			
			if(parentid == 'tl_sevadjian') {
				$('#cristina-sevadjian').fadeIn('slow').addClass('th_visible');
			}
			
			if(parentid == 'tl_clark') {
				$('#will-clark').fadeIn('slow').addClass('th_visible');
			}
			
			if(parentid == 'tl_students') {
				$('#practicum-students').fadeIn('slow').addClass('th_visible');
			}
			
			return false;
			
		});
			
			
	
	}
	
	
	
	/* ! Practice Areas | colour roll overs */
	/* ---------------------------------------- */
	function practice_areas() {
	
		// take care of the hovers
		$('#ph_list a').hover(
			function(){
				$(this).next().stop(true, false).animate({
					height: '76px',
					bottom: '34px'
				}, 'slow');
			},
			function(){
				if($(this).hasClass('ph_selected') == false) {
					$(this).next().stop(true, false).animate({
						height: '360px',
						bottom: '0'
					}, 'slow');
				}
			});
		
		$('#ph_indiv .img_colour').css({ 'height' : '76px', 'bottom' : '34px'}).prev().addClass('ph_selected');
		
		// turn on and off the right pages 
		$('#individual-counseling').addClass('ph_visible');
		$('#family-counseling, #pre-marital-marriage-counseling, #teen-counseling').hide();
		
		
		// create the navigation for each page
		$('#ph_list a').click(function(e){
			
			$.scrollTo($('#practice-areas'), {duration:750});
			
			$('#ph_list a.ph_selected').removeClass('ph_selected').next().stop(true, false).animate({
						height: '360px',
						bottom: '0'
					}, 'slow');
			$(this).addClass('ph_selected');
			
			$('#practice-areas .ph_visible').hide().removeClass('.ph_visible');
			
			if($(this).parent().attr('id') == 'ph_indiv') {
				$('#individual-counseling').fadeIn('slow').addClass('ph_visible');
			}
			
			if($(this).parent().attr('id') == 'ph_family') {
				$('#family-counseling').fadeIn('slow').addClass('ph_visible');
			}
			
			if($(this).parent().attr('id') == 'ph_marriage') {
				$('#pre-marital-marriage-counseling').fadeIn('slow').addClass('ph_visible');
			}
			
			if($(this).parent().attr('id') == 'ph_teen') {
				$('#teen-counseling').fadeIn('slow').addClass('ph_visible');
			}

			e.preventDefault();
			
		});
		
		list_columns();
	
	}
	
	
	function book_footer(){
		$('.book_footer a').click(function(){
			$('#mns_books a').trigger('click');
			return false;
		});
	}
	
	
	
