$(document).ready(function() {

	// Slideshow for the home page
	$('#slider').cycle({
		timeout: 6000,		
		after: onAfter
	});

	// tabbed nav for the resources and contact pages
	$('.tabbed_nav li a').click(function(){ 
		$('.tabbed_nav .current').removeClass('current');
		$(this).parent().addClass('current');
		$('.resources_content').hide();
		$('.contact_content').hide();
		var content_show = $(this).attr('href');
		$(content_show+'_box').fadeIn('fast');
		$('input.multiplesubmits').hide();
	});
	
	processHashes();
	
	$('#nav ul a').click(function(e)
	{ // Handles #nav dropdowns to allow them to set pages, too
		this_hash = $(this).attr('href');
		var subhash = this_hash.split('#');
		hash = subhash[1];
		processHashes('#'+hash);
	});	
	
	
	/* Handle empower pages */
	$(window).hashchange( function(){
		var hash = location.hash;
		
		if( hash.substring(0, 8) == '#empower' ) {
			$('#secondary_tabs .tabs a').removeClass('current');
			
			var thisTabSelector = hash + '-tab';
			$(thisTabSelector).addClass('current');
			
			$('.pane_content').hide();
			$(hash).show();
		} 
	}); 
	
	/* Empower video modal window */
	$('#empower_button_overlay').click(function(){
		$('#overlay').animate({ opacity : .85 });
	 	$('#overlay').fadeIn(); 
 		$('#modal_video').fadeIn(); 
	});
	
	$('#modal_video a').click(function(){ 
		$('#overlay').fadeOut();
		$('#modal_video').fadeOut();
	});	
	
	$(window).hashchange();

	
	
	
});



	function open_lower_panel()
	{// Part of the copied-over empower script. Could do something fun with this. 
	 // Triggered halfway through empower video.
	
	}

	function onAfter()
	{ // Slidehow z-index management
		$(this).parent().children().css('z-index', '1');
		$(this).css('z-index', '99');
	}


	function processHashes(intake){
		// Process hash-tag navigation so external bookmarks will work on resources page
		// Could replace with hashchange.
		var resources_hashes = [ '#glossary', '#video-library', '#helpful-links', '#forms', '#patient-satisfaction-survey', '#cataract-lifestyle-survey' ];
		var contact_hashes = [ '#contact', '#locations', '#rx-refill', '#santafe' ];
		var doctortest_hashes = [ '#dr-vocci', '#dr-wehrly', '#dr-terpstra', '#dr-holman'];

		var hash=location.hash;
		if(intake)
		{ // Intake allows us to override the current anchor with the #nav dropdowns
			hash = intake;
		}
		if (hash){
			//  Split to test *just* the part of the hash before the slash
			var subhash = hash.split('/');
			hash = subhash[0];
			if(jQuery.inArray(hash, resources_hashes) >= 0 || jQuery.inArray(hash, contact_hashes) >= 0)
			{
				// This hash is one of our tabs; show it.
				$('.tabbed_nav .current').removeClass('current');
				$(hash+'_link').addClass('current');
				$('.resources_content').hide();
				$('.contact_content').hide();
				$(hash+'_box').fadeIn('fast');
			} else if(jQuery.inArray(hash, doctortest_hashes) >= 0) {
				// This hash is one of our doctors; select them.
				
				hash = hash.substr(1);
				
				// Unhide anything that was hidden from the full list
				$('.hidefromfull').removeClass('hidefromfull');
				
				$('#doctor_selector .pictures .current').removeClass('current');
				$('#img_'+hash).addClass('current');
				
				$('.doctor').hide();
				$("#full_"+hash).fadeIn('fast'); 
				
				// Change header (just for doctors page)
				$("#head_slider").attr('src', 'images/header_eyedoctors_'+hash+'.jpg');
				
				// Change the dropdown to show this one
				$('#doctor_selector .text select').attr('value', hash);
				
			} else {
				// It's not a valid hash, so proceed as normal.	
			}
		}
	}



function showRecaptcha(element, submitButton, recaptchaButton, themeName) {
	Recaptcha.destroy();
	Recaptcha.create("6LdftcMSAAAAACvqmXs1K8np4Bwiy9xscAXda3bP", element, {
		theme: themeName,
		tabindex: 0,
		callback: Recaptcha.focus_response_field
	});
	$(".multiplesubmits").hide();
	$("#"+submitButton).show();
	$(".recaptcha_required").show();
	$("#"+recaptchaButton).hide();
}


/* Begin POP-UP SIZES AND OPTIONS CODE
function popcontact(URL) {
	var popup_width = 450
	var popup_height = 450
	day = new Date();
	id = day.getTime();
	popup_URL = 'popups/'+URL;
	eval("page" + id + " = window.open(popup_URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+popup_width+',height='+popup_height+'');");
}


*/


