/*****************************************************************************************/
function $(sId){ 
	return document.getElementById(sId); 
}

/*****************************************************************************************/
function reloadWindow(){
	window.location = window.location + '';
}


/*****************************************************************************************/
function addEvent(elNode, sEvent, fFunc){
	if(sEvent == 'keydown' || sEvent == 'keypress')
		sEvent = window.opera ? 'keypress' : 'keydown';

	if (isGecko){
		elNode.addEventListener (sEvent, fFunc, true);
	} else {
		elNode.attachEvent ('on' + sEvent, fFunc);
	} 
}	

/*****************************************************************************************/
function removeEvent(elNode, sEvent, fFunc){
	if(sEvent == 'keydown' || sEvent == 'keypress')
		sEvent = window.opera ? 'keypress' : 'keydown';

	if (isGecko){
		elNode.removeEventListener (sEvent, fFunc, true);
	} else {
		elNode.detachEvent ('on' + sEvent, fFunc);
	} 
}	

/*****************************************************************************************/
var oInfoWindow = new function(){
	this.isLoaded = 0;
	
	this.scrollTop =  function(){
		return window.pageYOffset
			|| document.documentElement.scrollTop
			|| document.body.scrollTop
			|| 0;
	}
	
		
	this.showContent =  function(){
		var elW = $('InfoWindowImg');
	}
	
		
	this.close =  function(){
		$('InfoWindow').style.display = 'none';
		if(window.opera){
			document.onkeypress = null;
		} else {
			document.onkeydown = null;
		}
	}
	
	this.escapeButton = function(event){
		var evt = event || window.event;
		if(evt.keyCode == 27) oInfoWindow.close();
	}
	
	this.showRequestResult =  function(){
	
		$('InfoWindowContent').firstChild.className = '';
		$('InfoWindowImg').firstChild.className = '';
					
		$('InfoWindowContent').firstChild.style.height = '';
		$('InfoWindowImg').firstChild.style.height = '';

		if(window.opera){
			document.onkeypress = this.escapeButton;
		} else {
			document.onkeydown = this.escapeButton;
		}
	}
	
	this.getInfoRequest =  function(iId){
		if(! JsHttpRequest ) return;
		
		var intervalId = setTimeout("reloadWindow()", 5000);
		var oReqValues = new Object();
			 oReqValues['id'] = iId;
		
		JsHttpRequest.query(
			window.location.href + '' ,
			oReqValues ,
         function(result, errors) {
				clearTimeout(intervalId);
				if(result){
//					oInfoWindow.isLoaded++;
//					if(oInfoWindow.isLoaded == 2){
//						oInfoWindow.showRequestResult();
//					}
					
					$('InfoWindowContent').firstChild.innerHTML = result.content;
					$('InfoWindowImg').firstChild.innerHTML = result.img;
					oInfoWindow.showRequestResult();
				}
			} ,
			true // disable caching
		);
	}
	
	this.open =  function(iId){
		var elW = $('InfoWindow');
		oInfoWindow.isLoaded = 0;
		
		$('InfoWindowContent').firstChild.innerHTML = '&nbsp;';
		$('InfoWindowImg').firstChild.innerHTML = '<img src="/_images/ajax-loader.gif" alt="" />';
		
		$('InfoWindowContent').firstChild.className = 'overflow';
		$('InfoWindowImg').firstChild.className = 'overflow';
		
//		$('InfoWindowContent').firstChild.className = '';
//		$('InfoWindowImg').firstChild.className = '';
				
		this.getInfoRequest(iId);
		
		elW.style.visibility = 'hidden';
		elW.style.overflow = 'hidden';
		elW.style.display = 'block';
		
		elW.style.top = this.scrollTop() - elW.parentNode.offsetTop + 'px';
		elW.style.visibility = 'visible';
		
//		elW.style.width = '0';
		var iPers = 0;
//		var intervalId = setInterval( _openProcess() , 5);
		
		function _openProcess(){
			return function(){
				iPers+=5;
				elW.style.width =  iPers +'%';
				var sH = $('InfoWindowImg').firstChild.offsetWidth + 'px';

				$('InfoWindowContent').firstChild.style.height = sH;
				$('InfoWindowImg').firstChild.style.height = sH;
				
				if(iPers == 100){
					clearTimeout(intervalId);
					oInfoWindow.isLoaded++;
					if(oInfoWindow.isLoaded == 2){
						oInfoWindow.showRequestResult();
					}
//					this.showContent();
//					elW.style.width = '';
				}
			}
		}
		
	}
	
	this.getInfo =  function(iId){
		this.open(iId);
	}
	
	
	
}