$(document).ready(function(){

	// |----------------------------------------------------------------------------------------
	// | Page Fadein
	// |-----------------------------------------------------------------------------------------

	$(window).load(function(){ 
		
  		 $(".site_wrapper").fadeIn("slow");
  		 
	});
		
	$('a[id^="open_drawer"]')
		.click(function(){
			var drawer_name = $(this).attr('id').split('_')[2];
			$('.drawer_'+drawer_name).slideDown('normal');
		});
		
	$('.close_drawer')
		.click(function(){
			$(this)
				.parent('div')
				.slideUp('normal');
		});
		
		$('#open_call')
		.click(function(){
			$('.phone_num').slideDown('normal');
		});
		
	$('.close_call')
		.click(function(){
			$(this)
				.parent('div')
				.slideUp('normal');
		});
		
	// |----------------------------------------------------------------------------------------
	// | Therapists Pop Out Images
	// |-----------------------------------------------------------------------------------------
		$(".therapist_image img")
			.hover(
				function(){
				$(this)
					.css({
					'z-index' : '200000001'
					})
					
			 	$(this).animate({
						top: '+=30',
						width: '270px'
						// height: '186px'
					}, 200)
					
			},
				function(){
					$(this).css({
					'z-index' : '0'
					})
					
					$(this).animate({
						top: '-=30',
						width: '250px' 
					}, 200)
		});
		
		//LOAD THE OVERLAY
		$(function() {
			$(function(){
			    $("div.therp_overlay").appendTo('body');
			});
			$(".therapist_image img[rel]").overlay({mask: {
                    color: '#acc79c',
                    loadSpeed: 'fast',
                    closeSpeed: 'fast',
                    opacity: 1
                },
                speed: 'fast',
                closeOnClick: false,
                fixed: false
             });
             
		});
		
		//LOAD THE IMAGES
		$('img[class^="therapist"]').each(function(){
		    $(this).bind('load',function(){
		        $(this).fadeIn('slow');
		        
		    })    
		})
		
		
	// |----------------------------------------------------------------------------------------
	// | Doctors Section Pop Out Images
	// |-----------------------------------------------------------------------------------------

	
		
	$("ul.doctor_section li")
		.hover(
			function() {
				var doc = $(this).find('img').attr('title');
				var this_li = $(this);
				
					
				$(this)
					.css({
					'z-index' : '100000001'
					})
					
					.append('<div class="doc_popup"><div class="left_side"></div><div class="right_side"></div><div class="doc_text"></div></div>')
					.find('.doc_text')
					.html(doc)
					.parent('div')
					.fadeIn('slow'); 
				$(this)
					.find('img')
					.css({
						'border' : '1px solid #fff',
						'z-index' : '100000002'
					})
					.animate({
						top: '+=30',
						width: '207px', 
						height: '137px'
					}, 200)
					
	
		} , function() {
				
				$('.doc_popup')
					.fadeOut('fast')
					.remove();
					
				$(this).css({
					'z-index' : '0'
				})
					 
				$(this).find('img').css({
					'border' : 'none',
					'z-index' : '0'
				})
					.animate({
						top: '-=30',
						width: '152px', 
						height: '101px'
					}, 200)
					
	});
	
	// |----------------------------------------------------------------------------------------
	// | Settings For Nivo Slider
	// |-----------------------------------------------------------------------------------------

	 $('#slider').nivoSlider({
	        effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
	        slices: 15, // For slice animations
	        boxCols: 8, // For box animations
	        boxRows: 1, // For box animations
	        animSpeed: 1000, // Slide transition speed
	        pauseTime: 6000, // How long each slide will show
	        startSlide: 0, // Set starting Slide (0 index)
	        directionNav: false, // Next & Prev navigation
	        directionNavHide: true, // Only show on hover
	        controlNav: true, // 1,2,3... navigation
	        controlNavThumbs: false, // Use thumbnails for Control Nav
	        controlNavThumbsFromRel: false, // Use image rel for thumbs
	        controlNavThumbsSearch: '.jpg', // Replace this with...
	        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
	        keyboardNav: true, // Use left & right arrows
	        pauseOnHover: false, // Stop animation while hovering
	        manualAdvance: false, // Force manual transitions
	        prevText: 'Prev', // Prev directionNav text
	        nextText: 'Next', // Next directionNav text
	        beforeChange: function(){
	        	
	        	
	        	
	        }, // Triggers before a slide transition
	        afterChange: function(){
	        	
	        	var float_caption = $('.ref').text();
	        	if(float_caption == 'green'){
	        		$('.nivo-caption')
	        			.css('color' ,'#fff');
	        	}else{
	        		$('.nivo-caption')
	        			.css('color' ,'#fff');
	        	}
	        }, // Triggers after a slide transition
	        slideshowEnd: function(){}, // Triggers after all slides have been shown
	        lastSlide: function(){}, // Triggers when last slide is shown
	        afterLoad: function(){} // Triggers when slider has loaded
    });
    

	
	// |----------------------------------------------------------------------------------------
	// | Main Nav
	// |-----------------------------------------------------------------------------------------
	
	$("div[class^='nav_item']")
		.hover(
			function(){
				$(".sub_nav", this)
					.slideDown("normal")
		},function(){
			$(".sub_nav", this)
				.slideUp("normal");
		});
		
	$('.sub_nav_item')
		.hover(
			function(){
				$(this)
					.css('background','url(/assets/hands/images/site/opaq_brown_40.png) top left repeat');
		}, function(){
			$(this)
				.css('background', 'none');
		});
		
			// |----------------------------------------------------------------------------------------
	// | Form Submission AND CHECK 
	// |-----------------------------------------------------------------------------------------
	
	$('form[id^="form_"]')
		.live('submit',
			  function(event){
				 
				$('.balloon').fadeOut('fast').remove();
				$('.req')
					.each(
						function(){
							
							var $this = $(this);
							var $val_TOF = ($this).val().length;
							var $this_val_id = ($this).attr('id');

							var balloon = '<div class="balloon"><div class="balloon_left"></div><div class="balloon_right"></div><div class="balloon_text"></div>';
							
							
							if($val_TOF <= 0){
								$(this)
									.closest('div.form_row')
									.append(balloon)
									.find('.balloon_text')
									.html('This Field is Required.')
									.parent('div')
									.fadeIn('slow')
								$('#'+$this_val_id)
									.focus()
									.css('background','url(/assets/wapl/images/site/opaq_red_30.png) top left repeat');
									
								event.preventDefault();
								return false;
							}
						});
					
			});
			
	
		// |----------------------------------------------------------------------------------------
	// | Photo Gallery THAT IS BEING USED
	// |-----------------------------------------------------------------------------------------
	
	//THIS LOADS THE GALLERY OVERLAY FROM FRONT PAGE
	$(function() {
		$(function(){
		    $("div.gallery_overlay").appendTo('body');
		});
		$(".photo_img img[rel]").overlay({mask: {
                    color: '#acc79c',
                    loadSpeed: 700,
                    opacity: 1
                },
                closeOnClick: false,
                fixed: false
             });
	});
	
	// |----------------------------------------------------------------------------------------
	// | Photo Gallery THAT IS BEING USED
	// |-----------------------------------------------------------------------------------------		
	
	//THIS IS TO CALL THE OVERLAY
	$(function() {
		$(function(){
		    $("div.gallery_overlay").appendTo('body');
		});
		$("#do_overlay img[rel]").overlay({mask: {
                    color: '#acc79c',
                    loadSpeed: 700,
                    opacity: 1
                },
                closeOnClick: false,
                fixed: false
             });
	});
	
	//THIS SECTION LOADS THE DATA
	$('img[id^="the_image"]')
		.click(
			 function(){
				//alert('hello');
				var parent_id = $(this).attr('pid');
				var child_id = $(this).attr('uid');
				//var gallery_title = $('#gallery_title').val();
				
			$('.gal_image')
					.load('/index.php/AJAX/call_photo_lightbox/'+parent_id+'/'+child_id,
					function(){
							$('#next')
								.live('click', 
									function(){
										parent_id = $('#photo_show').attr('galID');
										p_count = $('#photo_show').attr('photocount');
										
										//analytics('Photos','View Photo', 'Viewed More Photos :'+ gallery_title);
									
										$('.photo_casing')
											.slideUp('fast')
											.load('/index.php/AJAX/call_new_photo/'+parent_id+'/'+p_count+'/next',
												function(){
													//analytics();
													$(this).slideDown('slow');				     
												});
					
									});
				
							$('#prev')
								.live('click', 
									function(){
										parent_id = $('#photo_show').attr('galID');
										p_count = $('#photo_show').attr('photocount');
										
					
										$('.photo_casing')
											.slideUp('fast')
											.load('/index.php/AJAX/call_new_photo/'+parent_id+'/'+p_count+'/prev',
												function(){
													$(this).slideDown('slow');
												});
		
									});	
				
						
						});
	});

		
});

// |*****************************************************************************************
// | END DOCUMENT LOAD
// |*****************************************************************************************
	
	// |----------------------------------------------------------------------------------------
	// | Cleans all Inputs on focus and repopulates them based upon the input alt tag. 
	// |-----------------------------------------------------------------------------------------

	$.fn.clean_input = function() { 
		return $(this).focus(
				 function(){
					$(this).val('')
			}).blur(
				function(){
					if($(this).val() == ''){
						$(this).val( $(this).attr('alt') );
					}
				})
		}
	

	
