/*
 *
 * this module defines a AdPreview class, which represents dynamic window showing advert details
 * it uses AdInfoText.aspx service of mpmads application
 *
 */

function FloatingWindow(postMouseoutDelay, previewCssID) {
	/*
		constructor takes three arguments, postDelay, indicating the delay before window diminishes after mouse-out,
		previewCssID argument, giving the CSS ID of HTML element representing Advert Preview window 
		and servicePath argument, giving path to the service, which takes url argument "id" indicating uid of advert,
		returning plaintext in the format of the example below.

		CAPTION:Podrobnosti;
		SUBMITTER:Zadavatel:Muž;
		AGE:Věk:24;
		HEIGHT:Výška:189;
		WEIGHT:Váha:80;
		COUNTRY:Země:Česká republika;
		REGION:Region:Středočeský kraj;
		MARITALSTATUS:Rodinný stav:Svobodný/á;
		WANTED:Hledá:Ženu;
		RANK:Hodnocení:0;
		VOTES:Počet hlasů:0;
		RANK_REGISTERED:Hodnocení registrovanými:0;
		VOTES_REGISTERED:Počet hlasů od registrovaných:0;
		IMGPATH:services/medium.aspx?id=236&thumb=1;
		IMGCOMMENT:já;
	*/


	/* CONSTRUCTOR AND PRIVATE MEMBER DEFINITIONS */

	var _post_mouseout_delay = postMouseoutDelay;
	var _preview_id = previewCssID;
	var _previewElement = window.document.getElementById(previewCssID);	

	var _mouse = new Mouse();
	var _offsetX = -345;
	var _offsetY = -465;
	var _hideTimer;
	var _suppressExceptions = true;

	if (_previewElement == null) {
		throw new Error ("Element with specified ID (" + previewCssID + ") does not exists in the document.");
	}

	/* PRIVATE METHOD DEFINITIONS */

	function instantHide()
	{
		_previewElement.style.visibility = "hidden";
		_previewElement.style.display = "none";
	}
	function show()
	{
		clearTimeout(_hideTimer);
		_previewElement.style.visibility = "visible";
		_previewElement.style.display = "block";
		document.body.onmousemove = preview.updatePosition;
	}
	this.show = show;

	/* PUBLIC METHOD DEFINITIONS */

	function updatePosition(e)
	{
		var xPosition = _mouse.getX(e) + _offsetX;
		var yPosition = _mouse.getY(e) + _offsetY;

		if (ns6) {
			_previewElement.style.left = xPosition.toString() + 'px';
			_previewElement.style.top = yPosition.toString() + 'px';
		} else {
			_previewElement.style.posLeft = xPosition;
			_previewElement.style.posTop = yPosition;
		}
	}
	this.updatePosition = updatePosition;

	function delayedHide()
	{
		document.body.onmousemove = null;
		_hideTimer = self.setTimeout(instantHide, _post_mouseout_delay);
	}
	this.hide = delayedHide;
}


