// -----------------------
// tzer support
// in this (local) version swf and png files are loaded locally, from the disk
// -----------------------

// this one's for adding unique IDs to flash wrappers
counter = 0;
// tzer base-urls white list
whiteList = 'c.icq.com|www.icq.com|xtraz.icq.com';

function Teaser(text)
{
	// background color for tzer flash
	tzerBgColor = '#e2e8f4';
	// here come dimensions of the flash
	tzerWidth = 240;
	tzerHeight = 180;

	// echo recived text
	document.write(text + '<br>');

	// str with a link to swf
	tzer = '';

	// primary dummy check: does the recieved text contains any swf?
	if (text.indexOf('.swf', 0) != -1)
	{
		// now try to get the url by this stupid regexp
		linkRegExp = new RegExp('="(http:\/\/(' + whiteList + ')\/[a-zA-z0-9\/]+?\.swf)"', 'i');

		matches = linkRegExp.exec(text);

		if (matches) tzer = matches[1];

		// i'm tired of commenting :D
		var temp = new Array();
		// get the swf filename
		temp = tzer.split('/');
		str = temp[temp.length - 1];
		// get rid of its extension
		lenght = str.length - 4;
		tzer = str.substring(0, lenght);

		// finnaly form the local path
		tzerfile = 'teasers\\swf\\' + tzer + '.swf';

		// create object tag
		document.write('<div class="tzer_wrapper" id="tzer_' + counter + '">\
				<object width="' + tzerWidth + '" height="' + tzerHeight + '" name="movie" class="tzer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0">\
				<param name="movie" value="' + tzerfile + '">\
				<param name="bgcolor" value="' + tzerBgColor + '">\
				<param name="quality" value="high">\
				<param name="scale" value="showall">\
				<embed src="' + tzer + '" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash">\
				</embed></object></div>');

			// set timer, cheking, whether the animation is over
			window.setTimeout("SwfToPng('tzer_" + counter + "', '" + tzer + "')", 10000);

			counter++;
	}
}


function SwfToPng(id, tzer)
{
	// find flash wrapper by it's unique id
	d = document.getElementById(id);
	// get flash object
	obj = (d.getElementsByTagName('object'))[0];
	// if it stopped playing
	if (!(obj.playing))
	{
		// form the local path to image
		img = 'teasers\\png\\' + tzer + '.png';
		// replace flash with picture
		d.innerHTML = '<img src="' + img + '" width="60" height="46" alt="tZer" />';
	}
	// if it keeps "flashing" -- restart timer
	else window.setTimeout("SwfToPng('" + id + "', '" + tzer + "')", 4000);
}

// shit, but I was in a hurry, so this all stuff is just a repetition of previous mess
function TeaserImg(text)
{
	document.write(text + '<br>');

	tzer = '';
	if (text.indexOf('.swf', 0) != -1)
	{
		linkRegExp = new RegExp('="(http:\/\/(' + whiteList + ')\/[a-zA-z0-9\/]+?\.swf)"', 'i');
		matches = linkRegExp.exec(text);

		if (matches) tzer = matches[1];

		if ((tzer.length > 12))
		{
			var temp = new Array();
			temp = tzer.split('/');
			str = temp[temp.length - 1];
			lenght = str.length - 4;
			tzer = str.substring(0, lenght);
			img = 'teasers\\png\\' + tzer + '.png';
			document.write('<div class="tzer_wrapper"><img src="' + img + '" width="60" height="46" alt="tZer" /></div>');
		}
	}
}