jQuery(document).ready(function(){
  jQuery('.dynamic_image_extension_hover').each(function(){
    
   	var myTimer = {};
    if (jQuery(this).parent().attr('id') == 'corporate-publishing') {
		    jQuery(this).oneTime(1, function(){
			   doAnimation(this);
			   //alert("this is numba one");
			  });
    }
		if (jQuery(this).parent().attr('id') == 'print') {
		    jQuery(this).oneTime(500, function(){
			   doAnimation(this);
				 //alert("this is numba two");
			  });
    }
  });
});

function doAnimation(element){
  if (jQuery.cookie('intro') == null || jQuery.cookie('intro').indexOf(jQuery(element).parent().attr('id')) < 0) {
    var bgTop = 0; 
    var frames = 18; 
    var frameSize = 90;

    jQuery(this).everyTime(90, function(){ 
      jQuery(element).css('background-position', '0 ' + (bgTop - frameSize) + 'px');
      bgTop -= frameSize;
      //console.log('bgTop: '+bgTop+' -> '+this);     
    }, frames);
    jQuery(element).mouseover(function(){
      var tmp = bgTop/2 - frameSize;
      // console.log('bgTop: '+tmp);
      jQuery(element).css('background-position', '0 ' + tmp + 'px');
      // console.log('bgTop'+bgTop);
    });
    jQuery(element).mouseout(function(){
      jQuery(element).css('background-position', '0 ' + bgTop + 'px');
    });
    jQuery.cookie('intro', jQuery.cookie('intro') + " " + jQuery(element).parent().attr('id'));
  }	
}

