﻿var itemCounter = 0;
var itemBool = 0;

$(function() {
	if($('#TestimonialsContainer .Testimonial').length != 0) {
		$('#TestimonialsContainer .Testimonial:first').addClass('active');
	}
	
	//    Add a span around the text inside of each anchor in the navigation to allow for sliding door technique on tabs
	$('.MainNavigation li a').each(function () {
		var itemText = $(this).html();
		$(this).html('<span>' + itemText + '</span>');
	});

	$("#Staff li").each(function() {
		if (itemCounter == 4) { $(this).css('margin-right','0px'); }
		
		itemCounter++;
	});

	$("#Staff li").hover(function() {
		$(this).css({'z-index' : '10'});
		$(this).find(".BWPhoto").css('z-index','0');
		$(this).find(".ColorPhoto").css('z-index','1');
		$(this).find(".Description").css('display','block');
		$(this).find(".ColorPhoto").addClass("hover").stop()
			.animate({
				height: '198px',
				marginTop: '-10px',
				marginLeft: '-10px'
			}, 200);
		$(this).find(".BWPhoto").addClass("hover").stop()
			.animate({
				height: '198px',
				marginTop: '-10px',
				marginLeft: '-10px'
			}, 200);
		} , function() {
		$(this).find(".ColorPhoto").removeClass("hover").stop()
			.animate({
				height: '178px',
				marginTop: '0px',
				marginLeft: '0px'
		}, 400);
		$(this).find(".BWPhoto").removeClass("hover").stop()
			.animate({
				height: '178px',
				marginTop: '0px',
				marginLeft: '0px'
		}, 400);
		$(this).css({'z-index' : '0'});
		$(this).find(".ColorPhoto").css('z-index','0');
		$(this).find(".BWPhoto").css('z-index','1');
		$(this).find(".Description").css('display','none');
	});

	$(".Drawer").hide();

	if ($.browser.msie && $.browser.version <= 8) {
		$(".Accordian .Item").each(function () {
			itemCounter++;
			var itemPos = $(this).position();
			$(this).after('<div class="IEShadow IEShadow' + itemCounter + '"></div>');
			$(".IEShadow" + itemCounter).height($(this).height()).css('left', (itemPos.left - 10) + 'px').css('top', (itemPos.top - 10) + 'px');
		});
	};

	$(".Accordian .Item").click(function () {
		var bioLiNode = $(this);
		$(this).find(".Drawer").slideToggle(400, function () {
			bioLiNode.find("em").toggleClass('Open');
			$(this).parent(".Item").toggleClass('Open');
			if ($.browser.msie && $.browser.version <= 8) {
				$(".Accordian .Item").each(function () {
					itemCounter++;
					var itemPos = $(this).position();
					$(this).next(".IEShadow").height($(this).height()).css('left', (itemPos.left - 10) + 'px').css('top', (itemPos.top - 10) + 'px');
				});
			};
		});
	});

	if (!$.browser.msie) {
		$(".MainNavigation li a").hover(function() {
			$(this).animate({ backgroundColor: "#BE3940" }, 500);
		},function() {
			$(this).animate({ backgroundColor: "#E23940" }, 300);
		});
	} else {
		if($.browser.version > 8) {
			$(".MainNavigation li a").hover(function() {
				$(this).animate({ backgroundColor: "#BE3940" }, 500);
			},function() {
				$(this).animate({ backgroundColor: "#E23940" }, 300);
			});		
		}
	}

	var fieldSearchBox=$("#Q");
	var fieldSearchBoxDefault='Search';
	fieldSearchBox.val(fieldSearchBoxDefault);fieldSearchBox.focus(function(){
		if(fieldSearchBox.attr('value')==fieldSearchBoxDefault)fieldSearchBox.attr('value','');
	});
	fieldSearchBox.blur(function(){
		if(fieldSearchBox.attr('value')=='')fieldSearchBox.attr('value',fieldSearchBoxDefault);
	});
		
	if($("#PostTest").length > 0) {
		$('#PostTest').submit(function() {
			var CanARNPerformMSE = checkQuiz('CanARNPerformMSE','c');
			var MSESameAsTriage = checkQuiz('MSESameAsTriage','b');
			var ForWhichDoesEMTALANotApply = checkQuiz('ForWhichDoesEMTALANotApply','b');
			var WhoIsObligatedToReport = checkQuiz('WhoIsObligatedToReport','b');
			var AHospitalWithSpecializedCapabilitiesIsRequiredToAccept = checkQuiz('AHospitalWithSpecializedCapabilitiesIsRequiredToAccept','b');
			var DefinitionOfADedicatedED = checkQuiz('DefinitionOfADedicatedED','d');
			var InsuranceAuthorization = checkQuiz('InsuranceAuthorization','a');
			var PsychPatientStableForTransfer = checkQuiz('PsychPatientStableForTransfer','c');
			var AppropriateTransfer = checkQuiz('AppropriateTransfer','b');
			var PhysicianFailsToRespond = checkQuiz('PhysicianFailsToRespond','a');
			var UnacceptableReasonForFailingToRespond = checkQuiz('UnacceptableReasonForFailingToRespond','d');
			var AcceptableReasonToRefuseTransfer = checkQuiz('AcceptableReasonToRefuseTransfer','b');
			var EMTALAViolationReportingTime = checkQuiz('EMTALAViolationReportingTime','a');
			var WhichAgencyIsReponsible = checkQuiz('WhichAgencyIsReponsible','d');
			var FinesLeviedAgainstPhysicians = checkQuiz('FinesLeviedAgainstPhysicians','e');
			
			var totalerrors = CanARNPerformMSE + MSESameAsTriage + ForWhichDoesEMTALANotApply + WhoIsObligatedToReport + AHospitalWithSpecializedCapabilitiesIsRequiredToAccept + DefinitionOfADedicatedED + InsuranceAuthorization + PsychPatientStableForTransfer + AppropriateTransfer + PhysicianFailsToRespond + UnacceptableReasonForFailingToRespond + AcceptableReasonToRefuseTransfer + EMTALAViolationReportingTime + WhichAgencyIsReponsible + FinesLeviedAgainstPhysicians;
			if(totalerrors > 0) {
				return false;
			}		
		});
	};

	if($("#HIPAAPostTest").length > 0) {
		$('#HIPAAPostTest').submit(function() {
			var WhatDoesHIPAAStandFor = checkQuiz('WhatDoesHIPAAStandFor','a');
			var WhatIsPHI = checkQuiz('WhatIsPHI','d');
			var WhatDoesHIPAADo = checkQuiz('WhatDoesHIPAADo','a');
			var HealthcareEmployeesRight = checkQuiz('HealthcareEmployeesRight','b');
			var WhenCanYouUsePHI = checkQuiz('WhenCanYouUsePHI','d');
			var WhoAtEPAHasToFollowHIPAA = checkQuiz('WhoAtEPAHasToFollowHIPAA','d');
			var MayYouFaxPHI = checkQuiz('MayYouFaxPHI','a');
			var CoWorkerWalksAwayLoggedIn = checkQuiz('CoWorkerWalksAwayLoggedIn','e');
			var WorkstationSecuritySafeguards = checkQuiz('WorkstationSecuritySafeguards','e');
			var HITECH = checkQuiz('HITECH','a');
			var UnsecureProtectedInformationCanInclude = checkQuiz('UnsecureProtectedInformationCanInclude','a');
			var WhoShouldABreachBeReportedTo = checkQuiz('WhoShouldABreachBeReportedTo','e');
			var ExceptionToABreach = checkQuiz('ExceptionToABreach','d');
			var PermissibleToTakeCharts = checkQuiz('PermissibleToTakeCharts','d');
			var PHIReleaseToWorkersComp = checkQuiz('PHIReleaseToWorkersComp','a');
			
			var totalerrorsHIPAA = WhatDoesHIPAAStandFor + WhatIsPHI + WhatDoesHIPAADo + HealthcareEmployeesRight + WhenCanYouUsePHI + WhoAtEPAHasToFollowHIPAA + MayYouFaxPHI + CoWorkerWalksAwayLoggedIn + WorkstationSecuritySafeguards + HITECH + UnsecureProtectedInformationCanInclude + WhoShouldABreachBeReportedTo + ExceptionToABreach + PermissibleToTakeCharts + PHIReleaseToWorkersComp;
			if(totalerrorsHIPAA > 0) {
				return false;
			}		
		});
	};

});

function checkQuiz(field,answer){
	var button = "input[name="+field+"]:radio";
	var label = "#"+field;
	var badanswers = 0;

	if($(button).is(":checked")) {
		if($(button+":checked").val() != answer) badanswers++;
	} else {
			badanswers++;
	}

	if(badanswers > 0) {
		if ($("#Warning_"+field).length == 0) $(label).append('<p class="Warning" id="Warning_'+field+'">Answer is incorrect.</p>');
	} else {
		if ($("#Warning_"+field).length > 0) $("p#Warning_"+field).remove();
	}

	return badanswers;
}

function swapImages(){
	var $active = $('#MessageImage .active');
	var $next = ($('#MessageImage .active').next('img').length > 0) ? $('#MessageImage .active').next('img') : $('#MessageImage img:first');
//	$active.toggle(function() {
		$active.removeClass('active');
		$next.addClass('active');
//	});
}

function swapTestimonials(){
	var $activeTestimonial = $('#TestimonialsContainer .active');
	var $nextTestimonial = ($('#TestimonialsContainer .active').next('div').length > 0) ? $('#TestimonialsContainer .active').next('div') : $('#TestimonialsContainer div:first');
	$activeTestimonial.fadeOut('slow').css('display','none').removeClass('active');
	$nextTestimonial.fadeIn('slow').addClass('active');
}
