// Mobile
$(document).ready(function() {
	
	// For Mobile Template: if any div.cmspage is empty, let's remove it -- avoids padding on empty pages.			
		$('#Mobile div').each(function(i, el) {
		// Remove white space
		var html = $(el).html().replace(/\s+/, '');
		// Check if element is :empty or length of html is zero
		if ($(el).is(':empty') || html.length == 0)
			$(el).remove();
		});
	
	$('body#Mobile .ERWTRow span a')
	   .each(function() { 
		  this.href = this.href.replace(/southernregional.org/, document.domain);
		  this.href = this.href.replace(/www./, '');
		  this.href = this.href.replace(/services.urgent-care/, 'mobile/UrgentCare');
	   });

 });  //END DOC READY


function addPageTools() {
    var urlToUse = (('https:' == document.location.protocol) ? 'https://secure.addthis.com/js/250/addthis_widget.js?pub=srhsatlanta' : 'http://s7.addthis.com/js/250/addthis_widget.js?pub=srhsatlanta');
	var clientDomainName = 'southernregional.org',
		clientSiteName = 'Southern Regional Health System',
		currentPageUrl = document.location,
		currentPageTitle = $.trim($('title').text()),
		emailSubject = clientDomainName + ': ' + currentPageTitle,
		emailHref = 'mailto:?subject=' + escape(emailSubject) + '&body=I thought you would be interested in a page on the ' + escape(clientSiteName) + ' Web site: ' + escape(currentPageTitle) + ' - ' + escape(currentPageUrl);
	$('#PageToolsWrapper').append('<div id="PageTools">' +
		'<ul>' +
			'<li class="Email"><a href="' + emailHref + '">Email</a></li>' +
			'<li class="Print"><a href="javascript:;" onclick="print();">Print</a></li>' +
			'<li class="AddThis">' +
					'<script type="text/javascript">var addthis_pub = "srhsatlanta";</script>' +
					'<a href="http://www.addthis.com/bookmark.php?v=250&pub=srhsatlanta" onmouseover="return addthis_open(this, \'\', \'[URL]\', \'[TITLE]\')" onmouseout="addthis_close();"onclick="return addthis_sendto();">Add This</a>' +
					'<script type="text/javascript" src="' + urlToUse + '"></script>' +
			'</li>' +
		'</ul>' +
	'</div>');
}
function addTextSizer() {
	$('#PageToolsWrapper #PageTools').before('<div id="TextSizer" class="ClearFix"><ul>' +
				'<li><a class="NormalFont" href="javascript:;" title="Small Font Size"></a></li>' +
				'<li><a class="LargeFont" href="javascript:;" title="Medium Font Size"></a></li>' +
				'<li><a class="X-LargeFont" href="javascript:;" title="Large Font Size"></a></li>' +
			'</ul></div>');	
	$('a.NormalFont').click(function() {$('#Content').removeClass('textLarge').removeClass('textXLarge');$.cookie('text_sizer', null, { path: '/' });});
	$('a.LargeFont').click(function() {$('#Content').addClass('textLarge').removeClass('textXLarge');$.cookie('text_sizer', 'large', { path: '/' });});
	$('a.X-LargeFont').click(function() {$('#Content').removeClass('textLarge').addClass('textXLarge');$.cookie('text_sizer', 'xlarge', { path: '/' });});
	$('#TextSizer a').click(function() {$('#TextSizer a').removeClass('active');$(this).addClass('active');});
}
function text_size_checker() {
	var text_sizer_cookie = $.cookie('text_sizer');
	if (text_sizer_cookie==null){$('a.NormalFont').addClass('active')};
	if (text_sizer_cookie=='large'){ $('#Content').addClass('textLarge');$('a.LargeFont').addClass('active') };
	if (text_sizer_cookie=='xlarge'){ $('#Content').addClass('textXLarge');$('a.X-LargeFont').addClass('active') };
}


$(document).ready(function () {
    addPageTools();
    addTextSizer();
    text_size_checker();

    // ----------- TEMPLATE EXTRAS ------------------//

    $('#QuickLinks div.cmspanel li:last').addClass('Last');

    //hiding empty abstract div
    $('.Abstract:empty').hide();

    //moving flyout panels to be within the MainNav
    $('#MainNav li:nth-child(2)').addClass('Second');
    $('#MainNav li:nth-child(3)').addClass('Third');
    $('#MainNav li:nth-child(4)').addClass('Fourth');
    $('#MainNav li:nth-child(5)').addClass('Fifth');
    $('#MainNav li:nth-child(6)').addClass('Sixth');

    $('#Flyout1').appendTo('#MainNav li.First');
    $('#Flyout2').appendTo('#MainNav li.Second');
    $('#Flyout3').appendTo('#MainNav li.Third');
    $('#Flyout4').appendTo('#MainNav li.Fourth');
    $('#Flyout5').appendTo('#MainNav li.Fifth');
    $('#Flyout6').appendTo('#MainNav li.Sixth');

    //Ask our experts - menu
    $('#Experts li:nth-child(1)').addClass('First');
    $('#Experts li:nth-child(2)').addClass('Second');
    $('#Experts li:nth-child(3)').addClass('Third');
    $('#Experts li:nth-child(4)').addClass('Fourth');
    $('#Experts li:nth-child(5)').addClass('Fifth');
    $('#Experts li:nth-child(6)').addClass('Sixth');


    //remove the main nav drop down if .cmspanel doesn't exist or is empty
    $('.Flyout .FlyoutInner:empty').parent().parent().parent().remove();
    $('.Flyout .FlyoutInner .cmspanel:empty').parent().parent().parent().parent().remove();
	
	//remove the RegDetails div on Calendar details if empty - to prevent box from showing (bug 28599)			
		$('.CalendarDetail .CalendarEventRegistration .RegDetails').each(function(i, reg) {
		// Remove white space
		var html = $(reg).html().replace(/\s+/, '');
		// Check if element is :empty or length of html is zero
		if ($(reg).is(':empty') || html.length == 0)
			$(reg).remove();
		});

    //adding Advertiser OpenX script to career and nursing sections
    var thisDir = $.url.attr('directory')
    if (thisDir.indexOf('careers') > 0) {  // if the word 'careers' exists in the url path anywhere, then do this
        $('#Footer').append('<script src="http://ad.yieldmanager.com/pixel?id=926101&t=1" type="text/javascript"></script>');
    }
    if (thisDir.indexOf('nursing-careers') > 0) {  // if the word 'nursing-careers' exists in the url path anywhere, then do this
        $('#Footer').append('<script src="http://ad.yieldmanager.com/pixel?id=926103&t=1" type="text/javascript"></script>');
    }

    // Home page shades
    $('#BottomPanels .cmspanel p').hide();

    $('#BottomPanels .cmspanel').hover(
        function () {
            $(this).find("p").slideToggle("fast");
        },
        function () {
            $(this).find("p").slideToggle("fast");
        }
    );

    // Find a Doctor -- Combine Profile and Office Information Tabs
        // Display google map -- otherwise map only pulls in for the locations tab
        // this needs to be in a ready function in order to display on pageload
        $(document).ready(function () {
            $('#DrDetail .Tabnav li:last a').trigger('click');
        });    
        // Add class Tabactive to the first tab
        $('#DrDetail .Tabnav li:first-child').addClass('Tabactive');
        // Hide office information tab                
        $('#DrDetail .Tabnav li:nth-child(2)').css("display","none");
        // Move office location div above profile div
        $('div #VsMasterPage_ctl00_MainContentPlaceHolder_MainContent_ProfileInfo_OfficeTab').insertAfter('ul.Tabnav');



    // ----------- HACK LIST START ------------------//

	//Making doctor's url open in a new window
	$('#DrDetail .Contacts a').attr("target","_blank");
	
	
	
	var cols = 3; //defines no of columns
	var container = $('#DrSearch .TabContainerlive dl');
	var items = container.find('dt');
	var itemsPerCol = Math.ceil(items.length / cols); //get Items per column

	var stack = []; //array to hold items
	for (var i = 0; i < itemsPerCol; i++) {
	for (var k = 0; k < cols; k++) {
	stack.push(items[i + (itemsPerCol * k)]); //push items into respective columns
	}
	}
	items.css({
	float:'left',
	width:'28%',
	margin:'0.5em 2% 0'
	});
	container.html(stack).append($('<br>').css({clear:'both'})); //paint the columns in sorted order
    //adds class to every dt in first column
	$("#DrSearch #BrowseTab dt:nth-child(3n+1)").addClass("ClearVis")

	// Adding auto-scroll to services links
	$("#BrowseTab .AlphabetLinks a").each(function () {
	    var _href = $(this).attr("href");
	    $(this).attr("href", _href + '#BrowseTab');
	});

    // ----------- HACK LIST END ------------------//

});  // End Document Ready

// New PhotoSlider to be removed after 5.2.9
addLoadEvent(initializePhotoSliders); function initializePhotoSliders() { var c = [], f = []; $(".PhotoSliderVS").each(function (n) { var o = $(this); o.wrapInner('<div class="Border ClearFix"><div class="Overflow"></div></div>').find(".Border").append('<div class="Buttons ClearFix"></div>').find(".Overflow").children("ul").addClass("Container").children("li").addClass("Slide").eq(0).addClass("Active"); o.find("li.Slide:first").addClass("First"); o.find("li.Slide:last").addClass("Last"); if (o.attr("class").match(/^.*SlideW(\d+).*/) !== null) { var m = o.attr("class").match(/^.*SlideW(\d+).*/)[1]; o.find("li.Slide").width(parseInt(m)) } if (!o.hasClass("HideCaptions")) { o.find(".Buttons").before('<p class="PhotoCaption"></p>') } if (!o.hasClass("HideArrows")) { o.find(".Buttons").append('<a class="Prev" href="javascript:;"></a><a class="Next" href="javascript:;"></a>') } if (o.hasClass("ShowNav") || o.hasClass("Vertical")) { var v = o.find("li.Slide").size(), h = '<div class="SlideNav ClearFix"><ul>', y = 1; for (y = 1; y <= v; y++) { h += '<li><a href="javascript:;"><span>' + y + "</span></a></li>" } h += "</ul></div>"; o.find(".Buttons").append(h); o.find(".SlideNav li:first").addClass("First"); o.find(".SlideNav li:last").addClass("Last") } else { if (!o.hasClass("HideNumbers")) { o.find(".Buttons").append('<em class="Count"><span></span>&nbsp;of&nbsp;<span></span></em>') } } if (o.hasClass("HideNumbers") && o.hasClass("HideCaptions")) { o.find(".Buttons").prepend("<em>&nbsp;</em>") } if (o.hasClass("Vertical")) { o.find(".Border").addClass("Vertical") } var k = 0, l = 0, q = 0, z = parseInt(o.find(".Border").css("borderBottomWidth")) * 2, w = parseInt(o.css("padding-left")), u = parseInt(o.css("padding-right")); o.find(".Slide").each(function () { if ($(this).outerWidth(true) > l) { l = $(this).outerWidth(true) } }); var j = o.attr("class").match(/^.*Width(\d+).*/), r; if (j !== null || o.hasClass("FullWidth")) { if (o.hasClass("FullWidth")) { o.hide(); r = o.parent().width() - w - u; o.show() } else { r = parseInt(j[1]) } o.width(r).addClass("manualWidth"); o.find(".Overflow").width(r - z); var x = o.width() - o.css("padding-left").replace("px", "") - o.css("padding-right").replace("px", ""); o.find(".Slide").width(x).addClass("SlideContent") } else { if (o.attr("class").match(/^.*Show(\d+).*/) !== null) { o.addClass("manualWidth").addClass("MultiSlide"); var p = o.attr("class").match(/^.*Show(\d+).*/)[1], m = o.find("li.Slide.Active").outerWidth(), t = o.find("li.Slide").size() - p; o.width(p * m + z); o.find(".Overflow").width(p * m); o.find("li.Slide").eq(t).addClass("LastSlideToShow") } else { o.width(l + z) } } o.find("li.Slide").each(function () { k += $(this).outerWidth(true) }); o.find(".Container").width(k + 100); if (o.attr("class").match(/^.*AutoSlide.*/) !== null) { o.addClass("Continuous"); var s = 4000; if (o.attr("class").match(/^.*AutoSlide(\d+).*/)) { s = o.attr("class").match(/^.*AutoSlide(\d+).*/)[1]; f[e(o)] = s } c[e(o)] = setInterval(function () { d(e(o)) }, s) } d(e(this), 0, true) }); $('.PhotoSliderVS[class*="AutoSlide"]').hover(function () { var h = e($(this)); $(this).addClass("Paused"); clearInterval(c[h]) }, function () { var h = e($(this)); $(this).removeClass("Paused"); c[h] = setInterval(function () { d(h) }, f[h]) }); $(".PhotoSliderVS .Buttons .Prev:not(.Inactive)").live("click", function (h) { var i = $(this).closest(".PhotoSliderVS"); if (i.hasClass("Continuous") && i.hasClass("MultiSlide") && i.find("li.Slide.Active").hasClass("First")) { prevSlide = i.find("li.Slide").index(i.find("li.Slide.LastSlideToShow")) } else { if (i.hasClass("Continuous") && i.find("li.Slide.Active").hasClass("First")) { prevSlide = i.find("li.Slide").size() - 1 } else { prevSlide = a(this) - 1 } } d(e(this), prevSlide) }); $(".PhotoSliderVS .Buttons .Next:not(.Inactive)").live("click", function (h) { var i = $(this).closest(".PhotoSliderVS"); if (i.hasClass("Continuous") && i.hasClass("MultiSlide") && i.find("li.Slide.Active").hasClass("LastSlideToShow")) { nextSlide = 0 } else { if (i.hasClass("Continuous") && i.find("li.Slide.Active").hasClass("Last")) { nextSlide = 0 } else { nextSlide = a(this) + 1 } } d(e(this), nextSlide) }); $(".PhotoSliderVS .Buttons .SlideNav li").live("click", function () { var h = $(this).parent("ul").find("li").index($(this)); d(e(this), h) }); $(".PhotoSliderVS .Buttons .SlideNav ul.ImageThumbs li").hover(function () { $(this).not(".Active").animate({ opacity: 1 }, 200) }, function () { $(this).not(".Active").animate({ opacity: 0.4 }, 200) }).live("click", function () { $(this).css({ opacity: 1 }) }); function b(i) { var h = i.width() + parseInt(i.css("padding-left")) + parseInt(i.css("padding-right")) + parseInt(i.css("margin-right")) + parseInt(i.css("margin-left")) + parseInt(i.css("borderRightWidth")) + parseInt(i.css("borderLeftWidth")); return h } function g(j) { var i = j.height() + parseInt(j.css("padding-top")) + parseInt(j.css("padding-bottom")) + parseInt(j.css("margin-top")) + parseInt(j.css("margin-bottom")) + parseInt(j.css("borderTopWidth")) + parseInt(j.css("borderBottomWidth")); return i } function e(i) { var j = $(i).closest(".PhotoSliderVS"), h = $(".PhotoSliderVS").index(j); return h } function a(i) { var j = $(i).closest(".PhotoSliderVS"), h = j.find("li.Slide").index(j.find("li.Slide.Active")); return h } function d(h, j, i) { $(".PhotoSliderVS").eq(h).each(function () { var Q = $(this), N = Q.find(".Overflow"), H = Q.find(".Container"), G = Q.find("li.Slide").size(), U = "slide"; if (j == null) { j = a(this) + 1; if (Q.find("li.Slide.Active").hasClass("Last")) { j = 0 } } Q.find("li.Slide.Active").removeClass("Active"); Q.find("li.Slide").eq(j).addClass("Active"); Q.find(".Buttons .Count span:first").html(a(Q) + 1); Q.find(".Buttons .Count span:last").html(G); caption = Q.find("li.Slide.Active .Caption").html(); if (caption == null) { caption = Q.find("li.Slide.Active img").attr("alt") } Q.find(".PhotoCaption").html(caption); if (!Q.hasClass("Continuous")) { if (a(Q) == "0") { Q.find(".Buttons .Prev").addClass("Inactive") } else { Q.find(".Buttons .Prev").removeClass("Inactive") } if (a(Q) + 1 == G || Q.find("li.Slide.Active").hasClass("LastSlideToShow")) { Q.find(".Buttons .Next").addClass("Inactive") } else { Q.find(".Buttons .Next").removeClass("Inactive") } } Q.find(".SlideNav li.Active").removeClass("Active"); Q.find(".SlideNav li").eq(a(Q)).addClass("Active"); if (Q.hasClass("FadeMe")) { U = "fade"; Q.find("li.Slide").css("position", "absolute"); Q.find("li.Slide").eq(a(Q)).addClass("Active").stop().css({ opacity: "0", "z-index": "92" }); if (i == true) { Q.find("li.Slide").eq(a(Q)).css({ opacity: "1" }, function () { Q.find("li.Slide").not(".Active").css({ "z-index": "90" }); Q.find("li.Slide.Active").css("z-index", "91") }) } else { Q.find("li.Slide").eq(a(Q)).animate({ opacity: 1 }, function () { Q.find("li.Slide").not(".Active").css({ "z-index": "90" }); Q.find("li.Slide.Active").css("z-index", "91") }) } } var K = Q.find("li.Slide.Active").outerWidth(), V = Q.find("li.Slide.Active").outerHeight(), X = 0, E = 0; Q.find("li.Slide").each(function () { if (E < $(this).outerHeight()) { E = $(this).outerHeight() } }); if (!Q.hasClass("manualWidth")) { if (i == true) { N.width(K).height(E) } else { N.animate({ width: K }) } } if (Q.hasClass("ShowNav") || Q.hasClass("Vertical")) { var I, r, z = false, m = 0, s = 0, D = 0, W = 0, P = 0, y = 0, p = "", l = 0.1, S = Q.find(".SlideNav"), C = 0, L = 0, v = 0, M = Q.find(".Buttons .Prev").outerHeight(), o = Q.find(".Buttons .Next").outerHeight(), F = Q.find(".Buttons .Prev").outerWidth(), Y = Q.find(".Buttons .Next").outerWidth(), R, k; if (M > 0 && o > 0 && F > 0 && Y > 0) { if (M > o) { k = M } else { k = o } if (F > Y) { R = F } else { R = Y } } else { M = 0; F = 0; o = 0; Y = 0 } if (Q.hasClass("Vertical")) { z = true; I = Q.find(".Buttons").parent().height() - parseInt(Q.find(".Buttons").css("padding-top")) - parseInt(Q.find(".Buttons").css("padding-bottom")); r = I - (M + o); Q.find(".Buttons").height(I) } else { r = Q.find(".Buttons").width() - parseInt(Q.find(".Buttons").css("padding-left")) - parseInt(Q.find(".Buttons").css("padding-right")) - (F + Y) } if (Q.attr("class").match(/^.*ImageThumbs.*/) !== null) { Q.find(".SlideNav ul").addClass("ImageThumbs"); if (Q.attr("class").match(/^.*ImageThumbs(\d+).*/)) { l = Q.attr("class").match(/^.*ImageThumbs(\d+).*/)[1] * 0.01 } S.find("li").each(function (n) { p = Q.find("li img").eq(n); $(this).html('<img src="' + p.attr("src") + '" width="' + p.width() * l + '" height="' + p.height() * l + '"/>').not(".Active").css("opacity", "0.4") }) } S.find("li").each(function () { if (z) { y = g($(this)); $(this).height($(this).height()) } else { y = b($(this)) } D += y; if (y > W) { W = y } if ($(this).outerWidth(true) > C) { C = $(this).outerWidth(true); L = C } if (R > C) { C = R } }); P = (parseInt(r / W)); var O = 0; if ($.browser.msie && $.browser.version.substr(0, 1) < 7) { O = parseInt(S.find("li").css("margin-right")) } if (r < D) { if (!(P % 2)) { P = P - 1 } var T = S.find("li.Active"), x = S.find("li").index(T), A = 0, t = (P * 0.5) - 0.5, B = x - t, u = B + P, q = 0; if (B < 0) { B = 0; u = B + P } if (u > G) { u = G; B = u - P } S.find("li.ShowNav").removeClass("ShowNav"); S.find("li").slice(B, u).addClass("ShowNav"); var J = S.find("li").index(S.find(".ShowNav:first")); if (z) { S.find("li").slice(0, J).each(function () { A += g($(this)) }); S.find("li.ShowNav").each(function () { m += g($(this)) }); S.find("ul").height(D + O).stop().animate({ top: -A }) } else { S.find("li").slice(0, J).each(function () { A += b($(this)) }); S.find("li.ShowNav").each(function () { m += b($(this)) }); S.find("ul").width(D + O).stop().animate({ left: -A }) } } else { if (z) { S.find("ul").height(D + O) } else { S.find("ul").width(D + O) } m = D + O } if (z) { S.height(m).css("top", ((r - m) * 0.5) + Q.find(".Buttons .Prev").outerHeight()); if (i) { S.find("li").width(L - parseInt(S.find("li").css("padding-right")) - parseInt(S.find("li").css("padding-left")) - parseInt(S.find("li").css("borderRightWidth")) - parseInt(S.find("li").css("borderLeftWidth"))); I = +C + parseInt(Q.find(".Buttons").css("padding-left")) + parseInt(Q.find(".Buttons").css("padding-right")); Q.width($(this).width() + I); Q.find(".Buttons").width(C); if (Q.hasClass("NavRight")) { Q.find(".Overflow,.PhotoCaption").css("margin-right", I); Q.find(".Border").addClass("NavRight"); Q.find(".Buttons").css("margin-left", Q.find(".Overflow").width()) } else { Q.find(".Overflow,.PhotoCaption").css("margin-left", I) } if (R > L) { v = parseInt((C - L) * 0.5); S.css("margin-left", v + "px").css("margin-right", v + "px") } else { v = parseInt((C - R) * 0.5); S.siblings(".Prev,.Next").css("margin-left", v + "px").css("margin-right", v + "px") } } } else { S.width(m) } } Q.find("li.Slide:lt(" + a(Q) + ")").each(function () { X += $(this).outerWidth(true) }); if (U == "slide") { H.stop().animate({ left: -X }) } }) } };

// Home auto rotating tabs
    // Auto Rotating Tabs
    (function ($) {
        $.fn.equalHeights = function () {
            tallest = 0;
            this.each(function () {
                if ($(this).height() > tallest) {
                    tallest = $(this).height();
                }
            });
            return this.each(function () {
                $(this).height(tallest);
            });
        }
    })(jQuery);

    var rotateSpeed = 8000; // Milliseconds to wait until switching tabs.
    var currentTab = 0; // Set to a different number to start on a different tab.
    var numTabs; // These two variables are set on document ready.
    var autoRotate;

    function openTab(clickedTab) {
        var thisTab = $('#Home2011 .TabContainer .Tabnav a').index(clickedTab);
        $('#Home2011 .TabContainer .Tabnav li a').removeClass('active');
        $('#Home2011 .TabContainer .Tabnav li a:eq(' + thisTab + ')').addClass('active');
        $('#Home2011 .TabContainer .Tab').hide();
        $('#Home2011 .TabContainer .Tab:eq(' + thisTab + ')').show();
        currentTab = thisTab;
    }

    function rotateTabs() {
        var nextTab = (currentTab == (numTabs - 1)) ? 0 : currentTab + 1;
        openTab($('#Home2011 .TabContainer .Tabnav li a:eq(' + nextTab + ')'));
    }

    $(document).ready(function () {
        $('#Home2011 .Tab').equalHeights();
        numTabs = $('#Home2011 .TabContainer .Tabnav li a').length;
        $('#Home2011 .TabContainer .Tabnav li a').click(function () {
            openTab($(this)); return false;
        });
        $('#Home2011 .TabContainer').mouseover(function () { clearInterval(autoRotate) })
        .mouseout(function () { autoRotate = setInterval('rotateTabs()', rotateSpeed) });
        $('#Home2011 .TabContainer .Tabnav li a:eq(' + currentTab + ')').click()
        $('#Home2011 .TabContainer').mouseout();

        // Home alert popup
        $('#Home2011 #PopupAlert .cmspanel').append('<div class="CloseBtn">' +
        '<img src="/imgs/icons/delete.gif" title="Close" alt="Close" />' +
        '</div>');
        $('#Home2011 #PopupAlert .cmspanel .CloseBtn').click(function () { $('#Home2011 #PopupAlert').addClass('Hide') });

        $('.srhs2011 #Footer li:empty').remove();


    });  // End Document Ready
