/* CONFIG BLOCK FOR POP-UP SUPPRESSION
  TO DISABLE POP_UPS, UNCOMMENT THE FOLLOWING TWO LINES
*/
//var noArrivalPopFlag = true; // Disables entering pops.
//var noExitingPopFlag = true; // Disables exiting pops.


// import the ELIS class, which calls its exec method once loaded
document.writeln('<scr'+'ipt src="/js/elis.js"></scr'+'ipt>');

// Set up the MagNet namespace. All future JS objects, vars, functions should live here
var MAGNET = {};

// Pass in a query string variable and it returns the value.
function queryString(keyName) {
    var keyValue = "";
    keyName = keyName.toUpperCase() + "=";

    var queryString = location.search;
    if (location.search.indexOf("?") != -1) {
        queryString = location.search.substring(1, queryString.length);
        var searchString = queryString.toUpperCase();
        if (searchString.indexOf(keyName) != -1) {
            var keyValueStart = parseInt(searchString.indexOf(keyName)) + keyName.length;
            var keyValueEnd = searchString.indexOf("&", keyValueStart);
            var keyValueEnd = (keyValueEnd != -1) ? keyValueEnd : searchString.length;
            keyValue = queryString.substring(keyValueStart,keyValueEnd);
        }

        var plusPos = keyValue.indexOf('+');
        while (plusPos != -1) {
            keyValue = keyValue.substring(0, plusPos) + " " + keyValue.substring(plusPos + 1, keyValue.length);
            plusPos = keyValue.indexOf('+');
        }
    }

    return unescape(keyValue);
}



/* Window onload functions go here. */
function loadEvents() {
  SI.ClearChildren.initialize();

  // Suppress popups when mbid exists in the
  // query string.
  if (queryString("mbid") == "") {
    SubscriptionPopups.arrival();
    SubscriptionPopups.exiting();
  } else {
    // Not really needed, but just in case somewhere else someone
    // tries to turn on the popups.
    noExitingPop = noArrivalPopFlag = true;
  }
  //subscriptions.assign();
  if (typeof(feedmanager) !='undefined' && document.getElementsByTagName('body')[0].className.indexOf('ss_blogs')==-1) { feedmanager.assign(); } // don't assign feeds on pages without feeds.

}

/* Window onunload functions go here.
 * Make sure you pass the event object (e) to the handler object's method, otherwise
 * Firefox won't see the event object.
 */
function unloadEvents(e) {
  SubscriptionPopups.checkExiting(e); // checks changes in address
}

/* Document click functions go here.
 * Same deal as above. Make sure to pass event object to hander object's method.
 */
function clickEvents(e) {
  SubscriptionPopups.checkExiting(e); /* checks clicks */
}

/* toggle visibility of a an element.
 * Pass in the div id and it toggles the display from visible to not visible.
 */
function toggle( targetId ){
  if (document.getElementById){
    target = document.getElementById( targetId );
    if (target.style.display == "none"){
      target.style.display = "";
    } else {
      target.style.display = "none";
    }
  }
}

/* draw copyright text in the footer */
function drawFooterCopyright(divId) {
var mydate=new Date();
var year=mydate.getYear();
if (year < 1000) year+=1900;
document.getElementById(divId).innerHTML = "Copyright &copy; "+year+" Cond&#233; Nast. All rights reserved.<br/>";
}

/* Calls to event manager to attach functions to events. */
addEvent(window, "load", loadEvents);
addEvent(window, "unload", unloadEvents);

// Would like to use event manager for this, but when using onclick to pop windows,
// it will still follow the href.
//addEvent(document, "click", clickEvents);
document.onclick=clickEvents;

// For Pluck
try {
  var pluckUser = new Cookie("at");
}
catch (ex) {
  var pluckUser = null;
  }




/* COOKIE-126: START Update cookiemag.com for pushdown ad unit ad call
 *
 * This script will check if no ad is being served and hide
 * the container div if that is the case. The original author
 * of this script is Eric Hamilton.
 */
function detectPushdownAd()
{
   if( document.getElementById('topBannerPushdownAd') )
   {
      var pushDownAd       = document.getElementById('topBannerPushdownAd');
      var pushDownAdHeight = pushDownAd.offsetHeight;

      if( pushDownAdHeight <= 60 )
      {
         pushDownAd.style.display = "none";
      }
   }
}
/* COOKIE-126: END*/
