// MOBILE CHANGES
	$(document).ready(function() {
	
	$('body#Mobile .ERWTRow span a')
	   .each(function() { 
		  this.href = this.href.replace(/genesishealth.com/, document.domain);
		  this.href = this.href.replace(/www./, '');
		  this.href = this.href.replace(/services.urgent-care/, 'mobile/UrgentCare');
	   });
	
	});  //END DOC READY
	

function addTextSizer(){
	$('#PageToolsWrapper').append('<div id="TextSizer" class="ClearFix"><h2>Text Sizer</h2><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') };
}
function addPageTools(){
	var clientDomainName = 'genesishealth.com',
		clientSiteName = 'Genesis 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);
	var urlToUse = (('https:' == document.location.protocol) ? 'https://secure.addthis.com/js/250/addthis_widget.js?pub=genesishealth' : 'http://s7.addthis.com/js/250/addthis_widget.js?pub=genesishealth');
	$('#PageToolsWrapper #TextSizer').after('<div id="PageTools">' +
		'<ul>' +
			'<li class="Print"><a href="javascript:;" onclick="print();">Print</a></li>' +
			'<li class="Email"><a href="' + emailHref + '">Email</a></li>' +
			'<li class="AddThis">' +
				'<script type="text/javascript">var addthis_pub = "genesishealth";</script>' +
					'<a href="http://www.addthis.com/bookmark.php?v=250&pub=genesishealth" onclick="return addthis_open(this, \'\', \'[URL]\', \'[TITLE]\')" onmouseout="addthis_close()"onclick="return addthis_sendto()" onclick="pageTracker._trackEvent(\'AddThis\', \'Open\');"><img src="/imgs/icons/add-this.gif" width="16" height="16" alt="Bookmark and Share" style="border:0"/></a>' +
					'<script type="text/javascript" src="' + urlToUse + '"></script>' +
			'</li>' +
		'</ul>' +
	'</div>');
}


$(document).ready(function () {

    addTextSizer();
    text_size_checker();
    addPageTools();

    // A jumpmenu that will either 
    //     1: show a hidden div with the class of 'Hidden' plus a # (<div class="Hidden1">) 
    //     2: load the url listed in the option value in the current window.
    //     3: load the url listed in the option value in a NEW window.

    $('.JumpMenu')
		.attr('selectedIndex', 0)
		.change(function () {
		    var val = $(this).val();
		    if (val != '') {
		        if (val.indexOf('Hidden') >= 0) { // Option 1: Hide all divs with class*=Hidden and show the one selected
		            $('*[class*="Hidden"]').hide();
		            $('.' + val).fadeIn('slow');
		        }
		        else {
		            if ($(this).children('option:selected').attr('class').toLowerCase() == 'new') {
		                window.open(val);  // Option 3: if <option class="new"> then open url in a NEW window
		            }
		            else {
		                location.href = val; // Option 2: go to url 
		            } // end if: class=new
		        } // end if: Option 1
		    } // end if: val not empty
		});
    $('*[class*="Hidden"]').hide(); // HIDE ALL DIVS WITH THE CLASS NAME OF *Hidden*    


    // ----------- TEMPLATE EXTRAS ------------------//

    //Removes Footer Top and/or Banner if no cmspanel available
    $('#FooterTop:empty').remove();
    $('#Banner:empty').remove();

    //adds div within each cell of .Section table
    $('table.Sections td').wrapInner('<div class="SectionDec"></div>');

    //adds class of ClearFix to the SectionDec class for landing pages so image doesn't overflow area
    $('.SectionDec').addClass('ClearFix');

    // Ading class names to the tabnav links for styles
    $('#Home .Tabnav li:nth-child(1) a').addClass('First');
    $('#Home .Tabnav li:nth-child(2) a').addClass('Second');
    $('#Home .Tabnav li:nth-child(3) a').addClass('Third');
    $('#Home .Tabnav li:nth-child(4) a').addClass('Fourth');
    $('#Home .Tabnav li:nth-child(5) a').addClass('Fifth');
    $('#Home .Tabnav li:nth-child(6) a').addClass('Sixth');
    $('#Home .Tabnav li:nth-child(7) a').addClass('Seventh');
    $('#Home .Tabnav li:nth-child(8) a').addClass('Eigth');
    $('#Home .Tabnav li:nth-child(9) a').addClass('Ninth');
    $('#Home .Tabnav li:nth-child(10) a').addClass('Tenth');
    $('#Home .Tabnav li:last a').addClass('Last');

    // LOCATIONS: Moving Locations tabs within the locations module right below the search box
    $('div.LocationsTabs').insertAfter('#LocationsSearch .SearchBox');

    // PHYSICIANS: Moving Physicians tabs within the physicians module right below the search box
    $('div.LocationsTabs').insertAfter('#DrSearch .SearchBox');

    //Adding PanelWrappers around Bottom cmspanels - for right col template
    $('#LowerPanels .cmspanel').wrap('<div class="PanelWrapper"></div>');
    $('#LowerPanels .PanelWrapper').wrap('<div class="PanelWrapper2"></div>');

    //Adding class to first header in each cmspanel in col3 and bottom panels on Right Col Only template
    $('#Col3 .cmspanel :header:first-child').not('thead :header').addClass('PanelHeader');
    $('#Home #Col3 .cmspanel :header:first-child').removeClass('PanelHeader');
    $('#LowerPanels .cmspanel :header:first-child').not('thead :header').addClass('PanelHeader');

    // Mobile site - Reformat Locations  //
    // Loop through array //
    $('#Mobile .LocationsList > ul > li').each(function () {
        //Move phone number after location name
        $(this).find('.Headline').after($(this).find('.Phone'))
        //Move Minor Details after Major Details
        $(this).find('.MajorDetails').after($(this).find('.MinorDetails'))
    });

    $('#Mobile .Paging').each(function () {
        var BackNext = $(this).find('.BackNext');
        $(this).find('tr').after('<tr class="BackNextLink"><td class="BackNext">' + BackNext.html() + '</td></tr>');
        BackNext.remove();
    });

    // Mobile Find a doctor - move photo
    $('#Mobile .DrList > li').each(function () {
        var Picture = $(this).find('.Picture');
        $(this).find('dl').before('<div class="MovePicture">' + Picture.html() + '</div>');
        Picture.remove();
        $('.Locations .MovePicture').remove();
    });

    // Mobile Classes & Events Details Page //
    // --------------------------------------------- //
    // Move 'Registration Open' Text under event name
    $('#Mobile .CalendarDetailContent fieldset').insertBefore($('#Mobile .CalendarDetailContent .EventStatus'));
    
    


    // ----------- HACK LIST START ------------------//

    //Adding class to cmspanel containing portal login for styling
    $('#Col3 .Portal-Login').closest('.cmspanel').addClass('PortalPanel');

    //removing padding from empty table cells from calendar event detail header
    $('.CalendarEventDetailHeader td:empty').addClass('Empty');

    // Adding print link for Google API Maps within the Locations and Doctors Details
    $('.MapWrapper').after('<br /><img src="/imgs/icons/print_map.gif" class="printmap" alt="print" title="print" onclick="window.open(\'/print.html\')" />');
    $('#DrDetail .Locations').after('<br /><img src="/imgs/icons/print_map.gif" class="printmap" alt="print" title="print" onclick="window.open(\'/print.html\')" />');

    // Bug 28717 -- Find a Doctor -- Make the Address/Phone/Map tab the default tab
    // Display google map -- otherwise map only pulls in for the locations tab
    $('#DrDetail .Tabnav li:nth-child(2) a').trigger('click');
    // Remove class Tabactive from the first tab
    $('#DrDetail .Tabnav li:first-child').removeClass('Tabactive');
    // Add class Tabactive to 2nd tab                
    $('#DrDetail .Tabnav li:nth-child(2)').addClass('Tabactive');

    //Change order of tabs
    // Move office location li above profile li
    $('#DrDetail .Tabnav li:first-child').insertAfter('#DrDetail .Tabnav li:nth-child(2)');
    // Move office location div above profile div
    $('div #VsMasterPage_ctl00_MainContentPlaceHolder_MainContent_ProfileInfo_OfficeTab').insertBefore('div #VsMasterPage_ctl00_MainContentPlaceHolder_MainContent_ProfileInfo_ProfileTab');

    // ----------- HACK LIST END ------------------//


});    // END DOC READY
