//*************************************************************************************************
/*!
	\brief		Function: Creates a sticker object
	\param  		resdir Resource directory (without trailing slash)
	\param  		image  Background image file name
	\param  		text   Text to show
	\param  		sound  Mouseover played sound file name
	\param  		line  Text to show on Mouseover
	\param		left   Left position
	\param		top    Top position
	\param		width  Width position
	\param		height Height position
	\return		The created dom object
	\internal
	\date			Apr 2006
	\author		(c) PATANEGRA Soft - www.patanegra.com - AGS
*/
//*************************************************************************************************
function AddStickerObject(resdir, image, text, sound, line, left, top, width, height)
{
	var obj = new SlLayer(null, null, left, top, width, height);

	// Clear default captured events
	obj.captureEvents(false);

	// Capture mouse up
	SlEventCapture(obj.dom, 'mouseup', obj.onmouseup);

	// Keep some constructor parameters
	obj.__image = !image ? null : image;
	obj.__text  = !text  ? null : text ;
	obj.__sound = !sound ? null : sound;
	obj.__line  = !line  ? null : line;

	// Move/resize status
	obj._status['MoveOnUsing'   ] = 'always';
	obj._status['MoveOnDesign'  ] = 'never';
	obj._status['ResizeOnUsing' ] = 'never';
	obj._status['ResizeOnDesign'] = 'always';

	// Top for Z axis
	obj.dom.style.zIndex = SlGetDomMaxZIndex(SlSys._body);

	// No select text!
	obj.setSelection(false);

	// Has text?
	if(text)
	{
		// Set content
		obj.dom.innerHTML = text;

		// text + image at same time?
		if(image)
			obj.dom.style.backgroundColor = 'transparent';
	}

	// Has line?
	if(line)
	{
		// Set content
		SlEventCapture(obj.dom, 'mouseover', function(e) { SlEventStd(e); e.target.style.cursor = 'move'; document.getElementById('txtsti').innerHTML = line; });
		SlEventCapture(obj.dom, 'mouseout', function(e) { SlEventStd(e); e.target.style.cursor = 'arrow'; document.getElementById('txtsti').innerHTML = '&nbsp;'; });
	}

	// Has image?
	if(image)
		obj.setBGImage(resdir + "/" + image, true);

	// Has sound?
	if(sound)
	{
		// Create sound object
		obj.dom.appendChild(document.createElement('embed'));
		obj.dom.lastChild.setAttribute('width'           , (image || text) ? 1 : width);
		obj.dom.lastChild.setAttribute('height'          , (image || text) ? 1 : height);
		obj.dom.lastChild.setAttribute('visibility'      , 'hidden');
		obj.dom.lastChild.setAttribute('quality'         , 'high');
		obj.dom.lastChild.setAttribute('pluginspage'     , 'http://www.macromedia.com/go/getflashplayer');
		obj.dom.lastChild.setAttribute('wmode'           , 'transparent');
		obj.dom.lastChild.setAttribute('type'            , 'application/x-shockwave-flash');
		obj.dom.lastChild.setAttribute('src'             , resdir + '/' + sound + '.swf');
		obj.dom.lastChild.setAttribute('enablejavascript', true);

		//! Mouse over play sound (if not image neither text)
		if(image || text)
			SlEventCapture(obj.dom, 'mouseover', function(e) { obj.dom.getElementsByTagName('embed')[0].Play(); });
	}

	//! Double click duplicate the object
	SlEventCapture(obj.dom, 'dblclick', obj.dom.__dblclick = function(e)
		{ AddStickerObject(resdir, image, text, sound, line, obj.dom.style.left, obj.dom.style.top, obj.dom.style.width, obj.dom.style.height); });

	//! Right click delete the object
	SlEventCapture(obj.dom, 'contextmenu', function(e)
	{
		// Normalize event
		SlEventStd(e);

		// Ignore default action
		SlEventPreventDefault(e);

		// Call object destructor
		obj.destroy();
	});

	// Return the created dom object
	return obj.dom;
}
