
/**
 * _ptools.Info
 *
 * @author PCSG - Henning
 * @package com.pcsg.ptools.info
 * 
 * @copyright  2008 PCSG
 * @version    0.3 $Revision: 2407 $
 * @since      Class available since Release P.MS 0.1
 */

if(typeof _ptools == 'undefined') {
	var _ptools = {};
};

_ptools._Infos = new Array();
 
// settings.text
_ptools.Info = function(settings)
{
	var t = this;
	t.settings = settings;
	
	t.oImgL = null;
	t.oImgR = null;
	t.oDiv  = null;
	t.obj  = null;
	
	t.type = '_ptools::Info';
	
	if(typeof t.settings.name == 'undefined') {
		t.settings.name = new Date().getMilliseconds();
	};
};

/**
 * Erstellt eine Info Nachricht
 */
_ptools.Info.prototype.create = function()
{
	var t = this;
	var settings = t.settings;
	var _System  = _ptools._System;
	var stk      = _System.getAttribute('path');
	var width    = _System.getMaxWidth()-100;
	
	t.obj    = document.createElement('div');
	t.obj.id = 'Info_'+ settings.name;
	
	t.oDiv = t.obj.cloneNode(true);	
	t.oDiv.className = '_pInfoText';
	
	t.oImgL = document.createElement('img');	
	t.oImgR = t.oImgL.cloneNode(true);	

	t.obj.className = '_pInfo';
	
	var style = t.obj.style;
	style.top        = (_System.getScrollXY()[1] + 10) + 'px';
	style.visibility = 'hidden';
	style.width      = width +'px';
	
	// in body einfügen
	t.obj.appendChild(t.oImgR);
	t.obj.appendChild(t.oImgL);
	t.obj.appendChild(t.oDiv);
	
	// Per Klick kann die Info auch weggeglickt werden
	t.obj.onclick = function() {
		t.hide();
	};
	
	document.body.appendChild( t.obj );
	
	if (window.innerHeight) 
	{
		var maxHeight = window.innerHeight;
		var maxWidth  = window.innerWidth;
	} else 
	{
		var maxHeight = document.body.clientHeight;
		var maxWidth  = document.body.clientWidth;
	};
	
	style.left = (maxWidth - t.obj.offsetWidth) / 2 + "px";
	
	style = t.oDiv.style;
	
	style.backgroundImage  = 'url("' + stk + 'info/images/bg.png")';
	style.backgroundRepeat = 'repeat-x';
	
	style.width = (width-50) +'px';
	style.left  = '15px';
	
	if(settings.image)
	{
		var img_src = settings.image;
	} else
	{
		var img_src = stk + 'info/images/info.png';
	};
	
	t.oDiv.innerHTML = '<img src="'+ img_src +'" align="left" hspace="10" />'+ settings.text;
	
	t.oImgL.src = stk +'info/images/left.png';
	style = t.oImgL.style;
	style.position = 'absolute';
	style.top      = '0px';
	style.left     = '0px';
	style.height   = '59px';
	style.width    = '15px';
	
	t.oImgR.src = stk +'info/images/right.png';
	style = t.oImgR.style;
	style.position = 'absolute';
	style.right    = '0px';
	style.top      = '0px';
	style.height   = '59px';
	style.width    = '15px';
	
	var elm = $('Info_'+ settings.name);
	
	elm.set('opacity', 0);
	elm.set('tween', {
		duration: 500,
		onComplete : (function() {
	       t.hide();
	    }).delay(2000)
	});
	
	elm.tween('opacity', [0, 0.7]);
	
	_ptools._Infos[settings.name] = t;
};

/**
 * Info Box verschwinden lassen
 */
_ptools.Info.prototype.hide = function()
{
	var t = this;
	var oname = 'Info_'+t.settings.name;
	
	if(!$(oname)) {
		return;
	};
	
	$(oname).set('tween', {
		duration : 500,
		onComplete : function() {
			t.obj.parentNode.removeChild( t.obj );
	        delete _ptools._Infos[ t.settings.name ];
	    }
	});
	$(oname).tween('opacity', [0.7, 0]);
};

