document.write('<div id="habVisitorPopupBox" style="position:absolute; width: 300px; left: 0; top: -400px; border: 2px solid black; background-color: lightyellow; padding: 4px; z-index: 100; visibility:hidden;filter:progid:DXImageTransform.Microsoft.RandomDissolve(duration=1) progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=135); -moz-opacity:0;"></div>');

var habVisitorList       = new Object();
var habVisitorTimer      = 30;
var habVisitorCounter    = 0;
var habVisitorSound      = 'off';
var habVisitorHtmlCode   = '';


//== STICKY NOTE SCRIPT FROM DYNAMIC DRIVE  =============================================
/***********************************************
* Sticky Note script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use
* Go to http://www.dynamicdrive.com/ for full source code
***********************************************/

var visitorDisplayMode="always"

var visitorFadeEnabled="yes"       //("yes" to enable fade in effect, "no" to disable)
var visitorAutoHideBox=["yes", 5]  //Automatically hide box after x seconds? [yes/no, if_yes_hide_after_seconds]
var visitorShowOnScroll="yes"      //Should box remain visible even when user scrolls page? ("yes"/"no)
var visitorFadeLengthIE=1          //fade in duration for IE, in seconds
var visitorFadeDegreeMoz=0.05      //fade in degree for NS6+ (number between 0 and 1. Recommended max: 0.2)

////////No need to edit beyond here///////////

if (parseInt(visitorDisplayMode)!=NaN)
var visitorRandomNum=Math.floor(Math.random()*visitorDisplayMode)

function displayVisitorPopupBox(){
  var ie=document.all && !window.opera
  var dom=document.getElementById
  iebody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
  objref=(dom)? document.getElementById("habVisitorPopupBox") : document.all.habVisitorPopupBox
  var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset
  var docwidth=(ie)? iebody.clientWidth : window.innerWidth
  docheight=(ie)? iebody.clientHeight: window.innerHeight
  var objwidth=objref.offsetWidth
  objheight=objref.offsetHeight
  objref.style.left=docwidth/2-objwidth/2+"px"
  objref.style.top=scroll_top+docheight/2-objheight/2+"px"

  if (visitorShowOnScroll=="yes") visitorShowOnScrollVar=setInterval("visitorStaticFadeBox()", 50)

  if (visitorFadeEnabled=="yes" && objref.filters) {
   objref.filters[0].duration=visitorFadeLengthIE
   objref.filters[0].Apply()
   objref.filters[0].Play()
  }
  objref.style.visibility="visible"
  if (objref.style.MozOpacity){
   if (visitorFadeEnabled=="yes")
    mozfadevar=setInterval("visitorFadeFxMoz()", 90)
   else {
    objref.style.MozOpacity=1
    controlledVisitorHideBox()
   }
  } else
     controlledVisitorHideBox()
}

function visitorFadeFxMoz(){
  if (parseFloat(objref.style.MozOpacity)<1)
   objref.style.MozOpacity=parseFloat(objref.style.MozOpacity)+visitorFadeDegreeMoz
  else {
   clearInterval(mozfadevar)
   controlledVisitorHideBox()
  }
}

function visitorStaticFadeBox(){
  var ie=document.all && !window.opera
  var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset
  objref.style.top=scroll_top+docheight/2-objheight/2+"px"
}

function hideVisitorFadeBox(){
  objref.style.visibility="hidden"
  if (typeof visitorShowOnScrollVar!="undefined")
  clearInterval(visitorShowOnScrollVar)
}

function controlledVisitorHideBox(){
  if (visitorAutoHideBox[0]=="yes"){
   var delayvar=(visitorFadeEnabled=="yes" && objref.filters)? (visitorAutoHideBox[1]+objref.filters[0].duration)*1000 : visitorAutoHideBox[1]*1000
   setTimeout("hideVisitorFadeBox()", delayvar)
  }
}

function initVisitorFunction(){
  setTimeout("displayVisitorPopupBox()", 100)
}
//== END DYNAMIC DRIVE SCRIPT=====================


function getHabVisitorCookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1)
         end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

function readHabVisitors (returnFunction) {
  if (unescape(location.href).indexOf("http://football")!=-1||unescape(location.href).indexOf("http://6")!=-1) var currentURLBase = baseURLDynamic; else var currentURLBase = baseURLStatic;
  var url = currentURLBase + "/fflnetdynamic" + year + "/" + league_id + '_visitors.xml?random=' + get_random_string();
  try {
   makeHttpRequest(url, returnFunction , 1);
  } catch (e) {
     url = window.location.protocol + "//" + window.location.host + "/fflnetdynamic" + year + "/" + league_id + '_visitors.xml?random=' + get_random_string();
     makeHttpRequest(url, returnFunction , 1);
    }
}

function getHabVisitorSound() {
  var cookieName = 'habVisitorSound';
  habVisitorSound = getHabVisitorCookie(cookieName);
}

function saveHabVisitorSound() {
  var today = new Date();
  var expire = new Date();
  var cookieName = 'habVisitorSound';
  expire.setTime(today.getTime() + 1000*60*60*24*7); 
  document.cookie=cookieName+"="+habVisitorSound+";expires="+expire.toGMTString();
}

function toggleHabVisitorSound(mode) {
  if(mode=='on') {
   habVisitorSound='on';
   habVisitorHtmlCode += '<br />Sound has been activated for any further logins';
  } else {
   habVisitorSound='off';
   habVisitorHtmlCode += '<br />Sound has been disabled for any further logins';
  }
  saveHabVisitorSound();
  document.getElementById('habVisitorPopupBox').innerHTML = habVisitorHtmlCode;
}

function popNewVisitor (fid) { 
  var cookieName = fid + "_Popped_" + league_id;  // This is the session cookie
  habVisitorHtmlCode = '';
  try {
   if(fid!=franchise_id&&(getHabVisitorCookie(cookieName)=='')) {
    getHabVisitorSound();
    if(habVisitorSound=='on') {
     habVisitorHtmlCode += '<embed src="http://www.habman.com/mfl/sounds/online.wav" autostart="true" loop="false" hidden="true">';
     habVisitorHtmlCode += '<div align="right"><img src="http://www.habman.com/mfl/sounds/sound_on.gif" alt="click to mute" onclick="toggleHabVisitorSound(\'off\');"  /></div>';
    } else {
     habVisitorHtmlCode += '<div align="right"><img src="http://www.habman.com/mfl/sounds/sound_off.gif" alt="click for sound" onclick="toggleHabVisitorSound(\'on\');"  /></div>';
    }
    habVisitorHtmlCode += '<span style="color: black;">' + franchiseDatabase['fid_' + fid].name + ' has just logged on.</span><br /><br /><br />';
    habVisitorHtmlCode += '<div align="right"><a href="#1" onClick="hideVisitorFadeBox(); return false" style="color: black;">Hide Box</a></div>';
    document.getElementById('habVisitorPopupBox').innerHTML = habVisitorHtmlCode;
    initVisitorFunction();
    document.cookie= cookieName + "=yes";
   }
  } catch(er) { 
     //this is where I would put something
  }
}

function initialVisitors (visitorsXML) {
  var visitors = visitorsXML.getElementsByTagName("visit");
  for (var i = 0; i < visitors.length; i++) {
   var fid = visitors[i].getAttribute("franchise_id");
   var timestamp = visitors[i].getAttribute("timestamp");
   habVisitorList[fid] = timestamp;
  }
}

function updateVisitors (visitorsXML) {
  var visitors = visitorsXML.getElementsByTagName("visit");
  for (var i = 0; i < visitors.length; i++) {
   var fid = visitors[i].getAttribute("franchise_id");
   var timestamp = visitors[i].getAttribute("timestamp");
   if(habVisitorList[fid]==undefined) habVisitorList[fid]==0;
   if(timestamp!=habVisitorList[fid]) popNewVisitor(fid);
  }
}

function visitorCountdownTimer() {
  var timer;
  if(habVisitorCounter<habVisitorTimer){
   habVisitorCounter++;
   timer=setTimeout("visitorCountdownTimer()",1000);
  } else {
   habVisitorCounter=0;
   readHabVisitors('updateVisitors');
   timer=setTimeout("visitorCountdownTimer()",1000);
  }
}

readHabVisitors('initialVisitors');
getHabVisitorSound();
visitorCountdownTimer();