// 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();
    });

});  //END DOC READY

function addTextSizer() {
	$('#VisitorType').after('<div id="TextSizer" class="ClearFix"><ul>' +
				'<li>Text Size&nbsp;</li>' +
				'<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 () {
    addTextSizer();
    text_size_checker();

    // ----------- TEMPLATE EXTRAS ------------------//

    $('.ServicesAlpha ul li:even').addClass('Odd');
    $('.ServicesAlpha ul li:odd').addClass('Even');

    // ----------- HACK LIST START ------------------//

    // LOCATIONS: SAVE KEYWORD IN QUERYSTRING
    $('.LocationsTabs li.Tabactive a').click(function () { return false; }); // ignore the current tab

    var theKeyword = $.url.param('keyword'); // get the keyword from the querystring
    var theKeyword2 = $.url.param('keyword2'); // get the keyword2 from the querystring (exists if Next/Previous button was clicked)
    var theSort = $.url.param('sort'); // get the sort parameter from the querystring
    if (theSort == '' || theSort == null) { theSort = '13' } // set sort to 13 if it's not there
    var thePage = $.url.param('page'); // get the sort parameter from the querystring

    // if keyword exists then append all fake tab links with keyword and sort from querystring
    if (theKeyword != '' && theKeyword != null) {
        $('.LocationsSearchTextBox').val(theKeyword);
        $('.LocationsTabs li,').not('.Tabactive').each(function () { var thisHref = $(this).children('a').attr('href'); $(this).children('a').attr('href', thisHref + '&keyword=' + theKeyword + '&sort=' + theSort); });
        // also, add the keyword variable to the location detail links
        $('.LocationsList li a.Picture, .LocationsList li a.Name').each(function () { var thisHref = $(this).attr('href'); $(this).attr('href', thisHref + '&keyword2=' + theKeyword); });
        // also, add the keyword2 variable to the querystring on the Next/Previous links
        $('.Paging .BackNext a').each(function () { var thisHref = $(this).attr('href'); $(this).attr('href', thisHref + '&keyword2=' + theKeyword); });
    }
    else {
        // if keyword doesnt exist but keyword2 does, then append all fake tab links with keyword and sort from querystring
        if (theKeyword2 != '' && theKeyword2 != null) {
            $('.LocationsSearchTextBox').val(theKeyword2);
            $('.LocationsTabs li').not('.Tabactive').each(function () { var thisHref = $(this).children('a').attr('href'); $(this).children('a').attr('href', thisHref + '&keyword=' + theKeyword2 + '&sort=' + theSort); });
            // also, add the keyword variable to the location detail links
            $('.LocationsList li a.Picture, .LocationsList li a.Name').each(function () { var thisHref = $(this).attr('href'); $(this).attr('href', thisHref + '&keyword2=' + theKeyword2); });
            // also, add the keyword2 variable to the querystring on the Next/Previous links
            $('.Paging .BackNext a').each(function () { var thisHref = $(this).attr('href'); $(this).attr('href', thisHref + '&keyword2=' + theKeyword2); });
            // also, add the keyword2 variable to the querystring on the return to search results links on the detail page
            $('#LocationsDetail p.ReturnToResults a').each(function () { var thisHref = $(this).attr('href'); $(this).attr('href', thisHref + '?keyword2=' + theKeyword2); });
        }
    }

    // LOCATIONS: Moving Locations tabs within the locations module right below the search box
    $('div.LocationsTabs').insertAfter('#LocationsSearch .SearchBox');


    // ----------- HACK LIST END ------------------//


    //Multimedia Module
    //Video Player
    $('.MultimediaGallery a[href^="http://prohealthcare.cachefly.net/Video-Files/Video-Launch-Files/"]')
		.each(function () {
		    this.href = this.href.replace(/^http:\/\/prohealthcare\.cachefly\.net\/Video-Files\/Video-Launch-Files\//,
			"javascript:createPlayer(\"http://prohealthcare.cachefly.net/Video-Files/Video-Launch-Files/");
		});

    $('.MultimediaGallery a[href$=".flv"]')
		.each(function () {
		    this.href = this.href.replace(/\.flv/,
			'.flv", "", false, true)');
		});

    // Adding audio player to AudioPlayer link.
    $('a.AudioPlayer').each(function () {

        var divID = $(this).attr('title');
        $(this).wrap('<div class="AudioPlayer" id="' + divID + '"></div>');

        var so = new SWFObject('http://prohealthcare.cachefly.net/mp3_player/mp3player.swf', 'swf', '275', '24', '7');
        so.addParam('wmode', 'transparent');
        so.addParam('FlashVars', 'playerID=1&amp;bg=0xffffff&amp;leftbg=0xe1e1e1&amp;lefticon=0x2e4189&amp;rightbg=0xd0e4c7&amp;rightbghover=0xb7caa1&amp;righticon=0x2e4189&amp;righticonhover=0x2e4189&amp;text=0x444444&amp;slider=0x2e4189&amp;track=0xFFFFFF&amp;border=0xb7caa1&amp;loader=0xd0e4c7&amp;loop=no&amp;autostart=no&amp;soundFile=http://prohealthcare.cachefly.net/Audio-Files/' + divID + '.mp3');
        so.addParam('allowscriptaccess', 'always');
        so.addParam('menu', 'false');
        so.addParam('quality', 'high');
        so.write(divID);
    });

    //Removing Find a Physician at this Location Link for Waukesha and Oconomowoc
    var locArray = [];
    locArray[0] = 'Waukesha Memorial Hospital';
    locArray[1] = 'Oconomowoc Memorial Hospital';

    $(function () {
        $('.LocationsList>ul>li').each(function () {
            var $name = $(this).find('.Headline a').html();
            if ($.inArray($name, locArray) >= 0) {
                $(this).find('.DoctorLink').hide()
            }
        });
    });

    //Mobile MainNav - find inner html and apply style to that li
    $("#Mobile #MainNav li:contains('Doctor')").addClass("Doctor");
    $("#Mobile #MainNav li:contains('Location')").addClass("Location");
    $("#Mobile #MainNav li:contains('Events')").addClass("Events");
    $("#Mobile #MainNav li:contains('Wait')").addClass("Wait");
    $("#Mobile #MainNav li:contains('Symptom')").addClass("Symptom");
    $("#Mobile #MainNav li:contains('Contact')").addClass("Contact");
    $("#Mobile #MainNav li:contains('Why')").addClass("Why");

    // Find #WaitTimeHeader and add class to the div.cmspage above it in order to change styling in child elements
    $('#Mobile #WaitTimeHeader').parent('.cmspage').addClass('WaitTimes');

    // Add space in the Waukesha wait times - there is an Adult and Pediatric wait time & the formatting gets messed up without this hack
    $("#Mobile .WaitTimes h3:contains('Waukesha : I-94 & Hwy. 164')").addClass("SpaceAfter");

    // Add space before More Information at the bottom of the wait time page
    $("#Mobile .WaitTimes h2:contains('More Information')").addClass("SpaceBefore");

    // 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'))
    });
    // Move Prev and Next links to their own line
    $('#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();
    });

    // Event Details - Move td with class EventDetailTime to its own row
    $('#Mobile .CalendarEventDetailHeader').each(function () {
        var EventTime = $(this).find('.EventDetailTime');
        $(this).find('tr').before('<tr><td class="EventDetailTime">' + EventTime.html() + '</td></tr>');
        EventTime.remove();
    });
    // Event Detials - Add class of first to h3 and h4 in Tab container
    $('#Mobile .CalendarDetail .Tab h3:first').addClass('First');
    $('#Mobile .CalendarDetail .Tab h4:first').addClass('First');






});   // End Document Ready
