//YAHOO.realtruth.EmailArticle
(function(){

  var Dom = YAHOO.util.Dom,
      Event = YAHOO.util.Event,
      Overlay = YAHOO.widget.Overlay;

  var rtEmailArticle = function(element)
  {
    this._button = element;
    this.init();
  };

  rtEmailArticle.prototype = {

    _button: null,
    _overlay: null,
    _overlay_config: { fixedcenter: "contained",
                       width: "685px", // 600 + 30 + 30 padding, + ~20 scroll bar + 2 border
                       height: '400px' },

    init: function()
    {
      // make sure we have a px height configed
      this._overlay_config.height = this.getHeightForWindow();

      // apply click event to the element
      Event.addListener(this._button, 'click', this.onEmailClick, null, this);
    },

    getHeightForWindow: function()
    {
      // at the time of this comment, 85% height
      return (Dom.getViewportHeight() * 0.85) + 'px';
    },

    onEmailClick: function(event, args)
    {
      Event.preventDefault(event);
      this._overlay = new Overlay(Dom.generateId(), this._overlay_config);
      Dom.addClass(this._overlay.element, 'emailArticleIframeWrapper');
      Dom.setStyle(this._overlay.element, 'display', 'block');
      Dom.setStyle(this._overlay.element, 'position', 'absolute');

      Dom.addClass(this._overlay.body, 'emailArticleWindowBody');

      this._overlay.setHeader('')
      this._overlay.setBody('');
      this._overlay.setFooter('');
      this._overlay.render(document.body);
      this._overlay.bringToTop();
      this._overlay.cfg.setProperty('zindex', 999);
      Dom.setStyle(this._overlay.element, 'overflow', 'hidden');

      var closebtn = document.createElement('a');
      closebtn.href="#";
      Dom.addClass(closebtn, 'closeVerse');
      Dom.addClass(closebtn, 'close');
      Dom.setStyle(closebtn, 'zindex', 1001);
      this._overlay.body.appendChild(closebtn);
      Event.addListener(closebtn, 'click', this.onCloseButtonClick, null, this);

      var iframe = document.createElement('iframe');
      Dom.setStyle(iframe, 'width', '100%');
      Dom.setStyle(iframe, 'height', '100%');
      Dom.setStyle(iframe, 'border', 'none');
      Dom.setStyle(iframe, 'zindex', 1000);
      Dom.setStyle(iframe, 'background', '#ffffff');
      //Dom.setStyle(iframe, 'overflow', 'scroll');
      iframe.src = Event.getTarget(event).href;
      this._overlay.body.appendChild(iframe);

      // set the look feel here for the close button
      Dom.setStyle(closebtn, 'right', '23px');
      // for ie
      if(YAHOO.env.ua.ie > 0) {
        Dom.setStyle(closebtn, 'right', '28px');
        Dom.setStyle(closebtn, 'top', '10px');
      }
    },

    onCloseButtonClick: function(event, args)
    {
      Event.preventDefault(event);
      this._overlay.destroy();
    }

  }

  YAHOO.namespace('realtruth.EmailArticle');
  YAHOO.realtruth.EmailArticle = rtEmailArticle

})();

// YAHOO.realtruth.ExternalLink
(function(){

  var Dom = YAHOO.util.Dom;

  var rtExternalLink = function(a_link_element)
  {
    this._link = a_link_element;
    this.init();
  }

  rtExternalLink.prototype = {

    _link:null,
    _external_target: "_blank",
    _external_class: "boxArrow",
    _hostname:null,

    init: function()
    {
      this._hostname = window.location.hostname;
      this._hostname = this._hostname.replace("www.","").toLowerCase();

      // is the link external?
      if(this.isLinkExternal()) {
        // if so, add the class and make it external
        this.makeLinkExternal();
      }
    },

    makeLinkExternal: function()
    {
      this._link.target = this._external_target;
      Dom.addClass(this._link, this._external_class);
    },

    isLinkExternal: function()
    {
      var href = this._link.href.toLowerCase();
      return (href.indexOf("http://")!=-1 && href.indexOf(this._hostname)==-1) ? true : false;
    }

  }

  YAHOO.namespace('realtruth.ExternalLink');
  YAHOO.realtruth.ExternalLink = rtExternalLink;

})();

// YAHOO.realtruth.ImagePopup
(function(){

  var Dom = YAHOO.util.Dom,
      Event = YAHOO.util.Event,
      Overlay = YAHOO.widget.Overlay,
      Lang = YAHOO.lang;

  var rtImagePopup = function(element)
  {
    this._button = element;
    this.init();
  };

  rtImagePopup.prototype = {

    _link: null,
    _button: null,
    _overlay: null,
    _image_src: null,
    _overlay_config: { fixedcenter: "contained", constraintoviewport: true },

    init: function()
    {
      // get the url to the image
      this._link = this._button;
      this._image_src = this._button.href;

      // apply click event to the element
      Event.addListener(this._button, 'click', this.onImageClick, null, this);

      // if there is an image tag in the same div as the link, apply the click event's to the images as well for the popup
      var images = Dom.getChildrenBy(this._button.parentNode, this.isElementAnImage);
      for(var i in images) {
        Dom.setStyle(images[i], 'cursor', 'pointer');
        Dom.addClass(images[i], 'clickableImage');
        Event.addListener(images[i], 'click', this.onImageClick, null, this);
      }
    },

    isElementAnImage: function(element)
    {
      return element.tagName.toLowerCase() == 'img';
    },

    onImageClick: function(event, args)
    {
      Event.preventDefault(event);

      // get the caption elements, up to 3 lines here (could maybe just loop in a function, but rushing so...
      var text_1, text_2, text_3;
      text_1 = Dom.getNextSibling(this._link);
      if(Lang.isObject(text_1)) text_2 = Dom.getNextSibling(text_1);
      if(Lang.isObject(text_2)) text_3 = Dom.getNextSibling(text_2);

      //var img_tag = document.createElement('img');
      var img_tag = new Image();
      img_tag.src = this._image_src;

      this._overlay = new Overlay(Dom.generateId(), this._overlay_config);

      Dom.addClass(this._overlay.element, 'imageComponent_small');
      Dom.addClass(this._overlay.element, 'imagePopup');
      Dom.setStyle(this._overlay.element, 'opacity', 0);
      Dom.setStyle(this._overlay.element, 'display', 'block');

      this._overlay.setHeader('')
      this._overlay.setBody('');
      this._overlay.setFooter('');
      this._overlay.render(document.body);
      this._overlay.bringToTop();
      this._overlay.cfg.setProperty('zindex', 999);
      Dom.setStyle(this._overlay.element, 'overflow', 'hidden');

      var closebtn = document.createElement('a');
      closebtn.href="#";
      Dom.addClass(closebtn, 'smallerImage');
      Dom.addClass(closebtn, 'close');
      Dom.setStyle(closebtn, 'position', 'absolute');
      Dom.setStyle(closebtn, 'top', '13px');
      Dom.setStyle(closebtn, 'right', '13px');
      Dom.setStyle(closebtn, 'zindex', 1001);

      this._overlay.body.appendChild(closebtn);
      this._overlay.body.appendChild(img_tag)
      if(Lang.isObject(text_1)) this._overlay.body.appendChild(text_1.cloneNode(true));
      if(Lang.isObject(text_2)) this._overlay.body.appendChild(text_2.cloneNode(true));
      if(Lang.isObject(text_3)) this._overlay.body.appendChild(text_3.cloneNode(true));

      // center the overlay after the image has been reloaded.
      Event.addListener(img_tag, 'load', function(a,b,c){

        // get the width of the image, and set the class=bd item to be the same width
        var region = Dom.getRegion(img_tag);
        Dom.setStyle(this._overlay.body, 'width', region.width + 'px');

        this._overlay.center();
        this._overlay.forceContainerRedraw();
        Dom.setStyle(this._overlay.element, 'opacity', 1);
      }, null, this)

      this._overlay.center();
      this._overlay.forceContainerRedraw();


      // add listener to the actual link to close, and also to the image tag
      Event.addListener(img_tag, 'click', this.onCloseButtonClick, null, this);
      Event.addListener(closebtn, 'click', this.onCloseButtonClick, null, this);


    },

    onCloseButtonClick: function(event, args)
    {
      Event.preventDefault(event);
      this._overlay.destroy();
	  $(".yui-overlay").remove(); // A little jQuery fun to kill any remaining overlays. -JDD	  
    }

  }

  YAHOO.namespace('realtruth.ImagePopup');
  YAHOO.realtruth.ImagePopup = rtImagePopup

})();

// YAHOO.realtruth.Magnifier
(function(){

  var Dom = YAHOO.util.Dom,
      Event = YAHOO.util.Event,
      Cookie = YAHOO.util.Cookie,
      Lang = YAHOO.lang;

  /**
   * functionality for the jQuery magnifier
   * @param {HTMLElement} element
   */
  var rtMagnifier = function(element, increase_trigger, decrease_trigger)
  {
    this._target_element = element;
    this._increase_trigger = increase_trigger;
    this._decrease_trigger = decrease_trigger;
    this.init();
  };
  rtMagnifier.prototype = {

    _cookie_name: 'rt_font_magnifier_size',
    _cookie_options: { path: '/' },
    _font_size: 100, // in %'s
    _font_step_size: 10, // in %'s
    _font_size_max: 130,
    _font_size_min: 70,
    _target_element: null,
    _increase_trigger: null,
    _decrease_trigger: null,

    /**
     * Set the _font_size from the value in a cookie, if no cookie was set, then set the
     * cookie with the value from the _target_element currently
     */
    init: function()
    {
      // set the default font size from the div or current cookie
      var cookie_val = this.getFontSizeFromCookie();
      if ( cookie_val == null || cookie_val.length <= 0 || !Lang.isNumber(cookie_val)) {
        this.setFontSizeAndCookie(this._font_size);
      } else {
        // just use the _font_size var as a default / base for %
        this.setFontSizeAndCookie(cookie_val);
      }

      // add listeners
      Event.addListener(this._increase_trigger, 'click', this.increaseFontSize, null, this );
      Event.addListener(this._decrease_trigger, 'click', this.decreaseFontSize, null, this );
    },

    setFontSizeAndCookie: function(font_size)
    {
      this._font_size = font_size;
      this.applyCurrentFontSize();
      Cookie.set(this._cookie_name, this._font_size, this._cookie_options);

    },

    getFontSizeFromCookie: function()
    {
      return Cookie.get(this._cookie_name);
    },

    increaseFontSize: function(event)
    {
      Event.preventDefault(event);
      var new_font_size = parseInt(this._font_size) + this._font_step_size;
      if( !this.doesNextSizeStepGoToFar(new_font_size) ) {
        this.setFontSizeAndCookie(new_font_size);
      }
    },

    decreaseFontSize: function(event)
    {
      Event.preventDefault(event);
      var new_font_size = parseInt(this._font_size) - this._font_step_size;
      if( !this.doesNextSizeStepGoToFar(new_font_size) ) {
        this.setFontSizeAndCookie(new_font_size);
      }
    },

    applyCurrentFontSize: function()
    {
      Dom.setStyle(this._target_element, 'font-size', parseInt(this._font_size) +'%');
    },

    doesNextSizeStepGoToFar: function(desired_font_size)
    {
      // just check to see if the next step would be greater or less than the max/min
      desired_font_size = parseInt(desired_font_size);
      return ( (desired_font_size > this._font_size_max) || (desired_font_size < this._font_size_min) );
    }
  };

  YAHOO.namespace('realtruth.Magnifier');
  YAHOO.realtruth.Magnifier = rtMagnifier;

})();

// YAHOO.realtruth.PagePopup
(function(){

  var Dom = YAHOO.util.Dom,
      Event = YAHOO.util.Event
      Overlay = YAHOO.widget.Overlay;

  var rtPagePopup = function(elements, search, replace)
  {
    this._popup_elements = elements;
    this._popup_search = search;
    this._popup_replace = replace;
    this.init();
  };

  rtPagePopup.prototype = {

    _popup_elements: null,
    _popup_search: null,
    _popup_replace: null,
    _overlay: null,
    _overlay_config: { fixedcenter: "contained",
                       width: "685px", // 600 + 30 + 30 padding, + ~20 scroll bar + 2 border
                       height: '400px' },

    init: function()
    {
      // make sure we have a px height configed
      this._overlay_config.height = this.getHeightForWindow();

      for ( i in this._popup_elements ) {
        // apply click event to the element
        Event.addListener(this._popup_elements[i], 'click', this.onPopupClick, {element:this._popup_elements[i]}, this);
      }
    },

    getHeightForWindow: function()
    {
      // at the time of this comment, 85% height
      return (Dom.getViewportHeight() * 0.85) + 'px';
    },

    onPopupClick: function(event, args)
    {
      Event.preventDefault(event);
      var url = args.element.href;
      if (this._popup_search) {
        url = url.replace(this._popup_search, this._popup_replace);
      }

      Event.preventDefault(event);
      this._overlay = new Overlay(Dom.generateId(), this._overlay_config);
      Dom.addClass(this._overlay.element, 'pagePopupIframeWrapper');
      Dom.setStyle(this._overlay.element, 'display', 'block');
      Dom.setStyle(this._overlay.element, 'position', 'absolute');

      Dom.addClass(this._overlay.body, 'pagePopupWindowBody');

      this._overlay.setHeader('')
      this._overlay.setBody('');
      this._overlay.setFooter('');
      this._overlay.render(document.body);
      this._overlay.bringToTop();
      this._overlay.cfg.setProperty('zindex', 999);
      Dom.setStyle(this._overlay.element, 'overflow', 'hidden');

      var closebtn = document.createElement('a');
      closebtn.href="#";
      Dom.addClass(closebtn, 'closeVerse');
      Dom.addClass(closebtn, 'close');
      Dom.setStyle(closebtn, 'zindex', 1001);
      this._overlay.body.appendChild(closebtn);
      Event.addListener(closebtn, 'click', this.onCloseButtonClick, null, this);

      var iframe = document.createElement('iframe');
      Dom.setStyle(iframe, 'width', '100%');
      Dom.setStyle(iframe, 'height', '100%');
      Dom.setStyle(iframe, 'border', 'none');
      Dom.setStyle(iframe, 'zindex', 1000);
      Dom.setStyle(iframe, 'background', '#ffffff');
      //Dom.setStyle(iframe, 'overflow', 'scroll');
      iframe.src = unescape(url);
      this._overlay.body.appendChild(iframe);

      // set the look feel here for the close button
      Dom.setStyle(closebtn, 'right', '23px');
      // for ie
      if(YAHOO.env.ua.ie > 0) {
        Dom.setStyle(closebtn, 'right', '28px');
        Dom.setStyle(closebtn, 'top', '10px');
      }

      return false;
    },

    onCloseButtonClick: function(event, args)
    {
      Event.preventDefault(event);
      this._overlay.destroy();
    },

    /**
     * Get the url. If there is a get variable in use, then append a new get variable after a & char
     * to indicate we want the print version. Otherwise, add the ? along with the get var.
     */
    getUrlForNewWindow: function()
    {
      var url = window.location;
      // do we have a search query (get variables)
      if(url.search.length) {
        url = url.pathname + url.search;
      } else {
        url = url.pathname;
      }
      return url;
    }

  }

  YAHOO.namespace('realtruth.PagePopup');
  YAHOO.realtruth.PagePopup = rtPagePopup;

})();

// YAHOO.realtruth.PrintPage
(function(){

  var Dom = YAHOO.util.Dom,
      Event = YAHOO.util.Event;

  var rtPrintPage = function(element)
  {
    this._print_element = element;
    this.init();
  };

  rtPrintPage.prototype = {

    _print_page_get_var: 'print_view=yes',
    _print_element: null,
    _window_name: 'PrintPage',
    _window_attributes: 'width=800,height=500,resizable=yes,scrollbars=yes,location=no',

    init: function()
    {
      // apply click event to the element
      Event.addListener(this._print_element, 'click', this.onPrintClick, null, this);
    },

    onPrintClick: function(event, args)
    {
      Event.preventDefault(event);
      var url = this.getUrlForNewWindow();
      window.open(url, this._window_name, this._window_attributes);
    },

    /**
     * Get the url. If there is a get variable in use, then append a new get variable after a & char
     * to indicate we want the print version. Otherwise, add the ? along with the get var.
     */
    getUrlForNewWindow: function()
    {
      var url = window.location;
      // do we have a search query (get variables)
      if(url.search.length) {
        url = url.pathname + url.search + '&' + this._print_page_get_var;
      } else {
        url = url.pathname + '?' + this._print_page_get_var;
      }
      return url;
    }

  }

  YAHOO.namespace('realtruth.PrintPage');
  YAHOO.realtruth.PrintPage = rtPrintPage;

})();

// YAHOO.realtruth.Editor
(function(){

  var Dom = YAHOO.util.Dom,
      Event = YAHOO.util.Event,
      Editor = YAHOO.widget.Editor;

  var rtEditor = function()
  {
    this.init();
  }

  rtEditor.prototype = {

    init: function()
    {
    }
  }

  YAHOO.namespace('realtruth.Editor');
  YAHOO.realtruth.Editor = rtEditor;

})();

/**
 * Main goal of this file is to fix the tabindex of the forms in the site.
 * Currently, they are buggy, the yahoo simple editor and the recaptcha do not play nicely together.
 * (they do, but accessability tabindexs into the recaptcha fields do not need to be use i guess)
 *
 * As of the current writing of this object there is only ever one text area item in the form, and it is always
 * accompied by a recaptcha field.
 */
var focusTo = null;
var focusToTimeout = null;
var form_tabindex_fix = function(anEditor, last_el_id_before_textarea, element_after_textarea_el)
{
   var Event = YAHOO.util.Event,
       SimpleEditor = YAHOO.widget.SimpleEditor;

   // listen to the blur event of the last element (confirm email in this case) to focus the comment block next
   Event.addListener(last_el_id_before_textarea, 'keydown', function(event, anEditor) {
     // look for tab keyCode
     var keyCode = 0;
     try {
       keyCode = event.keyCode;
     } catch(err) {
       // do nothing, just catch the error
     }
     if(keyCode == 9) {
       focusTo = anEditor;
       focusToTimeout = setTimeout(function(){
         clearTimeout(focusToTimeout);
         focusTo.focus();
       }, 50);
     }
   }, anEditor);

   // add a listener to the tab button to move the focus to the captcha
   anEditor._handleKeyDown = function(keyDown) {
     // look for tab keyCode
     var keyCode = 0;
     try {
       keyCode = keyDown.keyCode;
     } catch(err) {
       // do nothing, just catch the error
     }
     if(keyCode == 9) {
       var recaptcha_el = document.getElementById(element_after_textarea_el);
       if(recaptcha_el) {
         focusToTimeout = 0;
         focusTo = recaptcha_el;
         clearTimeout(focusToTimeout);
         focusToTimeout = setTimeout(function(){
           clearTimeout(focusToTimeout);
           focusTo.focus();
         }, 50);
       }
     }
   }

   return anEditor;
}
var form_tabindex_skip = function(element_id_from, element_id_to)
{
   var Dom = YAHOO.util.Dom,
       Event = YAHOO.util.Event,
       SimpleEditor = YAHOO.widget.SimpleEditor;

   // listen to the blur event of the last element (confirm email in this case) to focus the comment block next
   Event.addListener(element_id_from, 'keydown', function(event) {
     // look for tab keyCode
     var keyCode = 0;
     try {
       keyCode = event.keyCode;
     } catch(err) {
       // do nothing, just catch the error
     }
     if(keyCode == 9) {
       focusFrom = Dom.get(element_id_from);
       focusTo = Dom.get(element_id_to);
       focusToTimeout = setTimeout(function(){
         clearTimeout(focusToTimeout);
         focusTo.focus();
       }, 5);
     }
   });
}

var link_ajax_cache = {};
(function(){

  var Dom = YAHOO.util.Dom,
      Event = YAHOO.util.Event,
      Connect = YAHOO.util.Connect;
      Lang = YAHOO.lang;
  var conn = false;
  var loading_el = false;
  var lists_more = [];

  // a funciton used to filter out the links in a getElementsBy call with the list as a root

  // prepare an object for the ajax functionality
  rtActivateAjaxPastItemsArchive = function(parent_el) {
    var links, url;
    var lists = Dom.getElementsByClassName('searchList', 'ul', parent_el);

    // make sure to get the links in the sortBy div as well
    lists_more = Dom.getElementsByClassName('sortBy', 'ul', parent_el);
    lists = lists.concat(lists_more);

    // also, there could be another
    lists_more = Dom.getElementsByClassName('sortByMedia', 'ul', parent_el);
    lists = lists.concat(lists_more);

      // loop through the list for links that are indeed links, and have href values
    for(var i in lists) {
      // get the links
      links = lists[i].getElementsByTagName('a');
      for(var j in links) {
        // if there is no href, count on this not being an actual a-link
        if(!Lang.isValue(links[j].href)) { continue; }

        if(Dom.hasClass(links[j], 'active')) {
          // TRY TO CACHE HERE ::: THIS MAY BREAK STUFF.
          // cache the current state / url
          // make it an ajax link. in this case, just the page name
          url = links[j].href;
          url = url.replace('.html', '_ajax.html');
          url = url.replace(/\=/g, '/');
          url = url.replace(/\&/g, '/');
          url = url.replace(/\?/g, '/');
          url = url.replace('#sortby', '');
          link_ajax_cache[url] = parent_el.innerHTML;
        }

        Event.addListener(links[j], 'click', function(evt, args){
          Event.preventDefault(evt);

          // don't make the call if we have one in process already
          if(conn !== false) { return; }

          // update and scroll to the 'waiting' message
          loading_el = document.createElement('div');
          loading_el.innerHTML = '<h3 class="ajax-loading-icon-heading"><span class="ajax-loading-icon">&nbsp;</span><span class="ajax-loading-text">Loading.</span></h3>';
          Dom.setStyle(loading_el, 'background', '#ccc');
          Dom.setStyle(loading_el, 'border', '1px solid #B5B5B5');
          Dom.setStyle(loading_el, 'position', 'absolute');
          Dom.setStyle(loading_el, 'opacity', 0.8);

          document.body.appendChild(loading_el);

          var parent_el_region = Dom.getRegion(parent_el);
          Dom.setStyle(loading_el, 'top', parent_el_region.y + 'px');
          // tweak, ie is off for some reason
          if(YAHOO.env.ua.ie > 0 && YAHOO.env.ua.ie < 7) {
            Dom.setStyle(loading_el, 'left', (parent_el_region.x-3) + 'px');
          } else {
            Dom.setStyle(loading_el, 'left', parent_el_region.x + 'px');
          }
          Dom.setStyle(loading_el, 'width', parent_el_region.width + 'px');
          Dom.setStyle(loading_el, 'height', parent_el_region.height + 'px');


          // make it an ajax link. in this case, just the page name
          url = this.href;
          url = url.replace('.html', '_ajax.html');
          url = url.replace(/\=/g, '/');
          url = url.replace(/\&/g, '/');
          url = url.replace(/\?/g, '/');

          // ie bugfix: the #sortbybreaks. the server must parse or respond to ie
          // different for some reason, because if this is here, php returns a different page
          url = url.replace('#sortby', '');

          // js caching, to make requests fast per real page request
          if(Lang.isValue(link_ajax_cache[url])) {
            // build a manual response and pass to the success
            var response = {};
            response.responseText = link_ajax_cache[url];
            response.argument = {};
            response.argument.parent_el = parent_el;
            response.argument.loading_el = loading_el;
            response.argument.cache_id = url;
            onArchiveClickSuccess(response);
            return;
          }

          // build the callback
          var callback = {
            success: onArchiveClickSuccess,
            failure: onArchiveClickFailure,
            argument: { 'parent_el':parent_el, 'loading_el':loading_el, 'cache_id':url }
          };

          // make the ajax call
          conn = Connect.asyncRequest('get', url, callback);

          // Remove scrolling to top of section per client request
          //var scroll_target = Dom.getFirstChild(parent_el);
          //if(scroll_target) {
          //  var scroll_target_region = Dom.getRegion(scroll_target);
          //  window.scroll(0,scroll_target_region.top - 10);
          //}
        });
      }
    }
  };

  onArchiveClickSuccess = function(response) {

    link_ajax_cache[response.argument.cache_id] = response.responseText;

    response.argument.parent_el.innerHTML = response.responseText;

    document.body.removeChild(loading_el);

    // reactivate the links
    rtActivateAjaxPastItemsArchive(response.argument.parent_el);

    // reactivate the ajax links
    conn = false;
  };

  onArchiveClickFailure = function(response) {

    // reactivate the ajax links
    document.body.removeChild(loading_el);

    conn = false;

  };

  // attach the functionality if the page exists.
  Event.onDOMReady(function(){
    // get our page element that will be hijaxed
    var dynamicRoot = Dom.getElementsByClassName('archiveResults', 'div', null, rtActivateAjaxPastItemsArchive);
  });

})();


//MAIN
(function(){

var Dom = YAHOO.util.Dom,
   Event = YAHOO.util.Event,
   Lang = YAHOO.lang,
   Magnifier = YAHOO.realtruth.Magnifier,
   PrintPage = YAHOO.realtruth.PrintPage,
   EmailArticle = YAHOO.realtruth.EmailArticle,
   ImagePopup = YAHOO.realtruth.ImagePopup,
   PagePopup = YAHOO.realtruth.PagePopup;

Event.onDOMReady(function(){

 var rt_content = Dom.getElementsByClassName('mainContent').pop();
 var rt_control = Dom.getElementsByClassName('tools', 'dl').pop();

 // init objects functionality for text resize tool
 var rt_mag_control_increase = Dom.getElementsByClassName('textIncrease', null, rt_control).pop();
 var rt_mag_control_decrease = Dom.getElementsByClassName('textDecrease', null, rt_control).pop();
 var rt_mag = new Magnifier(rt_content, rt_mag_control_increase, rt_mag_control_decrease);

 // init the print page functionality
 var rt_print_control = Dom.getElementsByClassName('print', null, rt_control).pop();
 if(rt_print_control) {
   var rt_print = new PrintPage(rt_print_control);
 }

 // init the email page functionality
// var rt_email_control = Dom.getElementsByClassName('email', null, rt_control).pop();
// if(rt_email_control) {
//   var rt_email = new EmailArticle(rt_email_control);
// }

 // get the image popups
 var rt_popups1 = Dom.getElementsByClassName('biggerImage', 'a', rt_control);
 var rt_popups2 = Dom.getElementsByClassName('imagePopup', 'a', rt_control);
 var rt_popups = Lang.merge(rt_popups1, rt_popups2);
 var rt_popup = null;

 for(var i in rt_popups) {
   rt_popup = new ImagePopup(rt_popups[i]);
 }

 // init the help/privacy page functionality
 var rt_help_links = Dom.getElementsByClassName('helpPopup');
 if(rt_help_links) {
   var rt_help_popup = new PagePopup(rt_help_links, /help.html/, 'help_popup.html?linkfix=yes');
 }
 var rt_privacy_links = Dom.getElementsByClassName('privacyPopup');
 if(rt_privacy_links) {
   var rt_privacy_popup = new PagePopup(rt_privacy_links, /privacy.html/, 'privacy_popup.html?linkfix=yes');
 }
});
})();
