/*******************************************************************************
	EasyWEB	5

	@Copyright 	Synerway Sp. z o. o. http://www.synerway.pl/
			All rights reserved

	@Author		Antoni Jakubiak <a.jakubiak@synerway.pl>


	@Description	Powiekszanie zdjec dla hoteli na liscie

	$Id: placephoto.js,v 1.1.4.1 2007/02/06 10:57:06 mgil Exp $
*******************************************************************************/


function PlacePhoto( iElement, iFileUrl, iOnMouseOverNow ) {
	/**
	 * Element aktywny
	 */
	this.element = iElement;
	/**
	 * Adres URL do obrazka
	 */
	this.fileUrl = iFileUrl;
	/**
	 * Element aktywowany
	 */
	this.elementOver = null;
	/**
	 * Wskaznie na siebie
	 */
	var oThis = this;
	this.timeout = null;
	this.element.onmouseover = function() {
		clearTimeout( oThis.timeout );
		var tmpFn = function() {
			oThis.show(); 
		};
		oThis.timeout = setTimeout( tmpFn, 500 );
	}
	this.element.onmouseout = function() {
		clearTimeout( oThis.timeout );
	}
	if ( iOnMouseOverNow ) {
		this.element.onmouseover();
	}
}

/**
 * Pokazywanie powiekszonego zdjecia
 */
PlacePhoto.prototype.show = function() {
	var oThis = this;
	this.position = this.getAbsolutePos( this.element );
	if ( ! this.elementOver ) {
		this.elementOver = document.createElement( 'img' );
		this.elementOver.src = this.fileUrl;
		this.elementOver.className = 'max';
		this.elementOver.onmouseout = function() {
			oThis.hide();
		}
		this.element.parentNode.appendChild( this.elementOver );
	}
	this.elementOver.style.left = ( this.position[0] - 1 ) + 'px';
	this.elementOver.style.top = ( this.position[1] - 1 ) + 'px';
	this.elementOver.style.display='block';
}
/**
 * Ukrywanie powiekszonego zdjecia
 */
PlacePhoto.prototype.hide = function() {
	clearTimeout( this.timeout );
	if ( this.elementOver ) {
		this.elementOver.style.display='none';
	}
}
/**
 * Absolutna pozycja elementu
 */
PlacePhoto.prototype.getAbsolutePos = function( oElem ) {
	var oTemp = typeof oElem == 'string' ? document.getElementById( oElem ) : oElem;
	oElem = oTemp;
	var absLeft = 0, absTop = 0;
	while ( oTemp ) {
		absTop += oTemp.offsetTop;
		absLeft += oTemp.offsetLeft;
		oTemp = oTemp.offsetParent;
	}
	return new Array(absLeft, absTop, absLeft + oElem.offsetWidth, absTop + oElem.offsetHeight );
}
