// -----------------------
// tzer support
// in this (local) version swf and png files are loaded from icq server
// -----------------------

// this one's for adding unique IDs to flash wrappers
counter = 0;
// tzer base-urls white list. devided by | sign. don't change this delimetr, because it's used in regexp
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];

		// why twelve? |"http://"| + |".sfw"| = 11. and one symbol for other part of URL %)
		if ((tzer.length > 12))
		{
			// 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="' + tzer + '">\
				<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 = (document.getElementsByTagName('object'))[0];
	// if it stopped playing
	if (!(obj.playing))
	{
		// here starts the dancing with the tambourine
		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);
		// this is a damn rename table, because icq corp put tzer's previews f. knows there, with strange names %)
		switch(tzer)
		{
		case 'gangsterSheep': tzer = 'gangsta'; break;
		case 'cant_hear': tzer = 'canthearu'; break;
		case 'scratch': tzer = 'skratch'; break;
//		case 'boo': tzer = 'boo'; break;
//		case 'kisses': tzer = 'kisses'; break;
		case 'rastamab': tzer = 'chillout'; break;
		case 'sappuko': tzer = 'akitaka'; break;
//		case 'sorry': tzer = 'sorry'; break;
//		case 'laugh': tzer = 'laugh'; break;
		case 'dahh': tzer = 'duh'; break;
		case 'beBack': tzer = 'beback'; break;
		case 'iLikeU': tzer = 'likeu'; break;
		}
		// form the URL to image
		img = 'http://c.icq.com/xtraz2/img/teaser/common/' + 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);
			switch(tzer)
			{
			case 'gangsterSheep': tzer = 'gangsta'; break;
			case 'cant_hear': tzer = 'canthearu'; break;
			case 'scratch': tzer = 'skratch'; break;
			case 'rastamab': tzer = 'chillout'; break;
			case 'sappuko': tzer = 'akitaka'; break;
			case 'dahh': tzer = 'duh'; break;
			case 'beBack': tzer = 'beback'; break;
			case 'iLikeU': tzer = 'likeu'; break;
			}
			img = 'http://c.icq.com/xtraz2/img/teaser/common/' + tzer + '.png';
			document.write('<div class="tzer_wrapper"><img src="' + img + '" width="60" height="46" alt="tZer" /></div>');
		}
	}
}