var Infographic = {

  timers: [],

  load: function()
  {
    this.infoPops();
  },
  
  
  checkParents: function(element,attachment)
  {
    if(element.className.indexOf(attachment) !== -1)
    {
      return true;
    }
    
    if(typeof(element.offsetParent) !== 'undefined' && element.offsetParent)
    {
      return this.checkParents(element.offsetParent,attachment);
    }
    
    return false;
  },
  
  
  infoPops: function()
  {
    var self = this;
  
    $('.infoPopSticky').each(function(){
      var attachment = $(this).attr('rel');
      var pop = $(this);
    
      
      //$('.'+attachment+', .infoPop'+attachment+', .'+attachment+'Cover').bind('mouseenter mouseleave',function(e){     
      /*
      $('.'+attachment+', .infoPop'+attachment).bind('mouseover mouseout',function(e){  
      
        if(e.type == 'mouseover')
        {
          var id = attachment;
          pop.show();
          
          self.timers[id] = setTimeout( function() {
            $('.cover:not([class~='+attachment+'Cover])').animate({
              opacity:0.25
            },500);
            self.timers[id] = "";
          }, 100 );
        }
        else
        {
          //console.log(e);
          //if(e.toElement.className.indexOf(attachment) !== -1)
          //{
          //  return;
          //}
          //else(self.checkOffsetParent(e.toElement.offsetParent,attachment))
          //{
          //  return;
          //}
          
          //if(self.checkParents(e.toElement,attachment))
          //{
          //  return;
          //}
          
          pop.hide();
            
          var id = attachment;
          if ( self.timers[id] != "" ) {
            clearTimeout( self.timers[id] );
          } else {
            $('.cover').animate({
              opacity:1
            },200);
          }
        }
        
      } );
      */
      
      
      /*
      $('.'+attachment).hover(
      
        function()
        {
          var id = attachment;
          pop.show();
          
          self.timers[id] = setTimeout( function() {
            $('.cover:not([class~='+attachment+'Cover])').animate({
              opacity:0.25
            },500);
            self.timers[id] = "";
          }, 100 );
        },
        
        function(e)
        {
          if(e.toElement.className.indexOf(attachment) !== -1)
          {
            return;
          }
          
          pop.hide();
            
          var id = attachment;
          if ( self.timers[id] != "" ) {
            clearTimeout( self.timers[id] );
          } else {
            $('.cover').animate({
              opacity:1
            },200);
          }
        }
        
      );
      */
      
    
      /*
      $('.'+attachment+', .infoPop'+attachment+', .'+attachment+'Cover').hover(
        function () {
          var id = jQuery.data( this );
          
          self.timers[id] = setTimeout( function() {
            $('.cover:not([class~='+attachment+'Cover])').animate({
              opacity:0.25
            },500);
            pop.show();
            self.timers[id] = "";
          }, 100 );
        },
        function () {
          var id = jQuery.data( this );
          if ( self.timers[id] != "" ) {
            clearTimeout( self.timers[id] );
          } else {
            $('.cover').animate({
              opacity:1
            },200);
            pop.hide();
          }
        }
      );
      */
    
      
      $('.'+attachment+', .infoPop'+attachment+', .'+attachment+'Cover').bind('mouseover mouseout',function(e){      
        if(e.type == 'mouseover')
        {
          pop.show();
        }
        else
        {
          pop.hide();
        }
      });
      
      
      
    });
  }

}


$(document).ready(function(){

  Infographic.load();

});

