function start() {
	//start
	
	if(jskomShow&&$('komunikat')) {
		jskomAppear();
		$('komunikat').observe('click',jskomFadeOut);
	}
	showLogo();
}
var loga=new Array;
var urls=new Array;
var aktLogo=0;
function declareLogo(lo,ur) {
	loga.push(lo);
	urls.push(ur);
}
function showLogo() {
/*	for (var i=0;i<loga.length;i++) {
		$('logotypy').update('<a href="'+urls[i]+'" target="_blank"><img src="images/czlonkowie/'+loga[i]+'" border="0" /></a>');
	}
	*/
	aktLogo=0;
	$('logotypy').update('<a href="'+urls[aktLogo]+'" target="_blank"><img src="images/czlonkowie/'+loga[aktLogo]+'" border="0" /></a>');
	new PeriodicalExecuter(changeLogo,1.7);	
}

function changeLogo() {
	if (aktLogo<(loga.length-1)) aktLogo++;
	else aktLogo=0;
	$('logotypy').update('<a href="'+urls[aktLogo]+'" target="_blank"><img src="images/czlonkowie/'+loga[aktLogo]+'" border="0" /></a>');
	
   	//pe.stop();
}


function printPopUp(adres) {
	window.open(adres,'forum','toolbar=0,scrollbars=1,width=670,height=500');
}

window.onload = start;
function showSub(i) {
	$('submenu_'+i).show();
}
function hideSub(i) {
	$('submenu_'+i).hide();
}
function setText(oTextInput) {
	if(oTextInput.value=='') oTextInput.value = oTextInput.defaultValue;
}
function clearText(oTextInput) {
	if(oTextInput.value==oTextInput.defaultValue) oTextInput.value = '';
}

function isEmail(address) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   return(reg.test(address));
}

var okno = null;
function window_open(page,PosX,PosY,width,height)
{
  borderless = false;
  
  if(okno != null && !document.layers)
  {
    okno.close();
  }
  if(borderless && !document.layers)
  {
	okno = window.open(page, "", "fullscreen=0, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=yes, resizable=0");
	okno.resizeTo(w, s);
	okno.moveTo(PosX, PosY);
  }
  else
  {
	okno = window.open(page, "", "menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=no, copyhistory=no, width=" + width + ", height=" + height + ", left=" + PosX + ", top=" + PosY);
  }
  okno.focus();
  okno = null;
}
function window_open_scroll(page,PosX,PosY,width,height)
{
  borderless = false;
  
  if(okno != null && !document.layers)
  {
    okno.close();
  }
  if(borderless && !document.layers)
  {
	okno = window.open(page, "", "fullscreen=0, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=yes, resizable=0");
	okno.resizeTo(w, s);
	okno.moveTo(PosX, PosY);
  }
  else
  {
	okno = window.open(page, "", "menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=no, copyhistory=no, width=" + width + ", height=" + height + ", left=" + PosX + ", top=" + PosY);
  }
  okno.focus()
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function selectedRadioValue(oForm, sRadioName) {
	var retval = '';
	for(var i=0;i<oForm.elements.length;i++) {
		if(oForm.elements[i].type!='radio'||oForm.elements[i].name!=sRadioName) continue;
		if(oForm.elements[i].checked) retval = oForm.elements[i].value;
	}
	return retval;
}

var jskomShow=false;
var jskomZostaw=true;
var peJskom;
function jskomAppear() {
	try{
		//Effect.Appear('jskom');
		$('komunikat').show();
	}
	catch (exc) {
		$('komunikat').show();
	}
	if(!jskomZostaw) peJskom = new PeriodicalExecuter(function(peJskom) {
			jskomFadeOut();
		}, 4);
}
function jskomFadeOut() {
	try{
		Effect.Fade('komunikat');
		}
	catch (exc) {
		$('komunikat').hide();
	}
	//$('komunikat').update('');
	if(peJskom) peJskom.stop();
}

var img;
var galFotos = [];
var aktFoto = 0;
function setGal(fot,fotos) {
	if(typeof fotos=='object') galFotos = fotos;
	else galFotos = [];

	$('bigFotoContainer').show();
	aktFoto = 0;
	if(galFotos.length>0) {
		for(var i=0;i<galFotos.length;i++) {
			if(galFotos[i]==fot) aktFoto = i;
		}
	}
	pokazFotoGal(fot);
}
function pokazFotoGal(fot) {
	$('bigFotoImg').update('<img src="images/czekaj_pl.gif" border="0" />')
	img = new Element('img');
	img.id = 'theimage';
	img.observe('load', showimg);
	//document.body.appendChild(img);
	img.src = fot;
	//$('bigFotoImg').update('<img src="'+fot+'" border="0" />';
	$('bigFotoImg').show();
	fotoNav();
	//$('main').hide();	
}
function pokazFoto(fot) {
	$('bigFotoImg').update('<img src="images/czekaj_pl.gif" border="0" />')
	img = new Element('img');
	img.id = 'theimage';
	img.observe('load', showimg);
	//document.body.appendChild(img);
	img.src = fot;
	//$('bigFotoImg').update('<img src="'+fot+'" border="0" />';
	$('bigFotoImg').show();
	$('bigFotoContainer').show();
	//$('main').hide();
}
function showimg(evt) {
	$('bigFotoImg').hide();
	$('bigFotoImg').update(img);
	$('bigFotoImg').show();
	var dim = document.viewport.getDimensions();
	if(img.width>dim.width||img.height>dim.height-160) {
		var new_size = image_small_maker(img.width, img.height, dim.width, dim.height-160)
		img.setStyle({'width':new_size[0]+'px','height':new_size[1]+'px'});
	}
}
function wywalFoto() {
	$('bigFotoContainer').hide();
	$('bigFotoImg').hide();
	//$('main').show();
}
function fotoNav() {
	if(aktFoto>0) $('bigFotoPrev').show();
	else $('bigFotoPrev').hide();
	if(aktFoto<galFotos.length-1) $('bigFotoNext').show();
	else $('bigFotoNext').hide();
}
function prevFoto() {
	if(aktFoto<=0) return;
	aktFoto--;
	pokazFotoGal(galFotos[aktFoto]);
}
function nextFoto() {
	if(aktFoto>galFotos.length-1) return;
	aktFoto++;
	pokazFotoGal(galFotos[aktFoto]);
}

function image_small_maker(orig_width, orig_height, max_width, max_height) {
	var xRatio = max_width / orig_width; 
	var yRatio = max_height / orig_height; 
	var new_width = 0;
	var new_height = 0;
	if ( (orig_width <= max_width) && (orig_height <= max_height) ) { 
	 new_width = orig_width; 
	 new_height = orig_height; 
	} 
	else if ((xRatio * orig_height) < max_height) { 
	 new_height = Math.ceil(xRatio * orig_height); 
	 new_width = max_width; 
	} 
	else { 
		new_width = Math.ceil(yRatio * orig_width); 
		new_height = max_height; 
		}
	var output = [];
	output.push(Math.round(new_width));
	output.push(Math.round(new_height));
	return output;
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}