function spcPopup()
{
//	container = null
//	elPopup = null
//	wndPopup = null
//	elPopupTitle = null
//	elPopupBody
	this.hoverItemId = null;

	this.name	 = 'mediawindow';

	this.wndPopup = new spcWindow(
						{ title:			''
						, className:		'mappopup pointpopup'
						, canclose:			false
						, candrag:			false
						, visible:			false
						, center:           false
						, preferredWidth:	300
						});

	this.elPopupTitle	= document.createElement('div');
	this.elPopupTitle.className = 'popupTitle';

	this.elPopupBody	= document.createElement('div');
	this.elPopupBody.className = 'popupDescription';

	if (!useragent.csssupport.rgba)
	{
		var bg = document.createElement('div');
	    bg.className = 'background';
		this.wndPopup.body.appendChild(bg);
	}
//	else
//		this.elPopupBody.style.cssText = 'display: none; background-color: rgba(0,0,0,0.75);'

	this.wndPopup.body.appendChild(this.elPopupTitle);
	this.wndPopup.body.appendChild(this.elPopupBody);

	this.elPopup = this.wndPopup.container;
}

spcPopup.prototype.setTitle = function(titleText)
{
	if (typeof titleText != 'undefined' && titleText != null)
	{
		this.elPopupTitle.innerHTML = titleText;
		this.elPopupTitle.style.display = 'block';
	}
	else
	{
		this.elPopupTitle.innerHTML = '';			// workaround for when why try to extract all <img> in the popup
		this.elPopupTitle.style.display = 'none';
	}
}

spcPopup.prototype.setDescription = function(descText)
{
	if (typeof descText != 'undefined' && descText != null)
	{
		this.elPopupBody.innerHTML = descText;
		this.elPopupBody.style.display = 'block';
	}
	else
	{
		this.elPopupBody.innerHTML = '';			// workaround for when why try to extract all <img> in the popup
		this.elPopupBody.style.display = 'none';
	}
}

spcPopup.prototype.showItem = function(item)
{
	if (this.hoverItemId == item.id)
		return;

	//if (this.wndPopup == undefined)
	//	this.create();

	_this = this;

	if (item == -1)
	{
		this.hide();
		return;
	}

	this.hoverItem = item;

	this.elPopup.style.display = 'none';	// hide till new popup content has been loaded
	
	// find images and create a countdown until all pictures are loaded before we will show the popup
		
	var setText = true;
//		if (this.onshowpopup) setText = this.onshowpopup(item);

	if (setText)
	{
		this.setTitle( item.name );
		this.setDescription( item.shortdesc );
	}


	// try to wait with showing the popup until all images in it have loaded
	// or 750 ms have passed
	
	var imagesInPopup = this.elPopupBody.getElementsByTagName('img');

	if (imagesInPopup.length == 0)
		this.show(item);
	else
	{
		for (var indexname in imagesInPopup)
		{
			var theimg = imagesInPopup[indexname];

			// TODO: check if errorimgs have dimensions
			// TODO: check if allready has dimensions (which means it is loaded???)
			// TODO: countdown until all images are loaded, then show the popup
			theimg.onload = function() { _this.show(item); clearTimeout(_this.forcepopuptimer); };
			theimg.onerror = function() { _this.show(item); clearTimeout(_this.forcepopuptimer); };
//			alert(theimg.src+' = '+theimg.readyState);
		}

		this.forcepopuptimer = setTimeout( function() { _this.show(item); }, 750 );

		// WORKAROUND for Opera:
		// Opera will not load with display: none;
		// TODO: only apply this for Opera, to minimize reflows in other browsers
		this.elPopup.style.visibility = 'hidden';
		this.elPopup.style.display    = 'block';
	}
}


spcPopup.prototype.hide = function()
{
	this.elPopup.style.display = 'none';
}

spcPopup.prototype.show = function(fromItem)
{
//	map.elPopup.style.display = 'display';
	var item = this.hoverItem;

	if (item != fromItem)
		return;		// loading took too long, whe expect another item now

	this.elPopup.style.visibility	= 'hidden';		// don't show result yet
	this.elPopup.style.display		= 'block';		// but render it in as a block

//	this.placePopupNextToItem(item);
	this.elPopup.style.visibility	= 'visible';
}

spcPopup.prototype.placePopup = function(newLeft,newTop,infoWidth,infoHeight)
{
//	read size of the popup
//	var infoWidth	= map.elPopup.clientWidth;
//	var infoHeight	= map.elPopup.clientHeight;

//	map.elPopup.onresize = function() { alert('resize'); }
	
//	set position and sizes of popup & popup-background
	this.elPopup.style.left	= newLeft+"px";
	this.elPopup.style.top	= newTop+"px";

/* For IE and other browsers that can't resize using CSS top+bottom and left+right: */
//	map.elPopupBG.style.width		= infoWidth+"px";
//	map.elPopupBG.style.height		= infoHeight+"px";

//	show the popup and background
//	map.elPopupBG.style.display	= 'block';
//	map.elPopup.style.visibility	= 'visible';

}
