//client stuff
function addTextSizer() {
    $('#PageToolsWrapper').append('<div id="TextSizer" class="ClearFix"><h2>Text Size</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 urlToUse = (("https:" == document.location.protocol) ? "https://secure.addthis.com/js/250/addthis_widget.js#username=alexianvs5" : "http://s7.addthis.com/js/250/addthis_widget.js#username=alexianvs5");
    var imgPath = '/imgs/icons/';
    $('#PageToolsWrapper').append('<div id="PageTools" class="ClearFix">' +
		'<h2 class="Hide">Page Tools</h2>' +
		'<ul>' +
			'<li class="Print"><a href="#">Print</a></li>' +
			'<li class="Share">' +
				'<!-- AddThis Button BEGIN -->' +
				'<script type="text/javascript">var addthis_pub  = \'alexianvs5\';</script>' +
                   '<a class="addthis_button" href="http://www.addthis.com/bookmark.php?v=250&amp;username=alexianvs5">Share</a>' +
                   '<script type="text/javascript" src="' + urlToUse + '"></script>' +
                '<!-- AddThis Button END -->' +
			'</li>' +
            '<li class="Save"><a href="javascript:Save(document.title,window.location)">Save</a></li>' +
		'</ul>' + 
	'</div>');
    var clientDomainName = 'alexianbrothershealth.org';
    var clientSiteName = 'Alexian Brothers Health System';
    var titleEl = document.getElementsByTagName('title')[0];
    var currentPageTitle = "";
    if (titleEl.text) { currentPageTitle = titleEl.text; } else { currentPageTitle = title.data; }
    currentPageTitle = escape(currentPageTitle);
    var currentPageUrl = document.location;
    var emailSubject = clientDomainName + ": " + currentPageTitle;
    var emailHref = "mailto:?subject=" + emailSubject + "&body=I thought you would be interested in a page on the " + clientSiteName + " Web site: " + currentPageTitle + " - " + currentPageUrl;
    $("li.Email a").attr({ href: emailHref });
    $("li.Print a").click(function() { print(); return false; });
}



$(document).ready(function() {

// Add Basic Search to the Advanced Search page....	
// Markup to look like this:
//	<div id="basicSearch">
//		<input type="text" name="keyword" id="theKeyword">
//		<input type="hidden" value="/doctors-locations/medicare gold/basic-search-results.aspx" id="theSearchPage">
//		<input type="hidden" value="Name, Specialty, City, and ZIP Code" id="thisInputText">
//		<input type="button" value="Search" id="basicSearchButton" class="Button">
//	</div>
  
	$('.basicSearch').each(function(){
		var thisInputText = $(this).find('input.thisInputText').val();
		var theInput = $(this).find('input.theKeyword');
		if (thisInputText.length){theInput.val(thisInputText)};
		
		$(this).find('input.theKeyword')
			.bind('focus', function() {
				var thisInputText = $(this).siblings('input.thisInputText').val();
				if ($(this).val()==thisInputText){ $(this).val('') };
			})
			.bind('blur', function() {
				var thisInputText = $(this).siblings('input#thisInputText').val();
				if ($(this).val()==''){ $(this).val(thisInputText) };
			})
			.bind('keypress', function(e) {
			   $(this).siblings($('.error:visible').slideUp());
				if (e.keyCode == 13) {
					e.preventDefault();
					var thisInputText = $(this).siblings('input.thisInputText').val();
						if (thisInputText.length==0) {thisInputTest = ''};
					var kword = $(this).val();
					if (kword.length && kword != thisInputText){
						var domainURL = jQuery.url.attr('host'); // returns 'mysite.com'
						var searchPage = $(this).siblings('input.theSearchPage').val();
						window.location = ('http://' + domainURL + searchPage + '?sort=7&keyword=' + kword);
					}
					else{ 
						$(this).prepend('<div style="color:red" class="error">Please enter in your search criteria.</div>');
					}
				}
		});
		
		$(this).find('.basicSearchButton').click(function(){
			var thisInputText = $(this).siblings('input.thisInputText').val();
				if (thisInputText.length==0) {thisInputTest = ''};
			var kword = $(this).siblings('input.theKeyword').val();
			if (kword.length && kword != thisInputText){
				var domainURL = jQuery.url.attr('host'); // returns 'mysite.com'
				var searchPage = $(this).siblings('input.theSearchPage').val();
				window.location = ('http://' + domainURL + searchPage + '?sort=7&keyword=' + kword);
			}
			else{
				$(this).prepend('<div style="color:red" class="error">Please enter in your search criteria.</div>');
			}
		});
			
});
	
	
		


// 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.
//		<select class="JumpMenu"> <option value="/search.aspx">Search</option> <option class="new" value="/search.aspx">Search in New Window</option> <option value="HiddenDivClass">Show div</option> </select>

	$('.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*
	
}); // END DOC READY


/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
function Save(title, url) {
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if (document.all)// ie
        window.external.AddFavorite(url, title);
    else {
        // other browsers - tell them to add a bookmark (adds current page, not target page)
        window.alert('Please use your browser\'s bookmarking facility to create a bookmark');
    }
}

function dynamicVideoPlayer(){
// markup to use: <a class="VideoLink" href="video/widescreen.mp4" title="height=288;width=512;aspect=16x9;hideControls=true;imageFilename=video/widescreen.jpg;">Video</a>
	String.prototype.startsWith = function(str) {return (this.match("^"+str)==str);}; // this creates a function that can be used to check if a string starts with a value
	// for each a.VideoLink, put a player in place
	$('a.VideoLink').each(function(n){
		var divID = 'videoID'+n;
			$(this).wrap('<div class="DynamicVideoPlayer" id="' + divID + '"></div>');
		var filename = $(this).attr('href');
		var vars = $(this).attr('title').replace(/\s+/g,'');
		var varArray = vars.split(";");
		var height, width, aspect, hideControls, imageFilename, theImage;
		height = width = aspect = hideControls = imageFilename = theImage = '';
		
		var cnt = 0;
		while (cnt < varArray.length) {
			if (varArray[cnt].toLowerCase().startsWith('height=')) { height = varArray[cnt].toLowerCase().replace(/height=/g,''); }
			if (varArray[cnt].toLowerCase().startsWith('width=')) { width = varArray[cnt].toLowerCase().replace(/width=/g,''); }
			if (varArray[cnt].toLowerCase().startsWith('aspect=')) { aspect = '_' + varArray[cnt].toLowerCase().replace(/aspect=/g,''); }
			if (varArray[cnt].toLowerCase().startsWith('hidecontrols=')) { hideControls = varArray[cnt].toLowerCase().replace(/hidecontrols=/g,''); }
			if (varArray[cnt].toLowerCase().startsWith('imagefilename=')) { imageFilename = varArray[cnt].toLowerCase().replace(/imagefilename=/g,''); }
			cnt+=1;
		}
		if (height < 0 || height > 600) { height = "240"; }
		if (width < 0 || width > 800) { width = "360"; }
		if ( aspect.length && !(aspect == '_4x3' || aspect == '_16x9' || aspect == '_1x1') ) { aspect = "_4x3"; }
		if (hideControls !== 'true' && hideControls !== 'false') { hideControls = 'false'; }
		if (imageFilename.length > 0 ) { theImage = 'imageFilename=' + imageFilename + '&'; }
			
		var so = new SWFObject('/video/videoPlayer' + aspect + '.swf?videoURL=' + filename, 'swf', width, height, '7' );
		so.addParam('wmode', 'transparent');
		so.addParam('FlashVars', theImage + 'hideControls=' + hideControls);
		so.addParam('allowscriptaccess', 'always');
		so.addParam('allowfullscreen', 'true');	
		so.write(divID);
	});
}

$(document).ready(function() {
			
	addTextSizer();
	text_size_checker();
	addPageTools();
	dynamicVideoPlayer();
	
// ----------- TEMPLATE EXTRAS ------------------//

/* adding padding to the last main nav link to span across entire container 
so that background spans all the way to the right.*/
$('#MainNav span').each(function(i) {
    var ah = $('#MainNav ul').eq(i).width();
    var mh = (996 - ah);
    $('#MainNav li.Last a').eq(i).css('padding-right', mh);
    $('#MainNav li.Last strong').eq(i).css('padding-right', mh);
});

//add extra class HomeTopAlert
    $('#HomeTop .cmspanel').before('<div class="AlertTop"></div>');

// ----------- HACK LIST ------------------//
//fixing 5.2.7 release tab containers
	$('.TabContainer').addClass('TabContainerlive');

//add extra classes to DeepFooter Panels
    $('#DeepFooter .cmspanel').before('<div class="DeepFooterTop"></div>');
    $('#DeepFooter .cmspanel').after('<div class="DeepFooterBtm"></div>');

//add extra classes to Col3 Panels
    $('#Col3 .cmspanel').before('<div class="Col3PanelTop"></div>');
    $('#Col3 .cmspanel').after('<div class="Col3PanelBtm"></div>');

//add span to Tabactive 
    $('.TabContainerlive ul.Tabnav li a').wrapInner('<span></span>');
//add span to Tabactive on Search
    $('#SiteSearchContainer ul.Tabnav li a').wrapInner('<span></span>');
    
//auto expand dropdowns for IE 
    $('select').mousedown(function () {
        $(this).css("width","100%");
    });
    $('select').blur(function () {
        $(this).css("width","");
    });
    
//change search button text on find a doc 
  $('.DrSearch .ButtonHolder input.Button').val('Browse All Doctors');       
    
  $('.DrSearch select').change(function () {
        $('.DrSearch .ButtonHolder input.Button').val('Search');
  });
  $('.DrSearch input').change(function () {
        $('.DrSearch .ButtonHolder input.Button').val('Search');
  });
  
//hide doctor silhouette with blank image
    $('#DrDetail .QuickInfo img').each(function() {
    if ($(this).attr('src') == '../imgs/doctors/silhouette_malebig.gif' || $(this).attr('src') == '/imgs/doctors/silhouette_femalebig.gif') {
            $(this).replaceWith('');
            $('#DrDetail .QuickInfo div.Designations').css({ 'margin-left': '0' });
        }
    });

// ----------- HACK LIST END ------------------//

}); // End Document Ready

// 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 = 9000; // 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 = $(".tabbed-box .tabs a").index(clickedTab);
		$(".tabbed-box .tabs li a").removeClass("active");
		$(".tabbed-box .tabs li a:eq("+thisTab+")").addClass("active");
		$(".tabbed-box .tabbed-content").hide();
		$(".tabbed-box .tabbed-content:eq("+thisTab+")").show();
		currentTab = thisTab;
	
		}

	function rotateTabs() {
		var nextTab = (currentTab == (numTabs - 1)) ? 0 : currentTab + 1;
		openTab($(".tabbed-box .tabs li a:eq("+nextTab+")"));
	
	}

	$(document).ready(function() {
	    $(".tabbed-box .tabs").css({ 'display': 'block' });
		$(".tabbed-content").equalHeights();
		numTabs = $(".tabbed-box .tabs li a").length;
		$(".tabbed-box .tabs li a").click(function() { 
			openTab($(this));
	
			return false; 
			
		});
		$(".tabbed-box").mouseover(function(){clearInterval(autoRotate)})
		.mouseout(function(){autoRotate = setInterval("rotateTabs()", rotateSpeed)});
		
		$(".tabbed-box .tabs li a:eq("+currentTab+")").click()
		$(".tabbed-box").mouseout();
		
	});