if(window.location.hash == '#wopClose')
{
    parent.wopFadeOutTS('0.5');
}


function wopGetInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}


var wopOverlay = document.createElement("div");
wopOverlay.id = 'wopOverlay';
document.body.appendChild(wopOverlay);


var wopIFrameHolder = document.createElement("div");
wopIFrameHolder.id = 'wopIFrameHolder';
wopIFrameHolder.style.width = 1 + 'px';
wopIFrameHolder.style.height = 1 + 'px';
wopIFrameHolder.style.left = 50 + '%';
wopIFrameHolder.style.position = 'absolute';
wopIFrameHolder.style.display = 'none';
wopIFrameHolder.style.zIndex = 99999999;
document.body.appendChild(wopIFrameHolder);

var wopIFrame = document.createElement("iframe");
wopIFrame.setAttribute('id', 'wopIFrame');
wopIFrame.setAttribute('src', '');

if(wopGetInternetExplorerVersion() < 7 && wopGetInternetExplorerVersion() > 1 )
{
    wopIFrame.setAttribute('height', '800px');
}
else
{
    wopIFrame.setAttribute('height', '100%');
}

wopIFrame.setAttribute('width', '100%');
wopIFrame.setAttribute('marginheight', '0');
wopIFrame.setAttribute('marginwidth', '0');
wopIFrame.setAttribute('frameborder', '0');
wopIFrame.setAttribute('scrolling', 'no');
wopIFrame.setAttribute('ALLOWTRANSPARENCY', 'true');
wopIFrameHolder.appendChild(wopIFrame);


//Floating JavaScript
var wopPageWidth = 0; var wopPageHeight = 0; var wopScrOfX = 0; wopScrOfY = 0;
function wopPositionOverlay()
{
    if( typeof( window.innerWidth ) == 'number' ) { //Non-IE
	  wopPageWidth = window.innerWidth; wopPageHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
	  wopPageWidth = document.documentElement.clientWidth; wopPageHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
	  wopPageWidth = document.body.clientWidth; wopPageHeight = document.body.clientHeight;
    }
	  
    if( typeof( window.pageYOffset ) == 'number' ) { //Netscape compliant
	  wopScrOfY = window.pageYOffset; wopScrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { //DOM compliant
	  wopScrOfY = document.body.scrollTop; wopScrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {//IE6 standards compliant mode
	  wopScrOfY = document.documentElement.scrollTop; wopScrOfX = document.documentElement.scrollLeft;
    }

    wopOverlay.style.width = (wopPageWidth + wopScrOfX) + 'px';
    wopOverlay.style.height = (wopPageHeight + wopScrOfY ) + 'px';
    wopOverlay.style.top = 0 + 'px';
    wopOverlay.style.left = 0 + 'px';
    
    wopIFrameHolder.style.minWidth = '950px';
    wopIFrameHolder.style.width = '100%';
    wopIFrameHolder.style.height = (wopPageHeight + wopScrOfY ) + 'px';
    wopIFrameHolder.style.top = 0 + 'px';
    wopIFrameHolder.style.left = 0 + 'px'; 
}




function wopFloatOverlay()
{
    wopPositionOverlay();
    wopOverlay.style.opacity = '0';
    wopOverlay.style.filter = 'alpha(opacity:0)';
    wopOverlay.style.zIndex = 999999;
    wopOverlay.style.width = 100 + '%';
    wopOverlay.style.height = 100 + '%';
    wopOverlay.style.position = 'fixed';
    wopOverlay.style.bottom = 0 + 'px';
    wopOverlay.style.top = 'auto';    

    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;
        }
    }  
    
    if(!isSupported)
    {
        wopPositionOverlay();
        wopOverlay.style.position = 'absolute';
    }
    
    window.onscroll = wopPositionOverlay;
    window.onresize = wopPositionOverlay;
}


var wopOverlayOpacity = 0;//Will be used to track current opacity of div for fadeout and fadein function



function wopLoad(opacity, fadeLength, color, url)
{
    if(window.location.hash != '#autoload' && document.getElementById('WebOutContainer').style.display != 'none')
    {
            if (navigator.appName == 'Microsoft Internet Explorer')
            {
                    newWO(350, 500, '', '', '');
            }
            
            document.getElementById('WebOutContainer').style.display = 'none';
    }
    
    scroll(0,0)
    wopOverlay.style.visibility = 'visible';
    wopOverlay.style.opacity = '0';
    wopOverlay.style.filter = 'alpha(opacity:0)';
    wopOverlay.style.zIndex = 99999;
    wopOverlay.style.backgroundColor = color;

    wopOverlay.style.display = 'block';
    wopFloatOverlay();
    overlayFinalOpacity = opacity;
    fadeIncrement = (opacity/(fadeLength * 30));
    fadeInterval = setInterval(wopFadeOverlay, 33);

    function wopFadeOverlay()
    {
	if(wopOverlayOpacity < overlayFinalOpacity)
	{
	    wopOverlayOpacity = wopOverlayOpacity + fadeIncrement;
	    wopOverlay.style.opacity = wopOverlayOpacity;
	    wopOverlay.style.filter = 'alpha(opacity:' + (wopOverlayOpacity * 100) +')';
	}
	else
	{
	    clearInterval(fadeInterval);
	    wopIFrameHolder.style.position = 'absolute';
	    wopIFrameHolder.style.zIndex = 99999999;
	    wopIFrameHolder.style.display = 'block';
	    
	    //For security reasons if the current location has www., the url needs to contain that as well (or not)
	    hn = document.location.protocol + "//" + document.location.hostname;
	    hnl = document.location.hostname.length;
	    a = url.indexOf(document.location.hostname);
	    b = url.substr(a + hnl)
	    c = hn + b;
	    
	    parentlocation = String(window.location);
	    hashlocation = parentlocation.indexOf('#autoload');
	    locationNoHash = parentlocation.substring(0, hashlocation);
	    
	    if(hashlocation > -1)
	    {
		document.getElementById('wopIFrame').src = url + '#' + locationNoHash;
	    }
	    else
	    {
		document.getElementById('wopIFrame').src = url + '#' + window.location;
	    } 
	}
    }
}


function wopCheckClose()
{
    if(window.location.hash == '#wopClose')
    {
	clearInterval(wopCloseCheckInterval);
	parent.wopFadeOutTS('0.5');
    }
}


function wopFadeOutTS(fadeLength)
{
    wopOverlayOpacity = 0;
    wopOverlay.style.display = 'none';
    wopIFrameHolder.style.display = 'none';
    
    //clearInterval(fadeInterval);
}

if(window.location.hash == '#autoload')
{
    wopLoad('0.8', '0.5', '#ffffff', 'http://www.affinityhealth.org/webout-ext/Presentations/St.E/wop.html');
}



//Check For Returning Visitors
function getWOPaCookie (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}

function writeWOPaCookie (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(getWOPaCookie('wopCookie'))
{	
	if(!getWOPaCookie('wopAfter11_3a_11'))
	{
	    _gaq.push(['_trackEvent', 'WebOuts', 'ReturnSince11_3_11']);
	    writeWOPaCookie('wopAfter11_3a_11', 'True', 'years', 10);
	}
}
else
{
	writeWOPaCookie('wopAfter11_3a_11', 'True', 'years', 10);
} 
