$(document).ready(function(){

	$(window).scroll(function() {

		var scrollYpos = $(document).scrollTop();
		var stopScroll = $('.products_page_section').height();
	   	
	    if (scrollYpos > 158 && scrollYpos < stopScroll) {

			$('.close').removeClass('close_top close_bottom').addClass('close_middle').css('margin-top', '0');
	    } 
	 	if (scrollYpos < 158){

	      $('.close').removeClass('close_middle close_bottom').addClass('close_top').css('margin-top', '0');
	    }
	
		if (scrollYpos > stopScroll + 31){
			$('.close').removeClass('close_middle close_top').addClass('close_bottom').css('margin-top', stopScroll - 130 );
		}
	
	}); 

	$("ul.subnav").parent().addClass("drop_down"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

	$("ul.topnav li.drop_down").hover(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
		
		$(this).hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
		});
		
		return false;
		
		});
		
		$('#doctor_link').click(function(){
			$('#patients').slideUp();
			$('#doctors').slideToggle();
			return false;
		});
		
		$('#doctors').click(function(){
			$(this).slideUp();	
			$('html, body').animate({scrollTop:0}, 'slow');
		});
		
		$('#patient_link').click(function(){
			$('#doctors').slideUp();
			$('#patients').slideToggle();
			return false;
		});
		
		$('#patients').click(function(){
			$(this).slideUp();	
			$('html, body').animate({scrollTop:0}, 'slow');
		});
	});
