// JavaScript Document
// Careers to Delete 9/22

function activeLearningCenter()
		{document.getElementById('map-img').src='/uploadedImages/Content/About_Cerner/Careers/career-worldhq-learning-center.jpg';}
		
function activeSolutionPlace()
		{document.getElementById('map-img').src='/uploadedImages/Content/About_Cerner/Careers/career-worldhq-solution-place.jpg';}

function activeServiceCenter()
		{document.getElementById('map-img').src='/uploadedImages/Content/About_Cerner/Careers/career-worldhq-service-center.jpg';}

function activeTransformationPlace()
		{document.getElementById('map-img').src='/uploadedImages/Content/About_Cerner/Careers/career-worldhq-transformation-place.jpg';}

function activeAssociateCenter()
		{document.getElementById('map-img').src='/uploadedImages/Content/About_Cerner/Careers/career-worldhq-associate-center.jpg';}

function activeInnovationPlace()
		{document.getElementById('map-img').src='/uploadedImages/Content/About_Cerner/Careers/career-worldhq-innovation-place.jpg';}

function activeDeliveryCenter()
		{document.getElementById('map-img').src='/uploadedImages/Content/About_Cerner/Careers/career-worldhq-delivery-center.jpg';}
		
function activeInnovationCampus()
		{document.getElementById('map-img').src='/uploadedImages/Content/About_Cerner/Careers/career-worldhq-innovation-campus.jpg';}

function inactiveMap()
		{document.getElementById('map-img').src='/uploadedImages/Content/About_Cerner/Careers/career-worldhq-map.jpg';}
		
		// End Careers to Delete 9/22

(function($) {
	var CERNER = {
		Config : {
			sHTMLtag : "can-has-js"
			,sIEHoverSel : "li.util-nav-global, li.sort-selection"
			,sIEHoverClass : "ie-hover"
			,sPathImg : "/static/cerner/assets/img/"
			,sPathSwf : "/static/cerner/assets/swf/"
			,sSelPNG : "img, .calendar, .calendar div"
		}

		/*
			STOP EDITING HERE
		*/
		,init : function() {
			var c = CERNER;
			var p = c.Project;

			$(document).ready(function() {
				p.checks();
				p.dateRange();
				p.tabs();
				p.tagIt();
			});

			if (typeof DD_belatedPNG != "undefined") {
				p.ieHover(c.Config.sIEHoverSel, c.Config.sIEHoverClass)
				DD_belatedPNG.fix(c.Config.sSelPNG);
			}

			p.loadSIFR();
		}
		/*
			SITE-SPECIFIC FUNCTIONS
		*/
		,Project : {
			checks : function() {
				var oGroups = $("fieldset.group"),
					iMax = oGroups.length;
				for (var i = 0; i < iMax; i++) {
					var oThis = $(oGroups[i]),
						oList = $([
							'<ul class="act">'
							,'<li><a class="all" href="#">Select All</a></li>'
							,'<li class="last"><a class="clr" href="#">Clear</a></li>'
							,'</ul>'].join("\n"));
					oThis.prepend(oList);
					oList.find("a").click(function() {
						var oLink = $(this),
							aChecks = oLink.parents("fieldset").find("input[type='checkbox']"),
							iMax = aChecks.length;

						for (var i = 0; i < iMax; i++) {
							var oThis = $(aChecks[i]);
							if (this.className == "all") {
								oThis.attr("checked", true);
							} else if (this.className == "clr") {
								oThis.attr("checked", false);
							}
						}
						return false;
					});
				}
			}
			,dateRange : function() {
				var c = CERNER,
					$oForm = $("form.filter-date"),
					$oInput = $oForm.find("input"),
					$oAct = $('<p class="act"><a class="clr" href="#">Clear Range</a></p>'),
					calConfig = {
						sClass : 'calendar'
						,iOldestYear : 1900
						,sHTMLcalIcon : '<a class="show-cal" href="#"><img src="{imgPath}ico-cal.gif" alt="Calendar" /></a>'
						,sHTMLcaption : [
							'<caption>',
								'<a class="prev" title="{sPrevMonth} {sPrevYear}" href="#{iPrevMonth}-{iPrevYear}">&laquo;</a>',
								'{sMonth} {year}',
								'<a class="next" title="{sNextMonth} {sNextYear}" href="#{iNextMonth}-{iNextYear}">&raquo;</a>',
							'</caption>'
						].join('\n')
					},
					oDate = new Date(),
					sIcon = calConfig.sHTMLcalIcon.replace(/\{imgPath\}/g, c.Config.sPathImg);

				// Add in "clear range" control
				$oForm.prepend($oAct);
				$oAct.find("a.clr").click(function() {
					$oInput.attr("value", "");
					return false;
				});

				// Append icons
				$("fieldset.range").append(sIcon);

				// Handler to show the calendar
				$("a.show-cal").click(function() {
					// Hide any existing calendars
					hideIt();

					var $oLink = $(this),
						$oWrap = $oLink.parents("fieldset.range")

					// Build the calendar, using the text field data if available
					var $oFields = $oWrap.find("input[type=text]"),
						oTextM = $oFields.filter("[name$=month]").attr("value"),
						oTextY = $oFields.filter("[name$=year]").attr("value"),
						iM = (isNaN(oTextM) || oTextM < 1 || oTextM > 12) ? oDate.getMonth() : parseInt(oTextM),
						iY = (isNaN(oTextY) || oTextY < calConfig.iOldestYear || oTextY > oDate.getFullYear()) ? oDate.getFullYear() : parseInt(oTextY);

					$oWrap.append(build(iM - 1, iY, $oWrap)).addClass("active");
					behave($oWrap);

					return false;
				});

				// build(): returns HTML string
				// 	@param iM = 0-11 integer
				// 	@param iY = \d{4} integer
				var build = function(iM, iY, $oWrap) {
					var c = CERNER;
					var p = c.Project;

					// Workaround for mysterious string concat bug
					iM = parseInt(iM);
					iY = parseInt(iY);

					// Parameters
					var Params = {
						aMonths : ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
						,aDays : ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
						,aMonthLengths : [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
					}

					var oToday = false,
						$oFields = $oWrap.find("input[type=text]"),
						oTextM = $oFields.filter("[name$=month]"),
						oTextD = $oFields.filter("[name$=day]"),
						oTextY = $oFields.filter("[name$=year]");

					if (oTextY.attr("value") && oTextM.attr("value") && oTextD.attr("value")) {
						oToday = parseInt(oTextM.attr("value")) + '-' + parseInt(oTextD.attr("value")) + '-' + oTextY.attr("value");
					}

					// This month
					var sM = Params.aMonths[iM],
						iMonthLength = Params.aMonthLengths[iM];

					// Get information about starting points
					var firstDay = new Date(iY, iM, 1);
					var startDay = firstDay.getDay();

					// Is this a leap year? If so, and the month is February, 29-ify iMonthLength
					if (iM == 1) {
						if ((iY % 4 == 0 && iY % 100 != 0) || iY % 400 == 0) {
							iMonthLength = 29;
						}
					}

					// TOGGLE IT
					var iNextM = iM + 1;
					var iNextY = iY;
					var iPrevM = iM - 1;
					var iPrevY = iY;

					if (iM == 11) {
						var iNextM = 0;
						var iNextY = iY + 1;
					}

					if (iM == 0) {
						var iPrevM = 11;
						var iPrevY = iY - 1;
					}

					// Previous/next month/year strings
					var sPrevM = Params.aMonths[iPrevM],
						sNextM = Params.aMonths[iNextM];

					// Begin building the HTML string
					var sCaption = calConfig.sHTMLcaption;
					sCaption = sCaption.replace(/\{imgPath\}/gi, c.Config.sPathImg)
						.replace(/\{sMonth\}/g, sM)
						.replace(/\{year\}/g, iY)
						.replace(/\{iPrevMonth\}/g, iPrevM)
						.replace(/\{iPrevYear\}/g, iPrevY)
						.replace(/\{iNextMonth\}/g, iNextM)
						.replace(/\{iNextYear\}/g, iNextY)
						.replace(/\{sPrevMonth\}/g, sPrevM)
						.replace(/\{sPrevYear\}/g, iPrevY)
						.replace(/\{sNextMonth\}/g, sNextM)
						.replace(/\{sNextYear\}/g, iNextY);

					var sHTML = '<div class="' + calConfig.sClass + '">';
					sHTML += '<div><table>' + sCaption + '<thead><tr>';
					for (var i = 0; i < Params.aDays.length; i++) {
						sHTML += '<th scope="col"><abbr title="' + Params.aDays[i] + '">' + Params.aDays[i].charAt(0) + '</abbr></th>';
					}
					sHTML += '</tr></thead>';

					// LOOP LIKE YOU'VE NEVER LOOPED BEFORE
					var day = 1;

					// Outer loop: weeks
					for (var i = 0; i < 9; i++) {
						if (i == 0) {
							sHTML += '<tbody><tr>';
						}
						// Inner loop: days
						for (var j = 0; j <= 6; j++) {
							var sDate = (iM + 1) + '-' + day + '-' + iY;
							sHTML += '<td';
							if (oToday && oToday === sDate) {
								sHTML += ' class="today"'
							}
							sHTML += '>';
							if (day <= iMonthLength && (i > 0 || j >= startDay)) {
								sHTML += '<a href="#' + sDate + '">' + day + '</a>';
								day++;
							}
							sHTML += '</td>';
						}
						if (day > iMonthLength) {
							break;
						} else {
							sHTML += '</tr><tr>';
						}
					}
					sHTML += '</tr></tbody></table></div></div>';

					return sHTML;
				}

				// Attach event handlers
				var behave = function($oTarget) {
					var c = CERNER;
					var p = c.Project;
					var t = p.dateRange;

					var oFields = $oTarget.find("input[type=text]"),
						oTextM = oFields.filter("[name$=month]"),
						oTextD = oFields.filter("[name$=day]"),
						oTextY = oFields.filter("[name$=year]");

					$("caption a", $oTarget).click(function() {
						var sSlug = $(this).attr("href").split("#")[1],
							aSlug = sSlug.split("-"),
							iM = aSlug[0],
							iY = aSlug[1];

						$("div.calendar", $oTarget).replaceWith(build(iM, iY, $oTarget));
						behave($oTarget);

						return false;
					});
					$("tbody a", $oTarget).click(function() {
						var sSlug = $(this).attr("href").split("#")[1],
							aSlug = sSlug.split("-"),
							iM = parseInt(aSlug[0]),
							iD = parseInt(aSlug[1]),
							iY = parseInt(aSlug[2]);

						// Supporting the ISO-ish date format (i590)
						if (iD < 10) {
							iD = "0" + iD;
						}
						if (iM < 10) {
							iM = "0" + iM;
						}

						oTextM.attr("value", iM);
						oTextD.attr("value", iD);
						oTextY.attr("value", iY);

						$(this).parents("tbody").find("td").removeClass("today");
						$(this).parents("td").addClass("today");

						hideIt();

						return false;
					});
				}

				// Hide event handler
				var hideIt = function() {
					$("div.calendar").remove();
					$("fieldset.range").removeClass("active")
				}

				// Hide the container if anything else gets clicked on / gains focus
				$(document.body).click(function(event) {
					var $src = $(event.target);

					if (!$src.is("input, textarea")) {
						hideIt();
					}
				});
				$("input, textarea").focus(function(event) {
					hideIt();
				});
			}
			,loadSIFR : function() {
				var c = CERNER;

				/*
					Register the fonts
				*/
				/*var gothamBold = {
					src: c.Config.sPathSwf + 'gotham-bold.swf'
				}
				var gothamBook = {
					src: c.Config.sPathSwf + 'gotham-book.swf'
				}
				var gothamMed = {
					src: c.Config.sPathSwf + 'gotham-medium.swf'
				}
				var gothamLite = {
					src: c.Config.sPathSwf + 'gotham-light.swf'
				}*/

				/*
					Activate the fonts
				*/
				/*sIFR.activate(gothamBold, gothamBook, gothamMed, gothamLite);*/

				/*
					Hi, we're the replacements
				*/
				/*sIFR.replace(gothamLite, {
					selector: '#page-mast .title'
					,css: [
						'.sIFR-root { background-color: #FFFFFF; color: #ff6600; font-size: 44px; letter-spacing: 0; text-transform: normal; }'
					]
					,wmode: 'transparent'
				});
				sIFR.replace(gothamBold, {
					selector: '#secondary h2.title'
					,css: [
						'.sIFR-root { background-color: #ffffff; color: #19437E; font-size: 14px; letter-spacing: 1; text-transform: uppercase; }'
					]
					,wmode: 'opaque'
				});
				sIFR.replace(gothamBook, {
					selector: '.article-featured h1'
					,css: [
						'.sIFR-root { background-color: #ffffff; color: #3E434A; font-size: 24px; letter-spacing: 0; text-transform: normal; } a { color: #3E434A; text-decoration: none; } a:hover { color: #436D97; }'
					]
					,wmode: 'transparent'
				});
				sIFR.replace(gothamBook, {
					selector: '.article-body h1'
					,css: [
						'.sIFR-root { background-color: #ffffff; color: #3E434A; font-size: 24px; letter-spacing: 0; text-transform: normal; }'
					]
					,wmode: 'transparent'
				});
				sIFR.replace(gothamBook, {
					selector: '.article h2'
					,css: [
						'.sIFR-root { background-color: #ffffff; color: #19437E; font-size: 20px; letter-spacing: 0; text-transform: normal; } a { color: #3E434A; text-decoration: none; } a:hover { color: #436D97; }'
					]
					,wmode: 'transparent'
				});
				sIFR.replace(gothamMed, {
					selector: '.product-article p.intro'
					,css: [
						'.sIFR-root { background-color: #ffffff; color: #666666; font-size: 21px; letter-spacing: 0; text-transform: normal; leading: 7px; }'
					]
					,wmode: 'transparent'
				});
				sIFR.replace(gothamBook, {
					selector: '.promo-customer-story blockquote'
					,css: [
						'.sIFR-root { background-color: #ffffff; color: #666666; font-size: 16px; letter-spacing: 0; text-transform: normal; leading: 3px; }'
					]
					,wmode: 'transparent'
				});*/
			}
			,ieHover : function(sSel, sClass) {
				$(sSel).hover(function() {
					$(this).addClass(sClass);
				}, function() {
					$(this).removeClass(sClass);
				});
			}
			,tabs : function() {
				var c = CERNER;
				var p = c.Project;

				var sClassClosed = "closed",
					sClassSelected = "selected";

				// Insert junk markup to .util-bar
				var $oMenu = $(".util-bar"),
					sTabHTML = $oMenu.html(),
					sHTMLstart = '<div class="ub-i"><div class="ub-t"><div></div></div><div class="ub-inner">',
					sHTMLend = '</div><div class="ub-b"><div></div></div></div>';

				$oMenu.html(sHTMLstart + sTabHTML + sHTMLend);

				// IE6 html() hack
				if (typeof DD_belatedPNG != "undefined") {
					p.ieHover(c.Config.sIEHoverSel, c.Config.sIEHoverClass)
				}

				// Close the existing "tabs" (except the first one)
				var $oTabs = $(".specs .tab"),
					iMax = $oTabs.length;

				$oTabs.addClass(sClassClosed).first().removeClass(sClassClosed);

				var $oLinks = $(".util-bar a");
				$oLinks.first().parent().addClass(sClassSelected);
/**/
				/*SM010164 12/02/10 - changed for pagebuilder edit mode errors
                $(".util-bar a").click(function() {*/
				$oLinks.click(function() {
					$oLinks.parent().removeClass(sClassSelected);

					var $oThis = $(this),
						sSlug = "#" + $oThis.attr("href").split("#")[1];

					// Activate the tab link
					$oThis.parent().addClass(sClassSelected);

					// Hide all active tabs, but display the one that matches .attr("id") == sSlug
					$oTabs.not($oThis).addClass(sClassClosed);
					$(sSlug).removeClass(sClassClosed);

					return false;
				});
/**/
			}
			,tagIt : function() {
    			var c = CERNER;
				$("html").addClass(c.Config.sHTMLtag);
			}
		}
	};

	CERNER.init();
})(jQuery);


