function TrackingManager(root_agof_code, root_nav_id, root_article_id, root_ivw_add)
{
  this.placeTracker = function()
  {
    var a = $$('.track_me');
    for(var i = 0; i < a.length; i++)
    {
      a[i].removeClassName('track_me');
      // observe clicks and watch for classname track_code_<code>
      // This <code> will be passed to count. <code> defaults to ''
      Element.observe(a[i], 'click', function ()
      {
        var e = $w(this.className);
        var ivw_add = '';
        for(var j = 0; j < e.length; j++)
        {
          if(e[j].substr(0,11) == 'track_code_')
          {
            ivw_add = e[j].substring(11);
          }
        }
        trackingManager.count(ivw_add);
      });
    }
  },
  
  this.init =  function()
  {
    // check clickable elements in DOM
    Event.observe(window, 'load', function() {
      trackingManager.placeTracker();
    });
  },

  // UmlautConversion for sitecatalyst
  this.deleteUmlaute = function (curText) {
   if (curText == "") 
   {
     return "";
   }
   var result = curText;

   result=result.replace(/ü/g, "ue");
   result=result.replace(/ö/g, "oe");
   result=result.replace(/ä/g, "ae");
   result=result.replace(/Ü/g, "Ue");
   result=result.replace(/Ö/g, "Oe");
   result=result.replace(/Ä/g, "Ae");
   result=result.replace(/ß/g, "ss");

   regExp = new RegExp("[\"]","g");
   result=result.replace(regExp,"");

   return result;
  },

  this.count = function(ivw_add, agof_code, nav_id, article_id, noivw)
  {
    // if no overriding value is passed to the method
    // we use the basic value that was used to initialize the tracking manager on this page
    nav_id      = (nav_id == null)      ? root_nav_id     : nav_id;
    agof_code   = (agof_code == null)   ? root_agof_code  : agof_code;
    ivw_add     = (ivw_add == null)     ? root_ivw_add    : ivw_add;
    article_id  = (article_id == null)  ? root_article_id : article_id;
    
    // on the current page we replace the src of the ivw-image to retrigger the counting ...
    if (document.images['ivw'] || parent.document.images['ivw'])
    {
      
      // IVW - usually we have one static navid for the ivw-counting
      // Special case I: autostarted Videos, than we dont trigger IVW (noivw)
      // Special case II: parent is used for videos in iframe
      if(noivw != 1)
      {
        ivwPixelPath = 'http://stern.ivwbox.de/cgi-bin/ivw/CP/' + agof_code + ';' + nav_id + ',' + article_id + ',JS_' + ivw_add + ',?p='+(Math.random()*100000);
        if (document.images['ivw'])
        {
          document.images['ivw'].src = ivwPixelPath;
        } 
        else if ( parent.document.images["ivw"] )
        {
          parent.document.images['ivw'].src = ivwPixelPath;
        }
      }

      // STAT-Pixel - the selfmade GuJ tracking
      // for historic reasons, we use virtual navids here to simulate the teamsite-content-hierarchy
      if($('stat') != null)
      {
        statPixelPath = '?c=' + nav_id +  ',' + article_id + ',JS_' + ivw_add +',&amp;p='+(Math.random()*100000);
        $('stat').src = statPixelPath;
      }

      // sitecatalyst and googleAnalytics
      iww_add = this.deleteUmlaute(ivw_add);
      // check, if ajax-call
      if (Ajax.activeRequestCount)
      {
        ivw_add = 'Ajax,' + ivw_add;
      }

      // sitecatalyst
      if(typeof s == 'object')
      {
        savehier = s.hier1;
        s.hier1= s.hier1 + ",Ajax," + iww_add;
        void(s.t());
        s.hier1 = savehier; 
      } 
      else if (typeof parent.s == 'object')
      {
        savehier = parent.s.hier1;
        parent.s.hier1= parent.s.hier1 + ",Ajax," + iww_add;
        void(parent.s.t());
        parent.s.hier1 = savehier; 
      }

      // googleAnalytics
      if((typeof pageTracker != 'undefined') && (pageTracker != null))
      {
        pageTracker._trackEvent('TrackingManager',iww_add);
      } 
      else if ((typeof parent.pageTracker != 'undefined') && (parent.pageTracker != null))
      {
        parent.pageTracker._trackEvent('TrackingManager',iww_add);
      }

      // debugBar
      if(typeof DebugBar == 'object')
      {
        DebugBar.addStatistics(ivw_add, agof_code, nav_id, article_id);
      } 
      else if (parent.DebugBar != null && typeof parent.DebugBar == 'object')
      {
        parent.DebugBar.addStatistics(ivw_add, agof_code, nav_id, article_id);
      }
    }
  };
}

function gujTrackingPixelReloader()
{
  this.reload = function(eventType)
  {
    if (Object.isArray(eventType) && eventType.length > 0)
    {
      // To be filled later
    }
    else if (Object.isString(eventType) && !eventType.empty())
    {
      trackingManager.count(eventType);
    }
    else
    {
      trackingManager.count();
    }
  }
}
