var hideTimer=120;function showPoll(refObj)
{ofset=0;hideTimer=120;pollObj=document.getElementById("pollWrapper");vertOfst=(pollObj.clientHeight/2)-(refObj.clientHeight/2);if(refObj.offsetParent)
{curleft=refObj.offsetLeft;curtop=refObj.offsetTop;while(refObj=refObj.offsetParent)
{curleft+=refObj.offsetLeft;curtop+=refObj.offsetTop;}}
if(navigator.userAgent.search("Firefox")>-1)
pollObj.style.left=curleft-ofset+"px";else
pollObj.style.left=curleft-ofset-3+"px";pollObj.style.top=curtop-vertOfst+"px";if(document.getElementById("pollTopImg")!=null)
{d=document.getElementById("pollTopImg");olddiv=d.parentNode;olddiv.removeChild(d);}
pollObj.style.visibility="visible";pollObj.onmouseover=function(){hideTimer=120;};if(document.getElementById("pollInner"))
{polLnks=document.getElementById("pollInner").getElementsByTagName("a");for(tmpLnk=0;tmpLnk<polLnks.length;tmpLnk++)
polLnks[tmpLnk].onclick=function(){hidePoll(true)}}}
function hidePoll(flag)
{if(hideTimer<1||flag==true)
{document.getElementById("pollWrapper").style.visibility="hidden";}
else
{hideTimer--;setTimeout("hidePoll()",1000);}}
LeadFlipDelay=8;CurLead=1;Delay=LeadFlipDelay;
function flipLead(LeadNum)
{if(LeadNum>4)
LeadNum=1;if(LeadNum!=CurLead)
{for(tmpx=1;tmpx<5;tmpx++)
{document.getElementById("LeadNavBox"+tmpx).className="HomeLeadNavBox";document.getElementById("NavArrow"+tmpx).src="/images/x.gif";document.getElementById("homeLead"+tmpx).style.display="none";}
document.getElementById("LeadNavBox"+LeadNum).className="HomeLeadNavBoxSel";document.getElementById("NavArrow"+LeadNum).src="/images/homeNavArrow.gif";document.getElementById("homeLead"+LeadNum).style.display="block";CurLead=LeadNum;Delay=LeadFlipDelay;}}
function setupLeades()
{
  for(tmpx=1;tmpx<5;tmpx++)
  {
    addTrackingCode("homeLead"+tmpx);
    document.getElementById("LeadNavBox"+tmpx).onclick=function(){flipLead(this.id.substr(this.id.length-1,1));};
  }
}

function autoFlipLead()
{if(Delay<=0)
flipLead(CurLead+1);else
Delay--;setTimeout("autoFlipLead()",1000);}
secBetween=3;step=0;time=0;tickPause=false;newsItems=new Array();showTicker=false;


function moveNews(tmpNewsItem)
{
  step-=1;
  tmpNewsItem.style.top=step+"px";
  tmpNewsItem.style.height = (tmpNewsItem.clientHeight+1)+"px";
  time=time/1.6;
  if(step>0)
    setTimeout("moveNews(newsDiv)",time);
  else
    setTimeout("hideNews()",secBetween*1000);}

function hideNews()
{
  if(!tickPause)
  {
    newsDiv.style.top=newsCont.clientHeight+"px";
    newsDiv.style.height="0px";
    setTimeout("newsNext()",10);
  }
  else
    setTimeout("hideNews()",10);}

function newsNext()
{
  step=newsCont.clientHeight;
  time=135;
  newsDiv.style.top=step+"px";
  curInner=newsItems.shift();
  newsItems.push(curInner);
  newsDiv.innerHTML=curInner;
  moveNews(newsDiv);
}
function startNews()
{
  //adds tracking links to the news ticker
  newsTracking();
  newsCont=document.getElementById("newsArea");
  newsDiv=document.createElement("div");
  newsDiv.id="news1";
  newsDiv.style.position="relative";
  newsDiv.style.height=document.getElementById("newsArea").style.height;
  newsDiv.style.width=document.getElementById("newsArea").style.width;
  newsDiv.style.verticalAlign="bottom";
  newsDiv.style.overflow="hidden";
  newsDiv.onmouseover=function(){tickPause=true;};
  newsDiv.onmouseout=function(){tickPause=false;};
  newsCont.appendChild(newsDiv);
  newsNext();
}


function showFeaturedPost()
{
  allDiv = document.getElementById("featuredBlogs").getElementsByTagName("div");
  allPost = new Array();
      
  for (tmpD=0;tmpD<allDiv.length;tmpD++)
    if (allDiv[tmpD].className == "blogEntry")
      allPost.push(allDiv[tmpD]);
          
  allPost[Math.floor(Math.random()*allPost.length)].style.display = "block";
}


vidMax = 3;
function moveVideosUp()
{
  if (vidMax >= 3)
    document.getElementById("vidScrollLeft").style.visibility = "visible";
  if (vidMax < 6)
  {
      vidMax++;
      document.getElementById("vidLink"+(vidMax-3)).style.display = "none";
      document.getElementById("vidLink"+vidMax).style.display = "block";
  }
  if (vidMax >= 6)
    document.getElementById("vidScrollRight").style.visibility = "hidden";
}

function moveVideosDown()
{
  if (vidMax <= 6)
    document.getElementById("vidScrollRight").style.visibility = "visible";
  if (vidMax > 3)
  {
      document.getElementById("vidLink"+(vidMax-3)).style.display = "block";
      document.getElementById("vidLink"+vidMax).style.display = "none";
      vidMax--;
  }
  if (vidMax <= 3)
    document.getElementById("vidScrollLeft").style.visibility = "hidden";
}


//for homepage tracking
areaName = new Array();
areaApnd = new Array();

areaName["findArea"] = "HOMETOPLINK";
areaName["homeLead1"] = "HOMELEAD1";
areaName["homeLead2"] = "HOMELEAD2";
areaName["homeLead3"] = "HOMELEAD3";
areaName["homeLead4"] = "HOMELEAD4";
areaName["blogArea"] = "HOMEBLOGS";
areaName["communityArea"] = "HOMECOMMUNITY";
areaName["videoOfTheDay"] = "HOMEVIDEO";
areaName["photoOfTheDay"] = "HOMEPHOTO";
areaName["dailyServing"] = "HOMESERVING";
areaName["recentFeatures"] = "HOMERECFEATURE";
areaName["dailyOfferings"] = "HOMEOFFERINGS";
areaName["pollArea"] = "HOMEPOLL";
areaName["beliefnetInterview"] = "HOMEINTERVIEW";
areaName["entertainmentBox"] = "HOMEENTERTAINMENT";
areaName["quizBox"] = "HOMEQUIZ";
areaName["ecardsBox"] = "HOMEECARD";
areaName["soulmatchBox"] = "HOMESOULMATCH";
areaName["promoBox"] = "HOMEPROBOX";
areaName["headerArea"] = "HOMETOPNAV";
areaName["BottomNav"] = "HOMEFOOTER";
areaName["Footer"] = "HOMEFOOTER";

//creates the URL with new properties attached to it
function appendToURL(origURL, appndStr)
{
  rtnURL = origURL;

  //if the url already contains a tracking link or is a javascript call, do nothing 
  if (origURL.search(/WT\.mc_id/) < 0 && origURL.search(/javascript:/i) < 0)
  {
    if (origURL.search(/\?/)>-1)
      preStr = "&";
    else
      preStr = "?";

    //if orig URL contains a #link append tracking link before the #
    if (origURL.search(/#/) < 0)
      rtnURL += preStr + "WT.mc_id=" + appndStr;
    else
      rtnURL =  rtnURL.replace("#",preStr + "WT.mc_id=" + appndStr+"#");
  }
  return rtnURL;
}

//changes links in spicific areas
function areaAppend(area,track)
{
//uncomment to enable tracking on the homepage
//  allLnk = document.getElementById(area).getElementsByTagName("a");
  
//  for (tmpLnk=0;tmpLnk<allLnk.length;tmpLnk++)
//    allLnk[tmpLnk].href = appendToURL(allLnk[tmpLnk].href,track);
}

//tracks exceptions
function trackDiscussions()
{
  allLnk = document.getElementById("findArea").getElementsByTagName("a")
  
  for (tmpLnk=0;tmpLnk<allLnk.length;tmpLnk++)
    if (allLnk[tmpLnk].innerHTML.search("Discussions")>-1)
      allLnk[tmpLnk].href = appendToURL(allLnk[tmpLnk].href,"HOMEDISCLINK ");
}

//adds tracking to the news ticker
function newsTracking()
{
//uncomment the code below to enable tracking
/*  for (tmpNwI=0;tmpNwI<newsItems.length;tmpNwI++)
  {
    if ( (newsItems[tmpNwI].search(/\?/) > -1) && (newsItems[tmpNwI].search(/\?/) < newsItems[tmpNwI].search("\">")) )
      newsItems[tmpNwI] = newsItems[tmpNwI].replace("\">","&WT.mc_id=HOMENWSTICK\">");
    else
      newsItems[tmpNwI] = newsItems[tmpNwI].replace("\">","?WT.mc_id=HOMENWSTICK\">");
  }
*/
}

//adds tracking code to the homepage
function addTrackingCode(trkArea)
{
  if (trkArea && (areaName[trkArea] != null) && (document.getElementById(trkArea) != null))
    areaAppend(trkArea,areaName[trkArea]);
  else
    for (tmpArea in areaName)
      areaAppend(tmpArea,areaName[tmpArea]);
}




//functions to run when the homepage is loaded
function loadPage()
{
  //starts the ticker if necessary
  if (showTicker)
    startNews();
    
  autoFlipLead();
}
