var rollingBlend = (function(){function _class(id,len)
{
	var _self = this;

	var precell, timer;
	var blendIdx = -1;

	this.delay = 5000;
	this.img = new Array();
	this.link = new Array();
	this.colorset = ['#ffffff','#000000'];
	this.mouseevent = "onclick";
	this.mode = "auto";

	this.href = "";

	this.exec = function()
	{
		if (this.color) this.colorset[1] = this.color;
		this.len = this.img.length;
		this.navi();
		this.blendAuto();
	}

	this.add = function(img,link)
	{
		this.img[this.img.length] = img;
		this.link[this.link.length] = link;
	}

	this.navi = function()
	{
		var obj = document.getElementById(id);
		//obj.style.filter = "blendTrans(duration=1)";
		obj.useMap = "#";
		obj.onmouseover = _self.stop;
		obj.onmouseout = _self.start;

		this.href = obj.parentNode;

		var obj = document.getElementById(id + '_bar');
		if (obj){

			if (this.naviMode != "img"){
				var sample = obj.childNodes[0];
				if (sample.tagName!="IMG"){
					this.colorset[0] = sample.style.background;
					for (var i=1;i<this.len;i++){
						obj.innerHTML += sample.outerHTML;
					}
				} else this.naviMode = "img";
			}

			for (var i=0;i<this.len;i++){
				//obj.childNodes[i].onclick = function(){ _self.chg(this); }
				if (this.naviMode!="img") eval("obj.childNodes[i]." + this.mouseevent + " = function(){ _self.chg(this); }");
				else {
					obj.getElementsByTagName('img')[i].style.filter = "gray";
					eval("obj.getElementsByTagName('img')[i]." + this.mouseevent + " = function(){ _self.chg(this); }");
				}
			}
		}
	}

	this.chg = function (cell,idx,auto)
	{
		if (cell){
			if (!auto) idx = this.nodeIndex(cell);
			if (this.naviMode!="img"){
				cell.style.background = this.colorset[1];
				if (precell && precell!=cell){
					precell.style.background = this.colorset[0];
				}
			} else {
				//document.title = cell.outerHTML;
				if (cell.tagName!="IMG") cell = cell.getElementsByTagName('img')[0];
				cell.style.filter = "";
				if (precell && precell!=cell){
					precell.style.filter = "gray";
				}
			}
			precell = cell;
		}

		var obj = document.getElementById(id);

		if (obj.filters[0]) obj.filters[0].apply();
		obj.src = this.img[idx];
		if (obj.filters[0]) obj.filters[0].play();

		if (_self.href.tagName!="A") obj.onclick = this.golink;
		else obj.onmouseover = this.golink;
		obj.style.cursor = (this.link[idx]) ? "pointer" : "";

		blendIdx = idx;

		if (!auto){
			clearTimeout(timer);
			if (this.mode=="auto") timer = setTimeout(_self.blendAuto,_self.delay);
		}
	}

	this.stop = function()
	{
		clearTimeout(timer);
	}

	this.start = function()
	{
		if (_self.mode=="auto") timer = setTimeout(_self.blendAuto,_self.delay);
	}

	this.blendAuto = function ()
	{
		if (++blendIdx>=_self.len) blendIdx = 0;
		if (document.getElementById(id + '_bar')){
			var cell = (_self.naviMode!="img") ? document.getElementById(id + '_bar').childNodes[blendIdx] : document.getElementById(id + '_bar').getElementsByTagName('img')[blendIdx];
		} else var cell = "";

		_self.chg(cell,blendIdx,1);
		if (_self.mode=="auto") timer = setTimeout(_self.blendAuto,_self.delay);
	}

	this.golink = function()
	{
		clearTimeout(timer);
		if (_self.link[blendIdx]){
			if (_self.href.tagName=="A") _self.href.href = _self.link[blendIdx];
			else location.href = _self.link[blendIdx];
		} else _self.href.href = "#";
	}

	this.nodeIndex = function(obj)
	{
		//var parent = obj.parentNode;
		var parent = document.getElementById(id + '_bar');
		var div = (this.naviMode=="img") ? parent.getElementsByTagName('img') : parent.childNodes;
		for (var i=0;i<div.length;i++){
			if (obj==div[i]) return i;
		}
		return false;
	}

};
return _class;
})();