if(rkHealthyButton == null)
{
	var rkHealthyButton = {};
	
	rkHealthyButton.rkGetElementByClassName = function(className)
	{
		var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
		var allElements = document.getElementsByTagName("*");
		var results = [];
	
		var element;
		for (var i = 0; (element = allElements[i]) != null; i++) {
			var elementClass = element.className;
			try
			{
				//Have to check if indexOf is defined bc SVG className return's and object not string, which breaks this funciton. We aren't concerned with SVG so works for us
				if (elementClass && typeof elementClass.indexOf == 'function' && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
					results.push(element);
				}
			catch(e)
			{
			}
		}
	
		return results;
	}		
	
	function rkReceiveMessage(event)
	{
		if(event.origin == rkHealthyButton.rkBaseUrl)
		{
			if(typeof rkHealthyButton.healthyCallback == 'function')
				rkHealthyButton.healthyCallback(event.data);
		}
	}
	
	rkHealthyButton.rkInitialize = function()
	{
		rkHealthyButton.waitForResponse = false;				
		
		var scripts = document.getElementsByTagName("script");		
		for(var i = 0 ; i < scripts.length ; i++)
		{
			if(scripts[i].src.indexOf("/static/js/healthy/rkHealthyButton.js") != -1) 
			{				
				rkHealthyButton.rkBaseUrl = scripts[i].src.substring(0,scripts[i].src.indexOf("/static/js/healthy/rkHealthyButton.js"));			 			
			}				
		}			
		
		if(typeof window.addEventListener == 'function')
			window.addEventListener("message",rkReceiveMessage,false);
		else
			window.attachEvent("onmessage",rkReceiveMessage,false);
		
		head = document.getElementsByTagName("head");
		rkHealthyCss = document.createElement("link");           
		rkHealthyCss.setAttribute("rel", "stylesheet")
		rkHealthyCss.setAttribute("type", "text/css")
		rkHealthyCss.setAttribute("href", rkHealthyButton.rkBaseUrl + '/static/kronos/css/HealthyButton.css');
		head[0].appendChild(rkHealthyCss);
				
		results = rkHealthyButton.rkGetElementByClassName('rk-healthy');
		if(results.length > 0)
		{
			for(i = 0 ; i < results.length ; i++)
			{							  			  
			  buttonType = encodeURIComponent(results[i].getAttribute('data-buttonType'));
			  healthyUrl = encodeURIComponent(decodeURIComponent(results[i].getAttribute('data-healthyUrl'))); //incase the developer already url encoded it.			  
			  
			  divRunKeeper = document.createElement("div");
			  				  
			  
			  frame = document.createElement("IFRAME");
			  frame.setAttribute("src",rkHealthyButton.rkBaseUrl + "/generateHealthyButton?buttonType=" + buttonType + "&origin=external&healthyUrl=" + healthyUrl);
			  frame.setAttribute("frameBorder","0");
			  frame.setAttribute("allowTransparency","true");
			  frame.setAttribute("scrolling","no");
			  
			  //setAttribute('style','foo') is broken in IE7 and 8 so we get to do it the long way :)
			  if(buttonType == "normal")
			  {
				  frame.style.height="22px";
				  frame.style.width="80px";
				  frame.style.border="none";
				  divRunKeeper.style.height="20px";
				  divRunKeeper.style.width="62px";
				  divRunKeeper.style.position="relative";
				  divRunKeeper.style.overflow="hidden";
			  }
			  else if(buttonType == "normalCount")
			  {
				  frame.style.height="25px";//20
				  frame.style.width="90px";//85
				  frame.style.border="none";
				  frame.style.overflow="hidden";					  
				  divRunKeeper.style.height="25px";
				  divRunKeeper.style.width="90px";
				  divRunKeeper.style.position="relative";
				  divRunKeeper.style.overflow="hidden";
			  }
			  else if(buttonType == "vertical")
			  {
				  frame.style.height="44px";
				  frame.style.width="62px";
				  frame.style.border="none";
				  frame.style.margin="auto";				  
				  divRunKeeper.style.height="44px";
				  divRunKeeper.style.width="62px";
				  divRunKeeper.style.margin="auto";
				  divRunKeeper.style.overflow="hidden";
			  }
				  				  					  					  
			  divRunKeeper.appendChild(frame);						  				  
			  				  				  
			  results[i].appendChild(divRunKeeper);				  			  			  
			}
		}
	}	
	rkHealthyButton.rkInitialize();
}
