$(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(/mymethodist.net/, document.domain);
		  this.href = this.href.replace(/www./, '');
		  this.href = this.href.replace(/services.urgent-care/, 'mobile/UrgentCare');
	   });

});  //END DOC READY


// Quality Reports Pop-Ups
function qualityPopUps() {
	var contentContainer = document.getElementById('PageContent');
	if (contentContainer) {
		var tableList = contentContainer.getElementsByTagName('table');
		for (var i = 0; i<tableList.length; i++) {
			if (tableList[i].className == 'QualityReports') {
				var anchorList = tableList[i].getElementsByTagName('a');
				for (var j = 0; j<anchorList.length; j++) {
					anchorList[j].onclick=function() {
						return popUp(this.href,350,250);
					}
				}
			}
		}
	}
}
addEvent(window, 'load', qualityPopUps, false);


// AddThis 
function addAddThis() {
var urlToUse = (('https:' == document.location.protocol) ? 'https://s7.addthis.com/js/250/addthis_widget.js?pub=methodistil' : 'http://s7.addthis.com/js/250/addthis_widget.js?pub=methodistil');
$('div.AddThis').append('<p>' +
			'<!-- AddThis Button BEGIN -->' +
				'<script type="text/javascript">var addthis_pub = "methodistil";</script>' +
				'<a href="http://www.addthis.com/bookmark.php?v=250&pub=methodistil" onmouseover="return addthis_open(this, \'\', \'[URL]\', \'[TITLE]\')" onmouseout="addthis_close();" onclick="return addthis_sendto();">' +
				'<img src="/img/logo/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/>' +
				'</a>' +
				'<script type="text/javascript" src="' + urlToUse + '"></script>' +
			'<!-- AddThis Button END -->' +
'</p>');
}
	
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(){
						   
   addAddThis();
	dynamicVideoPlayer();

// ----------- TEMPLATE EXTRAS ------------------//

	$('#Col3 .GreenBack').wrap('<div class="GreenBack2"></div>');
	$('#Col3 #FlashVideo').parent().parent().parent().parent().parent('.cmspanel').addClass('FlashPanel');
	$('#Col3 .cmsPanelContent').addClass('ClearFix');
	$('body.mcon div.Right').appendTo('#MainNav');

// ----------- HACK LIST START ------------------//

	$('.Tab').addClass('ClearFix');
	
	//removing padding from empty table cells from calendar event detail header
	$('.CalendarEventDetailHeader td:empty').addClass('Empty');
	
	//adding hack to be fixed after 5.2.7
	$('.TabContainer').addClass('TabContainerlive');

// ----------- HACK LIST END ------------------//

});


