/*-----------------------------------------
	projekt: PGS
	plik: 'funct.js'
	data utw.: 2005.09.26  15.41
	data ost. modyf.:
	autor: Tomasz Ryczanik,
		   Dariusz Krzeminski
  -----------------------------------------*/


function display_foto(file,width,height) {
	win = window.open('',"popup",'width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,left,top'); win.document.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><link href="lib/main.css" type="text/css" rel="stylesheet" /><title>Fotografia</title></head><body><table width="'+ width +'" cellpadding="0" cellspacing="0"><tr><td width="'+ width +'" height="'+ height +'"><a href="javascript:window.close()"><img src="' + file + '" alt="Zamknij okno" /></a></td></tr></table></body></html>'); win.document.close();
	win.focus();
}


function dcmail(co) {
	var cemail=unescape(co);
	var email = '';
	for(var ii=0;ii<cemail.length;ii++) 
	email += String.fromCharCode((cemail.charCodeAt(ii)+(ii%16)));
	
	return(email);
}


function mkmail(co) {
	var cemail=co.href.split('#')[1];
	if(typeof(cemail) != 'undefined') 
	co.href='mailto:'+dcmail(cemail); 
}


alpha_speed = 20;

	if (navigator.appName.indexOf("Netscape") != -1 && parseInt(navigator.appVersion) >= 5) {
		browser = 2;
		version = 0;
	} else if (navigator.appName.indexOf("Microsoft") != -1 && parseInt(navigator.appVersion) >= 4) {
		browser = 1;
		version = parseFloat(navigator.appVersion.substr(navigator.appVersion.indexOf("MSIE") + 4));
	} else {
		browser = 0;
		version = 0;
	}

function _get_object(id) {
	return document.getElementById(id);
}


function _set_timeout(id, exec, time) {
	id_object = _get_object(id);
	id_object.timeout = 
		setTimeout(exec, time);
	return id_object.timeout;
}


function _clear_timeout(id) {
	id_object = _get_object(id);
	clearTimeout(id_object.timeout);
}


function _get_visible(id) {
	id_object = document.getElementById(id);

	switch (browser) {
		case 1:
		case 2:
			return id_object.style.visibility == 'visible'; //	return id_object.style.visibility == 'show';
	}
}

function _set_visible(id, visible) {
	id_object = document.getElementById(id);

	switch (browser) {
		case 1:
		case 2:
			id_object.style.visibility = visible ? 'visible' : 'hidden'; return; //	id_object.style.visibility = visible ? 'show' : 'hide'; return;
	}
}


function _get_alpha(id) {
	id_object = document.getElementById(id);
	switch (browser) {
		case 1:	return id_object.filters.alpha.opacity;
		case 2:	return id_object.style.MozOpacity * 100;
	}
}


function _set_alpha(id, alpha) {
	id_object = _get_object(id)
	if (alpha < 0) alpha = 0; else if (alpha > 100) alpha = 100;
	switch (browser) {
		case 1:	id_object.filters.alpha.opacity = alpha; 
			return;
		case 2:	id_object.style.MozOpacity = alpha / 100; 
			return;
	}
}


function alpha_in(id) {
	alpha = _get_alpha(id);
	alpha += alpha_speed;
	if (alpha > 100) alpha = 100;
	_set_alpha(id, alpha);
	if (alpha < 100) setTimeout("alpha_in('" + id + "');", 50);
}


function alpha_out(id) {
	alpha = _get_alpha(id);
	alpha -= alpha_speed;
	if (alpha < 0) alpha = 0;
	_set_alpha(id, alpha);
	if (alpha > 0) setTimeout("alpha_out('" + id + "');", 50);
}


function alpha_go(id, go) { 

	switch (browser) {
		case 1:	if (version < 6) return;
		case 2:	break;
	}

	_clear_timeout(id);
	alpha = _get_alpha(id);
	if (go > alpha + alpha_speed) alpha += alpha_speed; else if (go < alpha - alpha_speed) alpha -= alpha_speed; else alpha = go;
	_set_alpha(id, alpha);
	if (alpha != go) _set_timeout(id, "alpha_go('" + id + "', " + go + ");", 50);
}


function menu_show(id, show, time) {
	_clear_timeout(id);
	if (time == null || time == 0)  _set_visible(id, show);
	else _set_timeout(id, "_set_visible('" + id + "', " + show + ");", time * 1000);
}


function menu_alpha_go(id, go) {

	switch (browser) {
		case 1:	if (version < 6) if (go == 0) menu_show(id, false, 0.2); else menu_show(id, true); 
			return;
		case 2:	break;
	}

	_clear_timeout(id);
	
	visible = _get_visible(id);
	alpha = _get_alpha(id);

	if (go > alpha + alpha_speed) alpha +=alpha_speed; else if (go < alpha - alpha_speed) alpha -= alpha_speed; else alpha = go;
	_set_alpha(id, alpha);

	if (visible && !alpha) _set_visible(id, false);
	else if (!visible && alpha) _set_visible(id, true);
	if (alpha != go) _set_timeout(id, "menu_alpha_go('" + id + "', " + go + ");", 50);
}


var _popup_alert = '';

function _popup_click(e) {
	switch (browser) {
		case 1: /*alert(_popup_alert);*/ return false;
		case 2: break;
	}
}

function popup_lock(text) {
	_popup_alert = text;
	switch (browser) {
		case 1:	document.oncontextmenu = _popup_click; break;
		case 2: break;	
	}
}

function menu_image(object, image) {
		/*alert(object);*/
//	object.img = image;
		
}

function menu_array(menu_array, k) {
	for (i = 0; i < menu_array.length; i++) {
		menu_show(menu_array[i], false);
	};
	menu_show(menu_array[k], true);
}
