//Adjusts the horizontal alignment of the ad container, use 'left', 'center', or 'right'
var woad_Align = 'center';

//Offsets the position of the ad container in relation to its alignment.
//Example: -20 will move the ad container 20 pixels to the left, 30 will move the container 30 pixels to the right
var woad_XOffset = 0;

//To float the ad container at the bottom of the browser window, set to 'true'.
//To give the ad an absolute position on the page, set to 'false'
var woad_FloatAd = 'true';

//If ad container is floating at the bottom of the browser window,
//this will determine the amount of space (in pixels) between the ad container and the bottom of the browser window.
var woad_BottomMargin = 0;

//If ad container has an absolute position (not floatign),
//this will adjust the ad containers verticle position (in pixels) in relation to the top of the page
var woad_Top = 0;

//Limits the amount of time the ad container is displayed in seconds.
//If set to 0 the ad container will remain on the page indefinately.
var woad_Timer = 0;

//Set to true to always display the ad when the page loads
var woad_showOnPageLoad = true;

//Only needed if option above is set to true.
//If set to true, it will hide the ad container while the WebOut is playing.
var woad_hideOnWebOutLoad = false;

//Set to true to display the the ad when the WebOut is complete or closed
var woad_showOnWebOutComplete = false;

//Set to true to display the ad when the user returns to the page for a second time.
var woad_showOnCookie = true;

//set to true to disable to ad from displaying (even if options above are set to true)
var woad_showNever = false;

var WO_AD = document.createElement("div");
document.body.appendChild(WO_AD);

var woad_Width = 615; var woad_Height = 122;
function placeWO_Ad(w, h, t, pa, ml, b, f, timer)
{
	WO_AD.style.visible = 'visible';
	WO_AD.style.overflow = 'hidden';
	WO_AD.style.position = 'absolute';
        WO_AD.style.display = 'block';

	WO_AD.style.zIndex = 9999;
	WO_AD.style.width = w +'px';
	WO_AD.style.height = h + 'px';
	WO_AD.style.decoration = 'none';
	WO_AD.innerHTML = "<img src='http://www.affinityhealth.org/webout-ext/Presentations/St.E/images/layout/Ad.png' width='615' height='122' border='0' usemap='#Map' /><map name='Map' id='Map'><area shape='rect' coords='536,44,593,67' href=\"javascript:hide_woad();\" /><area shape='poly' coords='598,124,598,74,531,74,531,35,30,36,29,122' href=\"javascript:wopLoad('0.8', '0.5', '#ffffff', 'http://www.affinityhealth.org/webout-ext/Presentations/St.E/wop.html');\" /></map>";
        
	if(pa == 'left')
	{
            WO_AD.style.left = 0 + 'px';
            WO_AD.style.marginLeft = ml + 'px';        
	}
	else if(pa == 'center')
	{
            WO_AD.style.left =  50 + '%';
            WO_AD.style.marginLeft = -(w/2) + ml + 'px';
	}
	else
	{
            WO_AD.style.left = 100 + '%';
            WO_AD.style.marginLeft = -w + ml + 'px';
	}
        
        woad_Height = h;
        woad_Width = w;
        woad_BottomMargin = b;
        woad_Timer = timer;
	
	if(f == 'true')
	{
	    WO_AD.style.position = 'fixed';
            woad_floatWebOut();
	}
        
        if(woad_Timer > 0)
        {
            var int = setInterval("hide_woad()", woad_Timer * 1000);
        }
}


var woad_PageWidth = 0; var woad_PageHeight = 0; var woad_ScrOfY = 0;
function woad_GetPageDimensions()
{
	if( typeof( window.innerWidth ) == 'number' ) { //Non-IE
	      woad_PageWidth = window.innerWidth; woad_PageHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
	      woad_PageWidth = document.documentElement.clientWidth; woad_PageHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
	      woad_PageWidth = document.body.clientWidth; woad_PageHeight = document.body.clientHeight;
	}
	      
	if( typeof( window.pageYOffset ) == 'number' ) { //Netscape compliant
	      woad_ScrOfY = window.pageYOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { //DOM compliant
	      woad_ScrOfY = document.body.scrollTop;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {//IE6 standards compliant mode
	      woad_ScrOfY = document.documentElement.scrollTop; 
	}
}

function woad_NoFixedFloat()
{
	woad_GetPageDimensions();
	if(woad_PageHeight > woad_Height)
	{
		WO_AD.style.top = (woad_ScrOfY + woad_PageHeight - woad_Height - woad_BottomMargin) + 'px';
	}
	else
	{
		WO_AD.style.top = woad_ScrOfY + 'px';
	}
}

function woad_fixedFloat()
{
	woad_GetPageDimensions();
	if (woad_PageHeight > woad_Height)
	{
		WO_AD.style.position = 'fixed';
		WO_AD.style.bottom = woad_BottomMargin + 'px';
		WO_AD.style.top = 'auto';
	}
	else
	{
		WO_AD.style.position = 'fixed';
		WO_AD.style.top = 0 + 'px';		
	}
}

function woad_floatWebOut()
{
	var isSupported = null;
	if (document.createElement)
	{
		var el = document.createElement("div");
		if (el && el.style)
		{
		      el.style.width = "1px";
		      el.style.height = "1px";
		      el.style.position = "fixed";
		      el.style.top = "10px";
		      var root = document.body;
		      if (root && root.appendChild && root.removeChild)
		      {
			      root.appendChild(el);
			      isSupported = el.offsetTop === 10;
			      root.removeChild(el);
		      }
		      el = null;
		}
	}
	woad_GetPageDimensions();
	
	if (isSupported)
	{
		woad_fixedFloat();
		window.onresize = woad_fixedFloat;
	}	
	else
	{
		WO_AD.style.position = 'absolute';
		woad_NoFixedFloat();
		window.onscroll = woad_NoFixedFloat;
		window.onresize = woad_NoFixedFloat;
	}
}


woad_DisplayOnPageLoad();
function woad_DisplayOnPageLoad()
{
    if(woad_showNever != true && woad_showOnPageLoad == true)
    {
        placeWO_Ad(woad_Width, woad_Height, woad_Top, woad_Align, woad_XOffset, woad_BottomMargin, woad_FloatAd, woad_Timer);
    }
}

function woad_DisplayOnWebOutComplete()
{
    if(woad_showNever != true && woad_showOnWebOutComplete == true)
    {
        placeWO_Ad(woad_Width, woad_Height, woad_Top, woad_Align, woad_XOffset, woad_BottomMargin, woad_FloatAd, woad_Timer);
    }
}

function woad_DisplayOnCookie()
{
    if(woad_showNever != true && woad_showOnCookie == true)
    {
        placeWO_Ad(woad_Width, woad_Height, woad_Top, woad_Align, woad_XOffset, woad_BottomMargin, woad_FloatAd, woad_Timer);
    }
}

function woad_HideOnWebOutPlay()
{
    if(woad_hideOnWebOutLoad == true)
    {
        WO_AD.style.display = 'none';
    }
}

function hide_woad()
{
    WO_AD.style.display = 'none';
}



function getWebOutAdCookie (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}


function writeWebOutAdCookie (CookieName, CookieValue, periodType, offset) {

  var expireDate = new Date ();
  offset = offset / 1;
  
  var myPeriodType = periodType;
  switch (myPeriodType.toLowerCase()) {
    case "years": 
     var year = expireDate.getYear();     
     // Note some browsers give only the years since 1900, and some since 0.
     if (year < 1000) year = year + 1900;     
     expireDate.setYear(year + offset);
     break;
    case "months":
      expireDate.setMonth(expireDate.getMonth() + offset);
      break;
    case "days":
      expireDate.setDate(expireDate.getDate() + offset);
      break;
    case "hours":
      expireDate.setHours(expireDate.getHours() + offset);
      break;
    case "minutes":
      expireDate.setMinutes(expireDate.getMinutes() + offset);
      break;
  } 
  
  document.cookie = escape(CookieName ) + "=" + escape(CookieValue) + "; expires=" + expireDate.toGMTString() + "; path=/";
}  


if(!getWebOutAdCookie('woad_cookie'))
{
    writeWebOutAdCookie ('woad_cookie', 'True', 'years', 10); 
}
else
{
    woad_DisplayOnCookie();
       
} 
