var showimgs=new Array(), showimgs_index=0;

function parseImg (obj_id)
{
	cmd = '_parseImg("' + obj_id + '");';
	delay = 3000 + parseInt(Math.random()*500);
	window.setTimeout(cmd, delay);
}

function _parseImg(obj_id)
{
	show_img_id = "SHOW" + Math.floor(Math.random()*10000);
	obj = document.getElementById(obj_id);
	imgs = obj.innerHTML.match(/<img .*?>/ig);

	j = 0;
	showimgs[show_img_id] = new Array();
	showimgs[show_img_id][0] = 0;
	showimgs[show_img_id][1] = new Array();
	showimgs[show_img_id][2] = 0; // preLoagImg index
	height = 0;
	for ( i=0 ; i < imgs.length ; ++i )
	{
		src = '';
		title='';
		if ( f = imgs[i].match(/ src="(.*?)"/i) )
		{
			src = f[1];
			if ( src.match(/space.gif$/) ) continue;
		}
		else continue;

		if ( f = imgs[i].match(/ title="(.*?)"/i) )
		{
			title = f[1];
		}

		if ( f = imgs[i].match(/ height=["]?([0-9]+)["]?/i) )
		{
			height = Math.max(parseInt(f[1]), height);
		}
		showimgs[show_img_id][1][j++] = new Array(src, title);
	}

	obj.innerHTML = "<img id=" + show_img_id + " src=\"space.gif\" align=top title=\"\"/>";
	obj.innerHTML+= "<img id=" + show_img_id + "H src=\"space.gif\" align=top height=1 width=1 title=\"\"/>";

	if ( height )
	{
		document.getElementById(show_img_id + 'H').height = height + 10;
	}

	cmd = "ImageShowTime('"+show_img_id+"');";
	eval(cmd);
	delay = 4500 + parseInt(Math.random()*500);
	window.setInterval(cmd, delay);

	cmd = "preLoagImg('"+show_img_id+"');";
	delay = 2500 + parseInt(Math.random()*500);
	window.setTimeout(cmd, delay);
}


function preLoagImg ( show_img_id )
{
	showimgs_index = showimgs[show_img_id][0];
	if ( showimgs_index >= showimgs[show_img_id][1].length ) return;
	obj = new Image();
	obj.src = showimgs[show_img_id][1][showimgs_index][0];
	showimgs[show_img_id][0] = ++showimgs_index;
	cmd = "preLoagImg('"+show_img_id+"');";
	delay = 2500 + parseInt(Math.random()*500);
	window.setTimeout(cmd, delay);
}


function ImageShowTime ( show_img_id )
{
	showimgs_index = showimgs[show_img_id][0];
	if ( showimgs_index >= showimgs[show_img_id][1].length ) showimgs_index = 0;
	obj = document.getElementById(show_img_id);
	obj.title = showimgs[show_img_id][1][showimgs_index][1];
	obj.src = showimgs[show_img_id][1][showimgs_index][0];
	showimgs[show_img_id][0] = ++showimgs_index;
}
