document.onmousemove = SmouseMove;
document.onkeydown = SkeyPress;

var SmousePos;
var STimeoutID = null;
var SShowerTimeout = null;
var SShowerStep = 0;
var SShowerMaxStep = 2;
var SShoverKoef = SShowerMaxStep / 10 ;
var SShowerBoxActive = false;
var SCZUWPLayerActive = false;

var keyPressTriggers = new Array();
// alt,ctrl,shift,keycode
keyPressTriggers['true,true,false,84'] = 'czuShowContactLayer';

//var SContactBox_W = document.getElementById('ContactBox').width;
//var SContactBox_H = document.getElementById('ContactBox').height;

//document.write('<div id="SSDebugConsole" style="border: 1px solid black; position: absolute; top: 10px; left: 10px; width: 400px; height: 400px;"> SS Debug Console: <br /> </div>');

function SmouseMove(ev) {
	ev           = ev || window.event;
	SmousePos = SmouseCoords(ev);
}

function SkeyPress( ev ) {
	
	var activeKey = '';
	var activeAlt = false;
	var activeShift = false;
	var activeCtrl = false;
	
	if( document.all ) {
		activeKey = window.event.keyCode;
		activeAlt = window.event.altKey;
		activeShift = window.event.shiftKey;
		activeCtrl = window.event.ctrlKey;
	} else {
		activeKey = ev.which;
		activeAlt = ev.altKey;
		activeShift = ev.shiftKey;
		activeCtrl = ev.ctrlKey;
	}
	
	testString = activeAlt + ',' + activeCtrl + ',' + activeShift + ',' + activeKey;
	if( keyPressTriggers[ testString ] ) {
		eval( keyPressTriggers[ testString ] + '()' );
//		return true;
//	} else {
//		return false;
	}
}

function SmouseCoords(ev) {
	if(ev.pageX || ev.pageY) {
		return {x:ev.pageX, y:ev.pageY};
	}
	
	return {
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:ev.clientY + document.body.scrollTop  - document.body.clientTop
	};
}


function showContactBox( id_Clovek ) {
	
	SSDebug('Showing contact card');
	
	box = document.getElementById('ContactBox');
	
	box.style.display = "block";
	box.style.top = (SmousePos.y - 10) + 'px';
	box.style.left = (SmousePos.x - 10) + 'px';
	
	SSDebug('SShowerBoxActive: '+ SShowerBoxActive);
	
	if( !SShowerBoxActive ) {
		DynShower();
		SShowerBoxActive = true;

		box.onmouseout = SmouseOut;
		box.onmouseover = SmouseIn;
	}
	
	if( STimeoutID != null ) {
		clearTimeout( STimeoutID );
		STimeoutID = null;
	}
	
	contactBoxLoadData( id_Clovek );
}

function contactBoxLoadData( id_Clovek ) {

	document.getElementById('ContactBoxContent').innerHTML = '<br /><br /><br /><div style="text-align: center;">' + 
															' <img src="http://webcore.czu.cz/img/progressBar2.gif"/>' + 
															'</div>';
	xajax_getPersonCard( id_Clovek );
	

}

function hideContactBox() {

	SSDebug('Hidding contact card');
	
	box = document.getElementById('ContactBox');
	
	DynHider();
	
	SShowerBoxActive = false;
	
	box.onmouseout = null;
	box.onmousein = null;
}

function SmouseOut() {

	SSDebug('SmouseOut: on');
	
	STimeoutID = setTimeout( 'hideContactBox()' ,1000);
}

function SmouseIn() {

	SSDebug('SmouseIn: on');

	if( STimeoutID ) {
		clearTimeout(STimeoutID);
		STimeoutID = null;
	}
}

function DynShower() {
	box = document.getElementById('ContactBox');
	
	if( SShowerStep < SShowerMaxStep ) {
		
		SShowerStep++;
		
		setOpacity = SShoverKoef * SShowerStep;	
		DynSetOpacity( box, setOpacity );
		
		setTimeout( "DynShower()", 50 );
		
		SSDebug('DynShower: showing object, koef=' + SShoverKoef + '; SShowerStep=' + SShowerStep + '; Opacity: ' + setOpacity );
		
	} else {
		DynSetOpacity(box, 1 );
		SShowerStep=0;
		
		SSDebug( 'box display is: ' + document.getElementById('ContactBox').style.display );
		
		SSDebug('DynShower: object is visible');
	}
}

function DynShower_Size()
{
	box = document.getElementById('ContactBox');
	
}

function DynHider() {
	
//	boxAlpha = document.getElementById('ContactBoxContent');
	box = document.getElementById('ContactBox');
	
	if( SShowerStep < SShowerMaxStep ) {
		
		SShowerStep++;
		
		setOpacity = 1 - (SShoverKoef * SShowerStep);	
		DynSetOpacity( box, setOpacity );
		
		SSDebug('DynHider: hidding object, koef=' + SShoverKoef + '; SShowerStep=' + SShowerStep );
		
		setTimeout( "DynHider()", 50 );
		
	} else {
		box.style.display = "none";
		DynSetOpacity( box, 0 );
		SShowerStep=0;
		
		SSDebug('DynHider: object hide');
	}
}

function DynSetOpacity( box, opacity )
{
	SSDebug('DynSetOpacity: Alpha = ' + opacity);

	if( navigator.appName == 'Microsoft Internet Explorer' ) {
		box.style.filter = 'alpha(opacity='+(opacity * 100)+')';
	} else {
		box.style.MozOpacity = opacity;
	}
}

function SSDebug( msg ) {
//	document.getElementById('SSDebugConsole').innerHTML = msg + '<br />' + document.getElementById('SSDebugConsole').innerHTML;
//	document.getElementById('SSDebugConsole').innerHTML = msg;
}




function czuShowContactLayer() {
	czu.tools.wpLayer.execute();
}




