//client stuff
// 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 = $('#FoxValleyHome .TabContainer .Tabnav a').index(clickedTab);
        $('#FoxValleyHome .TabContainer .Tabnav li').removeClass('Tabactive');
        $('#FoxValleyHome .TabContainer .Tabnav li:eq(' + thisTab + ')').addClass('Tabactive');
        $('#FoxValleyHome .TabContainer .Tab').hide();
        $('#FoxValleyHome .TabContainer .Tab:eq(' + thisTab + ')').show();
        currentTab = thisTab;
    }

    function rotateTabs() {
        var nextTab = (currentTab == (numTabs - 1)) ? 0 : currentTab + 1;
        openTab($('#FoxValleyHome .TabContainer .Tabnav li a:eq(' + nextTab + ')'));
    }

    $(document).ready(function () {
		$('#FoxValleyHome .Tab').wrapInner('<div class="TabDec"></div>');
        //$('#FoxValleyHome .Tab').equalHeights();
        numTabs = $('#FoxValleyHome .TabContainer .Tabnav li a').length;
        $('#FoxValleyHome .TabContainer .Tabnav li a').click(function () {
            openTab($(this)); return false;
        });
        $('#FoxValleyHome .TabContainer').mouseover(function () { clearInterval(autoRotate) })
        .mouseout(function () { autoRotate = setInterval('rotateTabs()', rotateSpeed) });
        $('#FoxValleyHome .TabContainer .Tabnav li a:eq(' + currentTab + ')').click()
        $('#FoxValleyHome .TabContainer').mouseout();
	});  // End Document Ready

$(document).ready(function(){

// ----------- TEMPLATE EXTRAS ------------------//
	//appt screening form
    //$('div.TotalHeartTestDescription').insertAfter('.ScheduleCheckboxList input[value="Total Heart Test - $99"]').next('label');
    //$('div.KnowYourNumbersDescription').insertAfter('.ScheduleCheckboxList input[value="Know Your Numbers - $25"]').next('label');
    //$('div.VascularScreeningPackageDescription').insertAfter('.ScheduleCheckboxList input[value="Vascular Screening Package - $50"]').next('label');
    $('.ScheduleCheckboxList input[value="Total Heart Test - $99"]').next('label').after($('div.TotalHeartTestDescription').remove());
    $('.ScheduleCheckboxList input[value="Know Your Numbers - $25"]').next('label').after($('div.KnowYourNumbersDescription').remove());
    $('.ScheduleCheckboxList input[value="Vascular Screening Package - $50"]').next('label').after($('div.VascularScreeningPackageDescription').remove());

// ----------- HACK LIST START ------------------//

//removing padding from empty table cells from calendar event detail header
    $('.CalendarEventDetailHeader td:empty').addClass('Empty');

	//replace legends with labels
	$('legend').each(function(index) {
		$(this).replaceWith('<label class="Block">' + $(this).html() + '</label>');
	});
	
	// BUG: 25797 - DOCTORS: move status section to the bottom of the doctor profile page.  http://bugzilla.geonetric.com/show_bug.cgi?id=25797
	$('#DrDetail .Tab:first').append( $('#DrDetail .Tab:first>div h3').filter(function(){ return /^Status$/.test( $.trim($(this).text()) ) }).parent('div').remove() );
	$('#DrDetail .Tab:first').append( $('#DrDetail .Disclaimer').remove() );

	// 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 ------------------//
});
