function key_shortcut(event) {
	//37 doleva, 39 doprava

	if(event.keyCode == 27) { // escape
		var c = false;
		if(ffind.on | ffind.on_status | ffind.on_visit) {
			ffind.hide();
			c = true;
		} else if(document.getElementById('message-out').style.display == 'block') {
			zavrit('message');
			c = true;
		} else if(profile.document.getElementById('fotkapozadi2')) {
			if(profile.document.getElementById('fotkapozadi2').style.display == 'block') {
				profile.schovejfotku();
				var c = true;
			}
		}
		
		if(c) {
			;
		} else if(document.getElementById('profile-out').style.display == 'block') {
			zavrit('profile');
		} else if(document.getElementById('mainframe-out').style.display == 'block') {
			zavrit('');
		}
	} else if(event.keyCode == 32 & event.shiftKey) { // shift + mezerník
		{ // pokud jde o textové pole a je v něm něco napsané, klávesovou zkratku nepoužít
			if(!event.target) {
				event.target = event.srcElement;	
			}
			
			if( (event.target.type == 'text' | event.target.type == 'textarea') & event.target.value != '') {
				return;
			}
		}
		
		ffind.show();
		ob('ffind_form').focus();
		ob('ffind_form').select();
		if(IE) {
			event.cancelBubble = true;
		} else {
			event.stopPropagation();
			event.preventDefault();
		}					
	}
}

var ffind = {
	on : false,
	on_status : false,
	on_visit : false,
	last : 0,
	first : 0,
	item : 0,
	items : 0,
	timeout : 0,
	timeout_init : 0,
	links : Array,
	
	hide : function() {
		clearTimeout(ffind.timeout_init);
		
		ob('ffind_in').style.display = 'none';
		ob('ff_status_in').style.display = 'none';
		ob('ff_visit_in').style.display = 'none';
		ob('ffind').style.display = 'none';
		
		ffind.on = false;
		ffind.on_status = false;
		ffind.on_visit = false;
	},
	
	show : function(p) {
		if((ffind.on | p == 'off') & p != 'on') {
			ffind.hide();
		} else {
			clearTimeout(ffind.timeout_init);
			
			ffind.hide();
			
			ob('ffind').style.display = 'block';
			ob('ffind_in').style.display = 'block';
			ob('ffind_form').focus();
			ob('ffind_footer').innerHTML = 'Shift + mezerník';
			ffind.on = true;
		}
		
	},
	
	// find
	link : function(id) {
		ffind.show(); // zavření vyhledávacího okna
		profil = ffind.links[ffind.item - 1];
		top.profile.location.href = 'profiles-show.php?id=' + profil;
	},
	
	search : function(event) {
		if(ffind.timeout & !(event.keyCode == 13 & !ffind.item)) {
			clearTimeout(ffind.timeout);
		}
		if(ffind.timeout_init) {
			clearTimeout(ffind.timeout_init);
		}
		
		if(event.keyCode == 13) { // enter
			if(ffind.item) {
				ffind.show(); // zavření vyhledávacího okna
				profil = ffind.links[ffind.item - 1];
				if(event.shiftKey) {
					top.message.location.href = 'messages-show.php?id=' + profil;
				} else {
					top.profile.location.href = 'profiles-show.php?id=' + profil;
				}
			}
		} else if(event.keyCode == 40) { // šipka dolů
			if(ffind.item < ffind.items) { // pokud není poslední, posune dolů
				ffind.activate(parseInt(ffind.item) + 1);
			} else if(ffind.items) { // jinak pokračovat na další "stránce"
				//ffind.search_request(ffind.last,'n');
				
			}
		} else if(event.keyCode == 38) { // šipka nahoru
			if(ffind.item > 1) { // pokud není první, zobrazí předchozí
				ffind.activate(parseInt(ffind.item) - 1);
			} else if(ffind.items) { // jinak pokračuje na předchozí "stránce"
				//ffind.search_request(ffind.first,'p');
			}
		} else if(!ob('ffind_form').value) {
			document.getElementById('ffind_result').innerHTML = '<div class="null">&nbsp;</div>';
			document.getElementById('ffind_footer').innerHTML = 'Shift + mezerník';
			document.getElementById('ffind_h_profily').style.display = 'none';
		} else {
			if(ob('ffind_form').value == ' ') {
				ob('ffind_form').value = ''; // u IE nefunguje cancelBubble :/
			}
			ffind.item = 0;
			string = ob('ffind_form').value;
			ffind.timeout = setTimeout('ffind.search_request("' + string + '");',500);
			ob('ffind_result').innerHTML = '<div class="item">&nbsp;Načítám...</div><div class="null">&nbsp;</div>';
			ob('ffind_footer').innerHTML = 'Enter = navštívit, Shift+Enter = napsat zprávu';
			
		}
	},
	
	search_request : function(string,prechod) {
		// prechod = '': hledá se řetězec string; prechod = n: zobrazí 5 výsledků > řetězec string; prechod = p: zobrazí 5 výsledků před profilem string
		if(prechod) string += '&prechod=' + prechod
		var head = document.getElementsByTagName("head")[0];
		var oldS = document.getElementById('ibActionScript'); 
		if (oldS != null) oldS.parentNode.removeChild(oldS);
		var script = document.createElement('script');
		script.id = 'ibActionScript';
		script.type = 'text/javascript';
		script.src = "action.js.php?action=search&search=" + string;
		head.appendChild(script);
	},
	
	
	activate : function(id) {
		//alert('item' + el.id);
		if(ffind.item) {
			ob('item' + ffind.item).className = 'item';
		}
		if(id) {
			ob('item' + id).className = 'item aktivni';
		}
		ffind.item = id;
	},
	
	status_show : function() {
		if(ffind.on_status == true) {
			ffind.hide();
		} else {
			ffind.hide();
			
			if(ffind.on_status != true) {
				ob('ff_status_in').style.display = 'block';
				ob('ffind').style.display = 'block';
				ob('ffind_footer').innerHTML = '&nbsp;';
				
				ffind.on_status = true;
			}			
		}
	},
	
	visit_show : function() {
		if(ffind.on_visit == true) {
			ffind.hide();
		} else {
			ffind.hide();
			
			if(ffind.on_visit != true) {
				ob('ff_visit_in').style.display = 'block';
				ob('ffind').style.display = 'block';
				ob('ffind_footer').innerHTML = '&nbsp;';
				
				ffind.on_visit = true;
			}
		}
	}
}






// zobrazení a schování panelů
function zobrazpanely(zobrazit) {
	if(zobrazit) {
		document.getElementById('panel-zobrazit').style.display = 'none';
		document.getElementById('panely').style.display = 'block';
	} else {
		document.getElementById('panel-zobrazit').style.display = 'block';
		document.getElementById('panely').style.display = 'none';
	}
}

// oznamování uživatelů


var oznameni = {
	tim1 : 0,
	tim2 : 0,

	zobraz : function() {
		try {
			clearTimeout(tim1);
			clearTimeout(tim2);
		} catch(e) {}
		
		oznameni.nastav(100);
		tim1 = setTimeout("oznameni.nastav(50)",10*1000);
		tim2 = setTimeout("oznameni.nastav(0)",15*1000);
	},
	
	nastav : function(op) {
		el = ob('oznameni');
		if(op == 0) {
			el.style.display = 'none';
		} else {
			el.style.filter='alpha(opacity=' + op + ')';
			el.style.MozOpacity = op / 100;
			el.style.KhtmlOpacity = op / 100;
			el.style.opacity = op / 100;
			el.style.display = 'block';
		}
	}
}

// schování čísílek u nabídky
function nab_x(co) {
	try {
		el = ob('nab' + co);
		el.innerHTML = '';
		el.style.display = 'none';
	}
	catch(x) {}
}

// checknew
function checknew(params) {
	rand = parseInt(rand) + 1;
	var head = document.getElementsByTagName("head")[0];
	var oldS = document.getElementById('ibCheckNewScript'); 
	if (oldS != null) oldS.parentNode.removeChild(oldS);
	var script = document.createElement('script');
	script.id = 'ibCheckNewScript';
	script.type = 'text/javascript';
	script.src = "checknew.js.php?rand=" + rand + params;
	head.appendChild(script);
}

// funkce pro práci se "schránkou" v panelech
var schranka = {
	
	pocet_msg : 0,
	pocet_profile : 0,
	pocet_auto : 0,
	
	
	msg_add : function(id,text) {
		if(this.pocet_msg == 0) {
			ob('schr_msg_h').style.display = 'block';
		}
		
		if(ob('schr_msg_' + id)) {
			ob('panel-schranka-msg').removeChild(ob('schr_msg_' + id));	
		} else {
			this.pocet_msg ++;
		}
		
		x = document.createElement('a');
		x.href = 'messages-show.php?id=' + id;
		x.target = 'message';
		x.className = 'item';
		x.id = 'schr_msg_' + id;
		x.innerHTML = text;
		ob('panel-schranka-msg').insertBefore(x, ob('schr_msg_h').nextSibling);

		if(IE) {
			x.attachEvent("onclick", this.msg_click);
		} else {
			x.addEventListener("click", this.msg_click, false);
		}
		
		ob('panel-schranka').style.display = 'block';
	},
	
	msg_click : function(event) {
		if(!event.target) {
			event.target = event.srcElement;	
		}
		if(event.target) {
			ob('panel-schranka-msg').removeChild(event.target);
			schranka.pocet_msg--;
			if(schranka.pocet_msg <= 0) {
				schranka.pocet_msg = 0; // pro jistotu, kdyby se dostal do záporu
				ob('schr_msg_h').style.display = 'none'; // schování nadpisu
			}
		}
	},

	profile_add : function(id,text) {
		if(schranka.pocet_profile == 0) {
			ob('schr_profile_h').style.display = 'block';
		}
		
		if(ob('schr_profile_' + id)) {
			ob('panel-schranka-profile').removeChild(ob('schr_profile_' + id));	
		} else {
			this.pocet_profile ++;
		}
		
		x = document.createElement('a');
		x.href = 'profiles-show.php?id=' + id;
		x.target = 'profile';
		x.className = 'item';
		x.id = 'schr_profile_' + id;
		x.innerHTML = text;
		ob('panel-schranka-profile').insertBefore(x, ob('schr_profile_h').nextSibling);

		if(IE) {
			x.attachEvent("onclick", schranka.profile_click);
		} else {
			x.addEventListener("click", schranka.profile_click, false);
		}
		ob('panel-schranka').style.display = 'block';
	},
	
	profile_click : function(event) {
		if(!event.target) {
			event.target = event.srcElement;	
		}
		if(event.target) {
			ob('panel-schranka-profile').removeChild(event.target);
			schranka.pocet_profile--;
			if(schranka.pocet_profile <= 0) {
				schranka.pocet_profile = 0; // pro jistotu, kdyby se dostal do záporu
				ob('schr_profile_h').style.display = 'none'; // schování nadpisu
			}
		}
	},
	
	auto_add : function(id,text) {
		if(ob('schr_auto_' + id)) {
			ob('panel-schranka-auto').removeChild(ob('schr_auto_' + id));	
		} else {
			if(schranka.pocet_auto >= 4) {
				ob('panel-schranka-auto').removeChild(ob('panel-schranka-auto').lastChild);
			}	
			this.pocet_auto ++;
		}			
		
		x = document.createElement('a');
		x.href = 'profiles-show.php?id=' + id;
		x.target = 'profile';
		x.className = 'item';
		x.id = 'schr_auto_' + id;
		x.innerHTML = text;
		ob('panel-schranka-auto').insertBefore(x, ob('schr_auto_h').nextSibling);
		
		if(schranka.pocet_auto == 1) { // u prvního zobrazí nadpis
			ob('schr_auto_h').style.display = 'block';
		}
	}
}



// zobrazení a schování menu
var menu = {
	timeout : '',
	elt : '',
	zobraz : function(el) {
		if(menu.elt) {
			if(menu.elt != el) {
				menu.elt.className='';
				el.className = 'aktivni';
			}
		}	
		menu.elt = el;
		clearTimeout(menu.timeout);
		menu.timeout = setTimeout("menu.zobrazZ();",250);				
	},
	zobrazZ : function() {
		menu.elt.className = 'aktivni';
	},
	
	skryj : function(el) {
		menu.elt = el;
		clearTimeout(menu.timeout);
		menu.timeout = setTimeout("menu.skryjZ()",200);	
	},
	skryjZ : function() {
		menu.elt.className = '';
		menu.elt = '';
	}
	
}




// zobrazení "čísílek" v nabídce
function nab(co,kolik) {
	var x;
	x = document.getElementById('nab' + co).innerHTML;
	if(!x) {
		x = 0;
		document.getElementById('nab' + co).style.display='block';
	}
	x = parseInt(x) + parseInt(kolik);
	if(x+0 != x) x = 100;
	if(x > 99) {
		document.getElementById('nab' + co).innerHTML = '&infin;';
	} else {
		document.getElementById('nab' + co).innerHTML = x;
	}
}


function setvypadek() {
	if (top != undefined) {
		top.vypadek(true);
	} else {
		vypadek(true);
	}
}
function vypadek(show) {
	try {
		var vyp0 = document.getElementById('vypadek0');
		var vyp1 = document.getElementById('vypadek1');
		vyp0.style.display = vyp1.style.display = show ? '' : 'none';
	} catch (e) {}
}