var videoset = function() {

  var min;
  var max;
  var cur;
  var timeout_id;
  var idIm;
  var speed;
  var needReturnSrc = false;
  var img_cache = new Object();

  var f1 = function()
  {
    el = document.getElementById(idIm);
    imlist = el.getAttribute('hoversrcvideoset');
    tmp = imlist.split(';');
    max = tmp.length-1;
    cur++;
    if (cur>max) { cur = min; }
    el.src=tmp[cur];
    timeout_id = setTimeout(f1,speed);
  }
  
  var f2 = function()
  {
    if (needReturnSrc)
    {
      el = document.getElementById(idIm);
      src = el.getAttribute('retSrc');
      el.src = src;
    }
    clearTimeout(timeout_id);
  }

  var preloader = function()
  {
    var ar = document.getElementsByTagName('img');
    var img_cache = new Array();
    var j = 0;
    
    for (var x = 0; ar[x]; x++) 
    {
			var im = ar[x];
			var hoversrc = im.getAttribute('hoversrcvideoset');
			if (hoversrc)
			{
  			srcimlist = hoversrc.split(';');
  			for (var y = 0; srcimlist[y]; y++) 
  			{
  			  img_cache[j] = new Image();
					img_cache[j].src = srcimlist[y];
					j++;
  			}
			}
    }    
  }
  
	return {
	  init:function(idImage,chSpeed,retSrc) { 
	    min = 0;
      cur = -1;
      idIm = idImage;
      speed = parseInt(chSpeed);
      needReturnSrc = retSrc;
	  },
	  preload:function() {
	    preloader();
	  },
		start: function() { 
			f1();
		},
		stop: function() {
		  f2();
		}
	};

} ();

/*
//usage
<div id="d1">
  <img id="im1" onmouseover="videoset.init('im1',1000,true); videoset.start()" onmouseout="videoset.init('im1',1000,true); videoset.stop()" src="1.jpg" retSrc="1.jpg" width="200" height="100" hoversrc="http://work.local.home/z_tmp/1.jpg;http://work.local.home/z_tmp/2.jpg;http://work.local.home/z_tmp/3.jpg" />
  <br />
  <img id="im2" onmouseover="videoset.init('im2',1000,false); videoset.start()" onmouseout="videoset.init('im2',1000,false); videoset.stop()" src="2.jpg" retSrc="2.jpg" width="200" height="100" hoversrc="http://work.local.home/z_tmp/1.jpg;http://work.local.home/z_tmp/2.jpg;http://work.local.home/z_tmp/3.jpg" />
</div>
*/
function preloadVideoSET()
{
  videoset.preload();
}
addLoadEvent(preloadVideoSET);
