	var thickboxCaller = "", timeoutHandle;

	$(document).ready(function () {
		setupNav();

		updateLinks();
		addMouseOver();
		toggler();
		
		athenaCarousel();
		mentorDelay(0);

		// profit calc nav widget
		if ($.cookie('calcTab')) {
			// if the cookie is set for already having seen the calc tab, then don't animate in
			$('#revCalcParent').css({top: 0});

			$('#revCalcClose').click(function(event) {
				closeCalcTab();
				event.preventDefault();
		 	});
		}
		/*
		else {
			// animate the tab in
			$('#revCalcClose').toggle(function() {
				animateCalcTabIn();
			}, function() {
				closeCalcTab();
			}).trigger("click");
		}
		*/

		if ($('#revCalcParent').length) {
			$('#revCalcParent').hover(
				function() {
					$('#revCalcParent').addClass('hover');
				},
				function() {
					$('#revCalcParent').removeClass('hover');
				}
			);
		}

		$("input[type='text']").setupFormField();
		$("textarea").setupFormField();
		$('form.validate').setupValidation();

		$('#accordion').setupAccordion();
		$('#accordion2').setupAccordion();

		setupEqualHeights();

		if ($('.canUnlock').length && $.cookie('revisit')) {
			unlockContent();
		}

		checkForLayers();

		if ($('#pageNav').length > 0) {
			$.address.init(function(event) {
				return;
			}).change(function(event) {
				// console.log("change: "+$.address.value());
				handleURLChange($.address.value())
			});
		}

	});

	function athenaCarousel(){
		$('.carouselNav a').not($(".carouselNav a").eq(0)).addClass("linkUp");
		$(".carouselNav a").eq(0).addClass("linkDown");
		$('.carouselNav a').click(function() {
			//changes slides
			//var carousalSlideNum = $(this).index();
			var position = $(this).index() * -226;
			$('.carouselContainer').animate({ "left": position }, 1000);
			// changes dots 
			$('.carouselNav a').not($(this)).removeClass("linkDown").addClass("linkUp");
			$(this).removeClass("linkUp").addClass("linkDown");
			// Stop Delay
			clearTimeout(timeoutHandle);
		});
	}
	
	function mentorDelay(num){
		timeoutHandle = window.setTimeout(function() {
			currentSlide = num;
			if (currentSlide <= 1){
				currentSlide = currentSlide+1;
			} else {
				currentSlide = 0;
			}
			$(".carouselNav a").eq(currentSlide).trigger('click');
		mentorDelay(currentSlide); }, 8000);
	}

	setupNav = function() {
		$("#mainNav > li").hover(
			function () {
				$(this).find('ul').stop(true, true).slideDown(200);
			}, function () {
				$(this).find('ul').stop(true, true).slideUp(0);
			}
		);
	}

	checkForLayers = function() {
		if (jQuery.url.param("open")) {
			var urlParam = jQuery.url.param("open");
			var mktoToken = jQuery.url.param("mkt_tok");

			if (urlParam.substring(0,5) == 'video') {
				tb_show(null,'/video-player.php?vid='+urlParam.substring(5)+'&height=1300&width=890&TB_iframe=true',false);
			}
			else if (urlParam.substring(0,3) == 'vid') {
				tb_show(null,'/video.php?vid='+urlParam.substring(3)+'&height=415&width=684&TB_iframe=true',false);
			}
			else if (urlParam.substring(0,4) == 'rVid') {
				tb_show(null,'/our-services/resource-library-video.php?vid='+urlParam.substring(4)+'&height=2000&width=764&TB_iframe=true',false);
			}
			else {
				switch(urlParam) {
					case "1": // contact us
						tb_show(null,'/forms/leadform.php?src=1&type=contact&height=700&width=946&TB_iframe=true',false);
						break;

					case "2": // subscribe
						tb_show(null,'/forms/leadform.php?src=4&type=newsletter&height=700&width=946&TB_iframe=true',false);
						break;

					case "3": // payerview methodology
						tb_show(null,'/our-services/payerview-methodology.php?height=2000&width=813&TB_iframe=true',false);
						break;

					case "4": // payerview disclaimer
						tb_show(null,'/our-services/payerview-disclaimer.php?height=700&width=813&TB_iframe=true',false);
						break;

					case "5": // tech requirements
						tb_show(null,'/our-services/technology-requirements.php?height=2000&width=813&TB_iframe=true',false);
						break;

					case "6": // FAQ - Implementation
						tb_show(null,'/our-services/faq-implementation.php?height=2000&width=813&TB_iframe=true',false);
						break;

					case "7": // FAQ - Utilization
						tb_show(null,'/our-services/faq-utilization.php?height=2000&width=813&TB_iframe=true',false);
						break;

					case "8": // FAQ - Security
						tb_show(null,'/our-services/faq-security.php?height=2000&width=813&TB_iframe=true',false);
						break;

					case "9": // Locations
						tb_show(null,'/our-company/locations.php?loc=watertown&height=2000&width=813&TB_iframe=true',false);
						break;

					case "10": // Awards
						tb_show(null,'/our-company/awards.php?height=1100&width=484&TB_iframe=true',false);
						break;

					case "11": // Partner Request Form
						tb_show(null,'/forms/partnerRequestForm.php?height=1200&width=484&TB_iframe=true',false);
						break;

					case "12": // Flywheel ReminderCall Offer
						tb_show(null,'/forms/leadform.php?src=55&height=800&width=946&TB_iframe=true',false);
						break;

					case "13": // 8 Tips EHR whitepaper
						tb_show(null,'/forms/leadform.php?src=44&type=gateway&height=700&width=946&TB_iframe=true',false);
						break;

					case "14": // Revenue erosion whitepaper
						tb_show(null,'/forms/leadform.php?src=34&type=gateway&height=700&width=946&TB_iframe=true',false);
						break;

					case "15": // Network effect whitepaper
						tb_show(null,'/forms/leadform.php?src=51&type=gateway&height=700&width=946&TB_iframe=true',false);
						break;

					case "16": // Payerview whitepaper
						tb_show(null,'/forms/leadform.php?src=53&type=gateway&height=700&width=946&TB_iframe=true',false);
						break;

					case "17": // VPG Form
						tb_show(null,'/forms/leadform.php?src=57&type=vpg&height=700&width=946&TB_iframe=true',false);
						break;

					case "18": // epocrates
						tb_show(null,'/forms/leadform.php?src=58&type=contact&height=700&width=946&TB_iframe=true',false);
						break;

					case "19": // hitech guarantee
						tb_show(null,'/our-company/hitech-guarantee.php?height=1400&width=724&TB_iframe=true',false);
						break;

					case "20": // clinicals demo
						loadDemoReg('48');
						break;

					case "21": // collector demo
						loadDemoReg('47');
						break;

					case "22": // sitemap
						tb_show(null,'/sitemap.php?height=650&width=484&TB_iframe=true',false);
						break;

					case "23": // schedule a meeting
						tb_show(null,'/crm/meeting_layer.php?mkt_tok='+mktoToken+'&height=650&width=484&TB_iframe=true',false);
						break;

					case "24": // share your specialty
						tb_show(null,'/crm/specialty_layer.php?mkt_tok='+mktoToken+'&height=650&width=484&TB_iframe=true',false);
						break;

					case "25": // Patient Workflow Whitepaper
						tb_show(null,'/forms/leadform.php?src=61&type=gateway&height=700&width=946&TB_iframe=true',false);
						break;

					case "26": // Sermo
						tb_show(null,'/sermo.php?height=1200&width=673&TB_iframe=true',false);
						break;

					case "27": // Revenue Calculator
						launchRevenueCalculator();
						break;

					case "28": // PSS
						tb_show(null,'/pss.php?height=1500&width=675&TB_iframe=true',false);
						break;

					case "29": // Humana Rewards Program
						tb_show(null,'/cmp/humana/rewards-program.php?height=1500&width=762&TB_iframe=true',false);
						break;

					case "30": // Communicator Demo
						loadDemoReg('56');
						break;

					case "31": // hitech guarantee with video autoplaying
						tb_show(null,'/our-company/hitech-guarantee.php?autoplay=1&height=1400&width=724&TB_iframe=true',false);
						break;

					case "32": // Humana Rewards Program - Video autoplaying
						tb_show(null,'/cmp/humana/rewards-program.php?autoplay=1&height=1500&width=762&TB_iframe=true',false);
						break;

					case "33": // Hospitals Landing Page
						tb_show(null,'/cmp/hospitals/index.php?height=1300&width=724&TB_iframe=true',false);
						break;

					case "34": // Octo Landing Page
						tb_show(null,'/cmp/octo/index.php?height=1300&width=724&TB_iframe=true',false);
						break;

					case "35": // More Money More Control
						tb_show(null,'/mmmc.php?height=1600&width=724&TB_iframe=true',false);
						break;

					case "36": // Hospitals Landing Page w/ Video Autoplaying
						tb_show(null,'/cmp/hospitals/index.php?autoplay=1&height=1300&width=724&TB_iframe=true',false);
						break;

					case "37": // 2011 User Conference
						tb_show(null,'/our-company/2011uc.php?height=1600&width=724&TB_iframe=true',false);
						break;

					case "38": // Quality Management Whitepaper
						tb_show(null,'/forms/leadform.php?src=122&type=gateway&height=700&width=946&TB_iframe=true',false);
						break;

					case "39": // 7 Tips Whitepaper
						tb_show(null,'/forms/leadform.php?src=134&type=gateway&height=700&width=946&TB_iframe=true',false);
						break;

					case "40": // Valley Med Video
						tb_show(null,'/our-services/resource-library-video.php?vid=21&height=2000&width=764&TB_iframe=true',false);
						break;

					case "41": // ACO Landing Page
						tb_show(null,'/cmp/ACO/index.php?height=1600&width=724&TB_iframe=true',false);
						break;
						
					case "42": // Cook Case Study
						tb_show(null,'/our-services/casestudies/cook-childrens.php?&amp;width=805&amp;height=1200&amp;TB_iframe=true',false);
						break;
					
					case "43": // PayerView 2011 Whitepaper
						tb_show(null,'/forms/leadform.php?src=146&type=gateway&height=700&width=946&TB_iframe=true',false);
						break;
					
					case "44": // ANSI 5010 WP
						tb_show(null,'/forms/leadform.php?src=132&type=gateway&height=700&width=946&TB_iframe=true',false);
						break;
					
					case "45": // Self-Pay WP
						tb_show(null,'/forms/leadform.php?src=135&type=gateway&height=700&width=946&TB_iframe=true',false);
						break;
					
					case "46": // Fax Compliance Form
						tb_show(null,'/our-company/fax.php?height=1100&width=484&TB_iframe=true', false);
						break;
					
					case "47": // Appalachian Case Study
						tb_show(null,'/our-services/casestudies/appalachian-orthopedic.php?&width=805&height=1200&TB_iframe=true',false);
						break;
					
					case "48": // Making the Switch Whitepaper
						tb_show(null,'/forms/leadform.php?src=133&type=gateway&height=700&width=946&TB_iframe=true',false);
						break;
					
					case "49": // Ferguson Case Study
						tb_show(null,'/our-services/casestudies/ferguson.php?&width=805&height=1200&TB_iframe=true',false);
						break;
					
					case "50": // athenaCoordinator Interstitial
						tb_show(null,'/our-services/athenaCoordinator-int.php?&width=805&height=1200&TB_iframe=true',false);
						break;

					case "51": // hitech software demo
						tb_show(null,'/our-company/hitech-guarantee_demo.php?height=1400&width=881&TB_iframe=true',false);
						break;
					
					case "52": // Eubanks Case Study
						tb_show(null,'/our-services/casestudies/eubanks.php?&width=805&height=1200&TB_iframe=true',false);
						break;
					
					case "53": // Coordinator Landing Page
						tb_show(null,'/cmp/freeimp/coordinator.php?height=1400&width=724&TB_iframe=true',false);
						break;
					
					case "54": // MU Free Imp Landing Page
						tb_show(null,'/cmp/freeimp/mupartner.php?height=1400&width=724&TB_iframe=true',false);
						break;
					
					case "55": // Provider Productivity WP
						tb_show(null,'/forms/leadform.php?src=147&type=gateway&height=700&width=946&TB_iframe=true',false);
						break;
					
					case "56": // Provider Productivity WP
						tb_show(null,'/cmp/freeimp/freeimp.php?height=1400&width=724&TB_iframe=true',false);
						break;
					
					case "57": // Pediatric Partners Case Study
						tb_show(null,'/our-services/casestudies/pediatric-partners.php?&width=805&height=1200&TB_iframe=true',false);
						break;
					
					case "58": // Masucci Case Study
						tb_show(null,'/our-services/casestudies/masucci.php?&width=805&height=1200&TB_iframe=true',false);
						break;
					
					case "59": // MacGregor Case Study
						tb_show(null,'/our-services/casestudies/macgregor.php?&width=805&height=1200&TB_iframe=true',false);
						break;
					
					case "60": // VaccineView Whitepaper
						tb_show(null,'/forms/leadform.php?src=165&type=gateway&height=700&width=946&TB_iframe=true',false);
						break;

					case "61": // Schedule a Meeting Contact Form
						tb_show(null,'/forms/leadform.php?src=166&type=meeting&height=700&width=946&TB_iframe=true',false);
						break;

					case "62": // What is the Cloud Layer
						tb_show(null,'/our-services/what-is-the-cloud.php?height=980&width=890&TB_iframe=true',false);
						break;

					case "63": // Patient Workflow Whitepaper
						tb_show(null,'/forms/leadform.php?src=75&type=gateway&height=700&width=946&TB_iframe=true',false);
						break;
					
					case "64": // Transworld Landing Page
						tb_show(null,'/cmp/transworld/index.php?height=1500&width=675&TB_iframe=true',false);
						break;
					
					case "65": // North Texas Case Study
						tb_show(null,'/our-services/casestudies/north-texas-heart-center.php?&width=805&height=1200&TB_iframe=true',false);
						break;

					case "66": // ICD-10 Whitepaper
						tb_show(null,'/forms/leadform.php?src=175&type=gateway&height=700&width=946&TB_iframe=true',false);
						break;

					case "67": // ACO Whitepaper
						tb_show(null,'/forms/leadform.php?src=136&type=gateway&height=700&width=946&TB_iframe=true',false);
						break;
					
					case "68": // Wright State Case Study
						tb_show(null,'/our-services/casestudies/wright-state.php?&width=805&height=1200&TB_iframe=true',false);
						break;
					
					case "69": // This is How - Care Coordination
						tb_show(null,'/cmp/this-is-how/care-coordination.php?&height=1300&width=724&TB_iframe=true',false);
						break;
					
					case "70": // This is How - Meaningful Use
						tb_show(null,'/cmp/this-is-how/meaningful-use.php?&height=1300&width=724&TB_iframe=true',false);
						break;						
					

					case "1000": // Marketo Test
						tb_show(null,'/forms/marketo-test.php?src=1&type=contact&height=700&width=484&TB_iframe=true',false);
						break;

					case "1001": // New Rev Calc Test
						window.thickboxCaller = "revCalc";
						tb_show(null,'/revenue-calculator/index.php?height=1000&width=715&TB_iframe=true',false);
						break;

				}
			}
		}

		// if the layer's been opened directly, then redirect to its default location
		if (typeof layerID != 'undefined') {
			if (layerID != 0 && !self.parent.tb_remove) {
				window.location.href = layerDefaultPage + '?open=' + layerID;
			}
		}
	}


	updateLinks = function() {
		// Format any external URLs to go through the exit interstitial
		$("a[rel='ext']").formatExternalURL();

		// Set the target of any links that should open in a new window
		$("a[rel='new']").attr('target','_blank');

		// Links in layers should open in the parent
		$("a[rel='top']").click(
			function() {
				self.parent.location = $(this).attr('href');
				self.parent.tb_remove();
			}
		);
		$("a[rel='layerNarrow']").click(
			function() {
				self.parent.sizeThickboxToContact();
				window.location.href = $(this).attr('href');
			}
		);
		$("a[rel='layerWide']").click(
			function() {
				self.parent.sizeThickboxToWide();
				window.location.href = $(this).attr('href');
			}
		);
		$("a[rel='layerDemo']").click(
			function() {
				if ($.cookie('revisit') || $.cookie('dfex')) {
					switch($(this).attr('name')) {
						case "47": // collector
							var vidID = "6";
							break;

						case "48": // clinicals
							var vidID = "2";
							break;

						case "56": // communicator
							var vidID = "9";
							break;
					}

					self.parent.sizeThickboxToVideoPlayer();
					window.location.href = '/video-player.php?vid='+vidID;
				}
				// if no, then show the form
				else {
					switch($(this).attr('name')) {
						case "47": // collector
							var srcID = "49";
							break;

						case "48": // clinicals
							var srcID = "50";
							break;

						case "56": // communicator
							var srcID = "74";
							break;

					}

					window.location.href = '/forms/leadform.php?src='+srcID+'&type=demo';
				}
			}
		);
		$("a[rel='scroll']").click(
			function() {
				console.log('scroll');
			}
	   );


		// Any element that has the class .clickable, watch for click and take user to first href's URL.
		$(".clickable").click(
			function () {
				$thisHref = $(this).find('a:first');

				// SS: handler for teaching thickbox to refrain from closing when needed
				window.thickboxCaller = ($thisHref.hasClass('revCalc')) ? 'revCalc' : '';

				if ($thisHref.attr('name')) {
					s=s_gi(s_account);
					s.tl($thisHref,'o', $thisHref.attr('name'));
				}

				if ($(this).attr('id') == 'softwareDemoCallout') {
					var srcID = $(this).find('a:first').attr('rel');
					loadDemoReg(srcID.toString());
				}
				else {
					if ($(this).find('a:first').hasClass('thickbox')) {
						tb_show(null,$thisHref.attr('href'),false);
						return false;
					}
					else {
						switch($thisHref.attr('rel')) {
							case "ext":
								tb_show(null,$thisHref.attr('href'),false);
								return false;
								break;

							case "new":
								window.open($thisHref.attr('href'));
								return false;
								break;

							case "playVideo":
								$thisHref.click();
								return false;
								break;

							default:
								document.location = $thisHref.attr('href');
								break;
						}
					}
				}
			}
		);

		$("#button_print").click(function() { window.print(); });
		$("#button_printAll").click(function() { window.print(); });
	}

	setupEqualHeights = function() {
		if ($('#servicesAthenaCollector').length == 0 && $('#servicesAthenaClinicals').length == 0 && $('#servicesAthenaCommunicator').length == 0) {
			if ($('#container > .colgroup > div').length && $('.pageContent_wider').length == 0) {
				itemstoresize = $('#container > .colgroup > div:not(.noresize)');
				if (itemstoresize.length == 3 || $('.twothirds').length) {
					$(itemstoresize).height("auto").css("overflow", "auto").equalHeights(0);
				} else {
					$(itemstoresize).height("auto").css("overflow", "auto").equalHeights(13);
				}
			}
			if ($('.col > .colgroup > div').length && $('.pageContent_wider').length == 0) {
				$('.col > .colgroup > div').height("auto").css("overflow", "auto").equalHeights(13);
			}
		}
	}

	addMouseOver = function() {
		// Format any external URLs to go through the exit interstitial
		$(".mouseout").hover(
			function () {
				$(this).removeClass('mouseout').addClass('mouseover');
			},
			function () {
				$(this).removeClass('mouseover').addClass('mouseout');
			}
		);

	}

	toggler = function() {
		// Format any external URLs to go through the exit interstitial
		$(".toggle_trigger").click(
			function() {
				//$.scrollTo($('#pageNavContainer'));

				$(".toggle_trigger").removeClass('active');
				$(this).addClass('active');
				clicked = $(".toggle_trigger").index(this);

				changeBodyContent(clicked, $(this).attr('id'));

				return false;
			}
		);
	}


	changeBodyContent = function(indexVal, sectionID) {
		// only scroll if the page nav container is off the screen
		if ($('#pageNavContainer').position().top < $(window).scrollTop()) {
			$.scrollTo($('#pageNavContainer').position().top - 50, 0);
		}

		$('.toggle_content').hide();
		$('.toggle_content:eq(' + indexVal + ')').show();
		setupEqualHeights();

		var bodyName = $('body').attr('id');
			bodyName = bodyName.replace('svcs','');
			bodyName = bodyName.replace('Athena','athena');

		var pageName = sectionID;
			pageName = pageName.replace('pageNav_', '');
			pageName = pageName.replace(/-/g, ' ');
			pageName = bodyName + ': ' + pageName;

		reTrack(pageName,'Our Services');
	}



	var title = document.title;

	handleURLChange = function(pathString) {

		var sectionID = pathString.replace('/','');

		if (sectionID.length == 0) {
			sectionID = 'Overview';
		}

		// clear all items
		$(".toggle_trigger").removeClass('active');

		// make correct item active
		$('#pageNav_'+sectionID).addClass('active');

		// show body content
		clicked = $(".toggle_trigger").index($('#pageNav_'+sectionID));

		changeBodyContent(clicked, 'pageNav_'+sectionID);

		$.address.title([title] + " :: " + sectionID.replace(/-/g, ' '));

	}

	formatTitle = function(titleAppend) {
		// get the current title
		var currentTitle = $('title').html();
		// append the section to the end
		return currentTitle + ' :: ' + titleAppend.replace('/','').replace(/-/g, ' ');
	}

/*
	toggle = function(selectedSection) {
		$.scrollTo($('#pageNavContainer'));

		$(".toggle_trigger").removeClass('active');
		clicked = $(".toggle_trigger").index($(selectedSection));

changeBodyContent(clicked, selectedSection);

		$('.toggle_trigger:eq(' + clicked + ')').addClass('active');
		$('.toggle_content').hide();
		$('.toggle_content:eq(' + clicked + ')').show();
		setupEqualHeights();

		var bodyName = $('body').attr('id');
			bodyName = bodyName.replace('svcs','');
			bodyName = bodyName.replace('Athena','athena');

		var pageName = $('.toggle_trigger:eq(' + clicked + ')').attr('id');
			pageName = pageName.replace('pageNav_', '');
			pageName = pageName.replace(/-/g, ' ');
			pageName = bodyName + ': ' + pageName;

		reTrack(pageName,'Our Services');

	}
*/
	reTrack = function(trackPageName, trackChannel) {
		s.pageName = trackPageName;
		s.channel = trackChannel;
		s.t();
	}


	unlockContent = function() {
		$('.canUnlock a').each(function(i) {
			if ($(this).attr('rel')) {
				var newHref = '/_doc/' + $(this).attr('rel');
				$(this).removeClass('thickbox').attr('href',newHref);
	
				$(this).unbind("click");
				$(this).click(function() {
					window.open($(this).attr('href'));
					return false;
				});
				
				if ($(this).parent().prev().hasClass('wp')) {
					$(this).parent().prev().addClass('unlocked');
				}
			}
		});

		$('.canUnlock li.lock').removeClass('lock').addClass('pdf');

		// call Flash to unlock content
		if ($('#athenaVideoPlayer').length > 0) {
			document.getElementById('athenaVideoPlayer').handleSuccessfulReistration();
		}
	}



	jQuery.fn.setupFormField = function(theField) {
		return this.each(function() {

			// Save original value
			// $(this).attr('originalValue',$(this).val());

			// Add focus action (selecting field)
			$(this).focus(function() {
				if ($(this).val() == $(this).attr('title')) {
					$(this).val('');
				}
				else {
					$(this).select();
				}
			});

			// Add blur action (moving off of field)
			$(this).blur(function() {
				if ($(this).val() == '') {
					$(this).val($(this).attr('title'));
				}
			});

		});
	};

	jQuery.fn.setupPasswordField = function(theField) {
		return this.each(function() {

			// Add focus action (selecting field)
			$(this).focus(function() {
				$(this).addClass('hidepasswordlabel');
			});

			// Add blur action (moving off of field)
			$(this).blur(function() {
				if ($(this).val().length == 0) {
					$(this).removeClass('hidepasswordlabel');
				}
			});

		});
	};

	jQuery.fn.formatExternalURL = function() {
		return this.each(function() {

			// rewrite URL to go through the exit page
			var currentHref = $(this).attr('href');
			$(this).attr('href', '/exit.php?u=' + encodeURI(currentHref) + '&TB_iframe=true&height=360&width=484');

		});
	};

	jQuery.fn.setupAccordion = function(el) {
		if(typeof document.body.style.maxHeight === "undefined") { // if IE6
			$(el).find('li h3 a').click(function() {
				if (!$(this).parent().parent().hasClass('expanded')) {
					$(this).parent().parent().siblings().removeClass('expanded');
					$(this).parent().parent().addClass('expanded');
				} else {
					$(this).parent().parent().removeClass('expanded');
				};

				// if this is a page, not a layer, then run equalheights
				if ($('.layer').length == 0) {
					setupEqualHeights();
				}

				return false;
			});

		} else { // if NOT IE6
			if($(el).find('li h3 a').length) {
				$(el).find('li h3 a').unbind('click').click(function() {
					if (!$(this).parent().parent().hasClass('expanded')) {
						$(this).parent().parent().siblings().removeClass('expanded').find('.panel_body').hide(); // mcs
						$(this).parent().parent().addClass('expanded').find('.panel_body').hide().fadeIn(400).slideDown(400); // mcs
					} else {
						$(this).parent().parent().removeClass('expanded').find('.panel_body').hide(); // mcs
					};

					// if this is a page, not a layer, then run equalheights
					if ($('.layer').length == 0) {
						setupEqualHeights();
					}

					return false;
				});
			} else {
				$('#accordion li h3 a').unbind('click').click(function() {
					if (!$(this).parent().parent().hasClass('expanded')) {
						$(this).parent().parent().siblings().removeClass('expanded').find('.panel_body').hide(); // mcs
						$(this).parent().parent().addClass('expanded').find('.panel_body').hide().fadeIn(400).slideDown(400); // mcs
					} else {
						$(this).parent().parent().removeClass('expanded').find('.panel_body').hide(); // mcs
					};

					// if this is a page, not a layer, then run equalheights
					if ($('.layer').length == 0) {
						setupEqualHeights();
					}

					return false;
				});
			}
		}
	};
	/*
	jQuery.fn.setupAccordion = function(el) {
		$(el).find('li h3 a').click(function() {
			if (!$(this).parent().parent().hasClass('expanded')) {
				$(this).parent().parent().siblings().removeClass('expanded');
				$(this).parent().parent().addClass('expanded');
			} else {
				$(this).parent().parent().removeClass('expanded');
			};

			// if this is a page, not a layer, then run equalheights
			if ($('.layer').length == 0) {
				setupEqualHeights();
			}

			return false;
		});
	};
	*/

	accordionExpandAll = function() {
		if(typeof document.body.style.maxHeight === "undefined") { // if IE6
			$('#accordion li h3 a').each(function() {
				$(this).parent().parent().addClass('expanded');
			});
		}
		else { // if NOT IE6
			$('#accordion li h3 a').each(function() {
				$(this).parent().parent().addClass('expanded').find('.panel_body').hide().fadeIn(400).slideDown(400); // mcs
			});
		}

		// if this is a page, not a layer, then run equalheights
		if ($('.layer').length == 0) {
			setupEqualHeights();
		}

		return false;
	}

	launchPayerViewDisclaimer = function() {
		tb_show(null,'/our-services/payerview-disclaimer.php?loc=entities&height=700&width=813&TB_iframe=true',false);
	}
	launchPayerViewMajorDisclaimer = function() {
		tb_show(null,'/our-services/payerview-disclaimer.php?loc=majorpayers&height=700&width=813&TB_iframe=true',false);
	}


	jQuery.fn.setupValidation = function() {
		return false;

		// only clear validation notices if there's no server error
		if (!($('.validation_notice').hasClass('server_notice'))) {
			$(".validation_notice").hide();
			$(".validation_notice li").hide();
		}

		this.submit(function() {

			var errors = new Array();



			$("input, select, textarea").removeClass("invalid");

			/*
			// passwords
			// check to see if pass1 and pass2 are long enough, then make sure they match
			if (($("#password1").length > 0) && ($("#password2").length > 0)) {
				if ( ($("#password1").val().length < 4) || ($("#password2").val().length < 4) || ($("#password1").val() != $("#password2").val()) ) {

				errors.push("password");
				$("#password1").addClass("invalid");
				$("#password2").addClass("invalid");

				}
			}
			*/

			// all other required form elements
			$(".required").each(function() {
				// detect if it's been modified
				if ( $(this).attr("title") == $(this).val() || $(this).val() == "") {
					// alert(this.id);
					// it hasn't, so show it's related LI
					errors.push(this.id);
					$(this).addClass("invalid");
				}
			});

			// does it have one @
			if ($(".email").length) {
				if ($(".email").val().split("@").length == 2 ) {

					// does it have at least one dot in the 2nd half
					if ($(".email").val().split("@")[1].split(".").length > 1 ) {

						//we're ok folks!

					} else {
						// alert("no dot");
						errors.push("email");
						$(".email").addClass("invalid");
					}
				} else {
					// alert("not the right number of @'s in the address");
					errors.push("email");
					$(".email").addClass("invalid");
				}
			}


			if ( errors.length > 0 ) {
				drawErrors(errors);
				return false;
			} else {
				// disable button
				if ($('button#submit').length > 0) {
					$('button#submit').attr('disabled','disabled');
					$('button#submit span').html('Please wait');
				}
				// exit
				return true;
			}
		});
	};


	stopVideo = function() {
		if ($('#athenaVideoPlayer').length > 0) {
			try {
				getFlashMovie("athenaVideoPlayer").stopVideo();
			} catch (err) {

			}
		}
	}

	function getFlashMovie(movieName) {
		if (navigator.appName.indexOf("Microsoft") != -1) {
			return window[movieName];
		}
		else {
			return document[movieName];
		}
	}


	drawErrors = function(errors) {

		if($("#formBlock").closest("body").length > 0) {
			validateFix(); // fix for athenaClinicals upsell page
		}

		var notice = "";
		notice += "	<div class=\"validation_inside\">";
		notice += "		<h3>Please correct the following errors:</h3>";
		// notice += "<p>" + errors + "</p>";
		notice += "		<ul class=\"traditional\">";

		// lead form
		( jQuery.inArray("first_name", errors) >= 0 ) ?
			notice += "<li><strong>First Name</strong> is a required field.</li>" : null ;
		( jQuery.inArray("last_name", errors) >= 0 ) ?
			notice += "<li><strong>Last Name</strong> is a required field.</li>" : null ;
		( jQuery.inArray("title", errors) >= 0 ) ?
			notice += "<li><strong>Title</strong> is a required field.</li>" : null ;
		( jQuery.inArray("company_name", errors) >= 0 ) ?
			notice += "<li><strong>Practice Name</strong> is a required field.</li>" : null ;
		( jQuery.inArray("specialty", errors) >= 0 ) ?
			notice += "<li><strong>Specialty</strong> is a required field.</li>" : null ;
		( jQuery.inArray("numberOfDocs", errors) >= 0 ) ?
			notice += "<li><strong>Number of physicians in your practice</strong> is a required field.</li>" : null ;
		( jQuery.inArray("phone", errors) >= 0 ) ?
			notice += "<li><strong>Phone</strong> is a required field.</li>" : null ;
		( jQuery.inArray("state", errors) >= 0 ) ?
			notice += "<li><strong>State</strong> is a required field.</li>" : null ;
		( jQuery.inArray("job_title", errors) >= 0 ) ?
			notice += "<li><strong>Job Title</strong> is a required field.</li>" : null ;
		( jQuery.inArray("email", errors) >= 0 ) ?
			notice += "<li><strong>Email</strong> is a required field.</li>" : null ;

		// partner request form fields
		( jQuery.inArray("org_name", errors) >= 0 ) ?
			notice += "<li><strong>Organization Name</strong> is a required field.</li>" : null ;
		( jQuery.inArray("website", errors) >= 0 ) ?
			notice += "<li><strong>Website URL</strong> is a required field.</li>" : null ;
		( jQuery.inArray("address", errors) >= 0 ) ?
			notice += "<li><strong>Address</strong> is a required field.</li>" : null ;
		( jQuery.inArray("street", errors) >= 0 ) ?
			notice += "<li><strong>Shipping Address</strong> is a required field.</li>" : null ;
		( jQuery.inArray("state_shipping", errors) >= 0 ) ?
			notice += "<li><strong>Shipping State</strong> is a required field.</li>" : null ;
		( jQuery.inArray("city", errors) >= 0 ) ?
			notice += "<li><strong>City</strong> is a required field.</li>" : null ;
		( jQuery.inArray("zip", errors) >= 0 ) ?
			notice += "<li><strong>ZIP</strong> is a required field.</li>" : null ;
		( jQuery.inArray("bizphone", errors) >= 0 ) ?
			notice += "<li><strong>Business Phone #</strong> is a required field.</li>" : null ;
		( jQuery.inArray("employees", errors) >= 0 ) ?
			notice += "<li><strong># of Employees</strong> is a required field.</li>" : null ;
		( jQuery.inArray("focus", errors) >= 0 ) ?
			notice += "<li><strong>Primary Business Focus</strong> is a required field.</li>" : null ;
		( jQuery.inArray("sales", errors) >= 0 ) ?
			notice += "<li><strong>Annual Sales</strong> is a required field.</li>" : null ;
		( jQuery.inArray("metro_coverage", errors) >= 0 ) ?
			notice += "<li><strong>Primary Territory/Metropolitan Area</strong> is a required field.</li>" : null ;
		( jQuery.inArray("interest", errors) >= 0 ) ?
			notice += "<li>Please explain your interest in partnering with athenahealth.</li>" : null ;
		( jQuery.inArray("unsubscribe", errors) >= 0 ) ?
			notice += "<li>Please select at least one type of email that you would like to receive.</li>" : null ;





		notice += "		</ul>";
		notice += "	</div>";

		if ($('.validation_notice').length) {
			$('.validation_notice').html(notice).show();
		}

	};

	/*
	homePromoCalloutLink1 = function() {
		s.tl(this,'o','Cook Childrens Video');
		tb_show(null,'/video.php?vid=14&height=415&width=684&TB_iframe=true',false);
	}
	*/
	homePromoCalloutLink2 = function() {
		s.tl(this,'o','Federal Stimulus Dollars Guaranteed - Learn More');
		// tb_show(null,'/our-company/hitech-guarantee.php?height=1300&width=724&TB_iframe=true',false);
		window.location.href = "/meaningful-use.php";
	}

	setCookie = function(cookievalue) {
		//NEED TO SET COOKIE... ALSO NEEDS TO KNOW IF IT'S ALREADY
		//SET SO AS NOT TO RESET IT ... 30 DAYS SINCE FIRST SET
		// $.cookie(cookievalue, 'true', { path: '/' });
		$.cookie(cookievalue, 'true', { expires: 30, path: '/' });
	}

	getCookie = function(cookievalue) {
		//NEED TO RETURN TRUE OR FALSE
		if($.cookie(cookievalue) == null) {
			return false;
		}
		else {
			return true;
		}
	}

	openSermo = function() {
		s.tl(this,'o','2010 Physician Sentiment Index - See the results');
		tb_show(null,'/sermo.php?height=1300&width=673&TB_iframe=true',false);
	}

	scrollToTop = function() {
		$.scrollTo({ top:0, left:0 });
	}

	sizeThickboxToDemo = function() {
		$.scrollTo({ top:0, left:0 });
		$('#TB_window').css({marginLeft: '-432px',width: '865px', marginTop: '0pt', position: 'absolute', top: '25px', display: 'block'});
		$('#TB_iframeContent').css({width: '864px', height: '552px'});
	}
	sizeThickboxToContact = function() { // 946 x 700
		$.scrollTo({ top:0, left:0 });
		$('#TB_window').css({marginLeft: '-488px',width: '976px', marginTop: '0px', position: 'absolute', top: '25px', display: 'block'});
		$('#TB_iframeContent').css({width: '975px', height: '712px'});
	}
	sizeThickboxToWide = function() {
		$.scrollTo({ top:0, left:0 });
		$('#TB_window').css({marginLeft: '-419px',width: '838px', marginTop: '0px', position: 'absolute', top: '25px', display: 'block'});
		$('#TB_iframeContent').css({width: '837px', height: '2007px'});
	}
	sizeThickboxToHitech = function() {
		$.scrollTo({ top:0, left:0 });
		$('#TB_window').css({marginLeft: '-377px',width: '754px', marginTop: '0px', position: 'absolute', top: '25px', display: 'block'});
		$('#TB_iframeContent').css({width: '753px', height: '1312px'});
	}
	resizeThickboxHeight = function(newHeight) {
		$.scrollTo({ top:0, left:0 });
		$('#TB_window').css({marginTop: '0px', position: 'absolute', top: '25px', display: 'block'});
		$('#TB_iframeContent').height(newHeight);
	}
	sizeThickboxToVideo = function() { // 684 x 415
		$.scrollTo({ top:0, left:0 });
		$('#TB_window').css({marginLeft: '-357px',width: '714px', marginTop: '0px', position: 'absolute', top: '25px', display: 'block'});
		$('#TB_iframeContent').css({width: '713px', height: '712px'});
	}
	sizeThickboxToVideoPlayer = function() { // 890 x 950
		$.scrollTo({ top:0, left:0 });
		$('#TB_window').css({marginLeft: '-460px',width: '920px', marginTop: '0px', position: 'absolute', top: '25px', display: 'block'});
		$('#TB_iframeContent').css({width: '919px', height: '962px'});
	}

	function validateFix() {
		$("#upsellFormContainer").css({ "background" : "url(/cmp/upsell/_img/upsell_form_bg-lg.gif) no-repeat scroll 15px 15px #42560B" }).find("#formBlock").css({ "height" : "370px" });
	}


	// ***********************************
	// REVENUE CALCULATOR
	// ***********************************
	launchRevenueCalculator = function() {
		window.thickboxCaller = "revCalc";
		tb_show(null,'/revenue-calculator/index.php?height=1000&width=715&TB_iframe=true',false);
	}
	closeRevenueCalc = function() {
		// call to flash to close the calculator
		document.getElementById('TB_iframeContent').contentWindow.closeCalculator();
	}
	animateCalcTabIn = function() {
		tb_remove();
		$('#revCalcParent').animate({"top": "0px"}, "slow");
		$.cookie('calcTab', '1', { expires: 3650, path: '/', domain: cookieDomain });
	}
	closeCalcTab = function() {
		if ($('#revCalcParent').length) {
			$('#revCalcParent').animate({"top": "-36px"}, "slow");
		}
		$.cookie('calc', null, { path: '/', domain: cookieDomain });
		$.cookie('calcTab', null, { path: '/', domain: cookieDomain });
		$.cookie('revCalcIn', null, { path: '/', domain: cookieDomain });
		return false;
	}


	// ***********************************
	// Home Page Panels
	// ***********************************

	/*
	panelHover = function(thisObj) {
		var panelID = '#' + $(thisObj).attr('id');
		var contentID = panelID.replace('_header','_content');

		// remove the hover
		$('.panel-header').unbind();

		// close the other panels
		$('.panel-header').not(panelID).removeClass('ui-state-active').addClass('ui-state-default');
		$('.panel-content').not(contentID).slideUp(300);

		// show the panel, hide the header
		$(panelID).addClass('ui-state-active').removeClass('ui-state-default');
		$(contentID).slideDown(300,setupPanelHovers);
	}
	*/
	panelHover = function(thisObj) {
		var panelSpeed = 175;
		var panelHovered = $('.panel-header').index(thisObj) + 1;

		// remove the hover
		$('h3.ui-state-default').unbind();

		switch (panelHovered) {
			case 1:
				$('#panel1_header').removeClass('ui-state-default').addClass('ui-state-active');
				$('#panel1').animate({top: '0px'},panelSpeed,"linear",function() { setupPanelHovers(1); });
				$('#panel2').animate({top: '270px'},panelSpeed);
				$('#panel3').animate({top: '330px'},panelSpeed);

				break;

			case 2:
				$('#panel2_header').removeClass('ui-state-default').addClass('ui-state-active');
				$('#panel1').animate({top: '0px'},panelSpeed);
				$('#panel2').animate({top: '55px'},panelSpeed,"linear",function() { setupPanelHovers(2); });
				$('#panel3').animate({top: '330px'},panelSpeed);
				break;

			case 3:
				$('#panel3_header').removeClass('ui-state-default').addClass('ui-state-active');
				$('#panel1').animate({top: '0px'},panelSpeed);
				$('#panel2').animate({top: '55px'},panelSpeed);
				$('#panel3').animate({top: '115px'},panelSpeed,"linear",function() { setupPanelHovers(3); });
				break;
		}
	}

	setupPanelHovers = function(selectedPanel) {
		if (selectedPanel) {
			switch (selectedPanel) {
				case 1:
					$('#panel2_header').removeClass('ui-state-active').addClass('ui-state-default');
					$('#panel3_header').removeClass('ui-state-active').addClass('ui-state-default');
					break;
				case 2:
					$('#panel1_header').removeClass('ui-state-active').addClass('ui-state-default');
					$('#panel3_header').removeClass('ui-state-active').addClass('ui-state-default');
					break;
				case 3:
					$('#panel1_header').removeClass('ui-state-active').addClass('ui-state-default');
					$('#panel2_header').removeClass('ui-state-active').addClass('ui-state-default');
					break;
			}
		}

		$('h3.ui-state-default').hover(
			function() {panelHover($(this))},
			function() { return; }
		);
	}


	startOcto = function() {
		$('#octopus').show();
	}
	removeOcto = function() {
		$('#octopus').hide().remove();
	}


	hideTBCloseButton = function() {
		$('#TB_closeWindowButton').css("display", "none");
	}
	
	whitepaperFormValidate = function() {
		
		if($('html').hasClass('ie6')) {
			$("#btn_viewWhitepaperIEs").hover(function() {
				$(this).addClass('hover');
			}, function() {
				$(this).removeClass('hover');
			});
		}
		
		$('#whitepaperFormNewstyle').find('input').bind('focus', function() {
			$(this).addClass('inputFocus');
		});

		$('#whitepaperFormNewstyle').find('input').bind('blur', function() {
			$(this).removeClass('inputFocus');
		});

		$('#whitepaperFormNewstyle').find('textarea').bind('focus', function() {
			$(this).addClass('inputFocus');
		});

		$('#whitepaperFormNewstyle').find('textarea').bind('blur', function() {
			$(this).removeClass('inputFocus');
		});

		$('#state').bind('change', function() {
			var value = $(this).val();
			if(value != "" && value != "null") { $("#state-label").each(function() { $(this).css('display', 'none'); $(this).remove(); }); }
		});

		jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
			phone_number = phone_number.replace(/\s+/g, ""); 
			return this.optional(element) || phone_number.length > 9 &&
				phone_number.match(/^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})$/);
		}, "Enter a valid phone number");

		jQuery.validator.addMethod("stateSelect", function(value, element, arg){
			if(value != "" && value != "null") { $("#state-label").each(function() { $(this).css('display', 'none'); $(this).remove(); }); }
			return value != "" && value != "null";
		}, "Please select a state.");

		// Default messages 		
		jQuery.validator.messages.required = "This field is required.";
		jQuery.validator.messages.email = "Enter a valid address.";

		function customEffect(){
		   $(this).effect("bounce", { direction:"right", distance: "6" }, 250);
		}

		$('input').bind('focusout', function(event) {
			$("#whitepaperFormNewstyle").validate().element( this );
		});

		$("#whitepaperFormNewstyle").validate({
			submitHandler: function(form) {
				$('#submit').attr('disabled','disabled').removeClass('btn_contact_us').removeClass('btn_viewDemo').removeClass('btn_viewWhitepaper').addClass('btn_please_wait');
			   	form.submit();
			},
			rules: {
				first_name: "required",
				last_name: "required",
				email: { 
					required: true, 
					email: true
				}, 
				company_name: "required",
				numberOfDocs: { 
					required: true, 
					number: true
				},
				phone: { 
					required: true, 
					phoneUS: true
				},
				state: {
					stateSelect: true
				},
				comments: {
					required: false, 
					maxlength: 500
				}
			},
			messages: {
				first_name: "This field is required.",
				last_name: "This field is required.",
				company_name: "This field is required.",
				email: "A valid address is required.", 
				numberOfDocs: { 
					number: "Enter the number of docs."
				},
				comments: {
					maxlength: "Max 500 characters."
				},
				phone: {
					phoneUS: "Enter your phone number."
				}
			}, 
			errorPlacement: function(error, placement) {
				var targetVal; var toolVal; var flipSides = false;
				targetVal = 'leftMiddle';
				toolVal = 'rightMiddle';

				$(placement).qtip({
					content: error.text(),
					show: { when: { event: 'none'}, ready: true, effect: customEffect },
					hide: { when: { event: 'keydown' } },
					position: {
						corner: {
							target: targetVal,
							tooltip: toolVal
						},
						adjust: { 	
							x: ($('html').hasClass("ie")) ? 15 : 0
						}
					},
					style: {
						border: { width: 0 },
						tip: false,
						background: "#ffe867", 
						color: "#923503", 
						padding: "0", 
//						padding: ($('html').hasClass("ie")) ? "0 1px" : "0 5px", 
						textAlign: "center"
					},
					api: {
						onRender: function() {
							$('.qtip').each(function() {
								if(!$(this).attr("id") || $(this).attr("id") == "") {
									if($("#" + $(placement).attr('id') + "-label").length > 0) {
										$(this).attr("id", $(placement).attr('id') + "-label");
										// $(placement).qtip("destroy");
										return false;
									} else {
										$(this).attr("id", $(placement).attr('id') + "-label");
									}
								}
							});
						}, beforeDestroy: function() {
							if($('html').hasClass("ie")) {
								$(placement).qtip("destroy");
							} else {
								$('input').each(function() {
									if( $(this).hasClass('valid') ) { $(this).closest('label').qtip("destroy"); }
								});
							}
						}
					}
				});

				var api = $(placement).qtip("api");
				api.elements.tooltip.css('width', parseInt(api.elements.tooltip.css('width')) + 1);

				api.elements.tooltip.css('left', parseInt(api.elements.tooltip.css('left')) - 2);
			}
		});
	}
	
	loadDemoReg = function( sourceID, videoID ) {
		// for safety, convert source ID to string so no switch statements below break
		sourceID = sourceID.toString();

		// check whether the users already registered
		// if yes, then show the demo
		if ($.cookie('revisit') || $.cookie('dfex')) {

			switch(sourceID) {
				case "47": // collector
					var vidID = "6";
					break;

				case "48": // clinicals
					var vidID = "2";
					break;
				
				case "56":
				case "74": // communicator
					var vidID = "9";
					break;
			}

			if ($('#lyr_video').length > 0) {
				window.location.href = '/video.php?vid='+vidID;
				self.parent.sizeThickboxToVideoPlayer();
			}
			else {
				// alert( 'loadContactUs( ' + sourceID + ' )' );
				tb_show(null,'/video-player.php?vid='+vidID+'&height=1300&width=890&TB_iframe=true',false);
			}
		}
		// if no, then show the form
		else {

			switch(sourceID) {
				case "47": // collector
					var srcID = "49";
					break;

				case "48": // clinicals
					var srcID = "50";
					break;
				
				case "56":
				case "74": // communicator
					var srcID = "74";
					break;
					
			}

			if ($('#lyr_video').length > 0) {
				window.location.href = '/forms/leadform.php?src='+srcID+'&type=demo&height=700&width=946&TB_iframe=true';
				self.parent.sizeThickboxToContact();
			}
			else {
				// alert( 'loadContactUs( ' + sourceID + ' )' );
				tb_show(null,'/forms/leadform.php?src='+srcID+'&type=demo&height=700&width=946&TB_iframe=true',false);
			}
		}
			
		/*
		// The videoID could be null if the call is form a postroll 'Watch Demo' 
		if( AthenaVideoPlayer.flashvarsObj.regStatus != 'true' )
		{
			alert( 'loadDemoReg( ' + sourceID + ', ' + videoID + ' )' );
			AthenaVideoPlayer.flashvarsObj.regStatus = 'true';
		}
		if( videoID != undefined && videoID != '' )
		{
			AthenaVideoPlayer.flashvarsObj.defaultVideoID = videoID;
		}
		else
		{
			AthenaVideoPlayer.flashvarsObj.defaultVideoID = '';
			AthenaVideoPlayer.flashvarsObj.playlistURL = 'lang/en/playlist_demo.xml';
		}
		AthenaVideoPlayer.flashvarsObj.defaultCornersRound = 'true';
		AthenaVideoPlayer.embedDemo();
		*/
	}	
