// detekcja przegladarki
var ns4 = (document.layers)? true:false;
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
var ie5 = false;
if (ie4)
{
	if((navigator.userAgent.indexOf('MSIE 5')> 0)||(navigator.userAgent.indexOf('MSIE 6')> 0)||window.opera)
	{
		ie5=true;
	}
	if (ns6)
	{
		ns6=false;
	}
}
if((ns4)||(ie4)||(ns6))
{
	document.onmousemove=mouseMove;
	if (ns4) document.captureEvents(Event.MOUSEMOVE)
}

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];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		index_05_over = newImage("images/index_05-over.gif");
		index_07_over = newImage("images/index_07-over.gif");
		preloadFlag = true;
	}
}

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

// wielkosc okienka przegladarki
function browsewidth()
{
	if (ns4 || ns6)
	{
        available_width=innerWidth;
    } else {
        available_width=document.body.clientWidth;
    }
	return available_width
}

function browseheight()
{
	if (ns4 || ns6)
	{
        available_height=innerHeight;
    } else {
        available_height=document.body.clientHeight;
    }
	return available_height
}

noweokno=null;
function okno(url,nazwa,x,y,scroll,resize) {
	if (noweokno)
	{
		noweokno.close();
	}
	if (nazwa==null)
	{
		nazwa = '';
	}
	if (scroll==null)
	{
		scroll=0;
	}
	if (resize==null)
	{
		resize=0;
	}
	if (x!=null)
	{
		x1=((screen.availWidth/2)-(x/2)); y1=((screen.availHeight/2)-(y/2));
		noweokno=window.open(url,nazwa,'toolbar=0,location=0,status=0,menubar=0,scrollbars='+scroll+',resizable='+resize+',left='+x1+',top='+y1+',width='+x+',height='+y);
	} else
	{
		window.open(url,nazwa,'toolbar=0,location=0,status=0,menubar=0,scrollbars='+scroll+',resizable=yes,left=0,top=0,width='+(screen.availWidth-40)+',height='+(screen.availHeight-40));
	}
}

fotaokno=null;
function fotka(url,nazwa,x,y,scroll) {
	if (nazwa==null)
	{
		nazwa = '';
	}
	if (scroll==null)
	{
		scroll=0;
	}
	if (noweokno)
	{
		fotaokno.close();
	}
	if (x!=null)
	{
		x1=((screen.availWidth/2)-(x/2)); y1=((screen.availHeight/2)-(y/2));
		if (x1<0)
		{
			x1=0; scroll=1; x=screen.availWidth-50; y=y+40;
		}
		if (y1<0)
		{
			y1=0; scroll=1; y=screen.availHeight-50; x=x+40;
		}
		fotaokno=window.open(url,nazwa,'toolbar=0,location=0,status=0,menubar=0,scrollbars='+scroll+',resizable=0,left='+x1+',top='+y1+',width='+x+',height='+y);
		fotaokno.document.open();
		fotaokno.document.write ('<html>'); 
		fotaokno.document.write ('<head>'); 
		fotaokno.document.write ('<title>Foto</title>'); 
		fotaokno.document.write ('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">'); 
		fotaokno.document.write ('</head>'); 
		fotaokno.document.write ('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">'); 
		fotaokno.document.write ('<p align="center"><a href="javascript:void(null)" onClick="window.close();"><img src="'+url+'" border="0"></a></p>'); 
		fotaokno.document.write ('</body>'); 
		fotaokno.document.write ('</html>'); 
		fotaokno.document.close();
		fotaokno.focus();
	} else
	{
		fotaokno=window.open(url,nazwa,'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0');
		fotaokno.document.open();
		fotaokno.document.write ('<html>'); 
		fotaokno.document.write ('<head>'); 
		fotaokno.document.write ('<title>Foto</title>'); 
		fotaokno.document.write ('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">'); 
		fotaokno.document.write ('</head>'); 
		fotaokno.document.write ('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">'); 
		fotaokno.document.write ('<p align="center"><a href="javascript:void(null)" onClick="window.close();"><img src="'+url+'" border="0"></a></p>'); 
		fotaokno.document.write ('</body>'); 
		fotaokno.document.write ('</html>'); 
		fotaokno.document.close();
		fotaokno.focus();
	}
}

function mouseMove(e)
{
	if((ns4)||(ns6)){ox=e.pageX;oy=e.pageY;}
	if(ie4){ox=event.x;oy=event.y;}
	if(ie5){ox=event.x+self.document.body.scrollLeft;oy=event.y+self.document.body.scrollTop;}
}

id4 = null;
function foto_opis(onoff,opis_txt,kolor_ram,kolor_tlo,kolor_txt)
{
	if (onoff == 'on')
	{
		if (opis_txt != null)
		{
			Kod = '<table border="0" class="tekst"><tr><td align="center" valign="middle" style="padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; background: '+kolor_tlo+'; border-top: 1px solid '+kolor_ram+'; border-bottom: 1px solid '+kolor_ram+'; border-left: 1px solid '+kolor_ram+'; border-right: 1px solid '+kolor_ram+';"><p style="color: '+kolor_txt+';">'+opis_txt+'</td></tr></table>';
			if (ns4)
			{
				document.layers['opis'].document.open();
				document.layers['opis'].document.write(Kod);
				document.layers['opis'].document.close();
			}
			if (ns6)
			{
				document.getElementById('opis').innerHTML = Kod;
			}
			// IE
			if (ie4 || ie5)
			{
				document.all['opis'].innerHTML = Kod;
			}
		}
		id4 = setTimeout("foto_opis('on');",10);
		warstwa('opis','on',ox+5,oy+5);
	} else
	{
		if (id4)
		{
			clearTimeout(id4);
		}
		warstwa('opis');
	}
}

var message_int = false;
function message(onoff,time)
{
	if (ns4)
	{
		szer = document.layers['message_layer'].document.width;
		wys = document.layers['message_layer'].document.height;
	}
	// Netscape 6.x Code
	if (ns6)
	{
		szer = document.getElementById('message_layer').scrollWidth;
		wys = document.getElementById('message_layer').scrollHeight;
	}
	// IE
	if (ie4 || ie5)
	{
		szer = document.all['message_layer'].scrollWidth;
		wys = document.all['message_layer'].scrollHeight;
	}
	if (onoff == 'on')
	{
		if (time==null)
		{
			czas = 1000 * 20;
		} else
		{
			czas = 1000 * time;
		}
		x = ((browsewidth()/2)-(szer/2)); y = ((browseheight()/2)-(wys/2));
		if (x<0)
		{
			x = 0;
		}
		if (y<0)
		{
			y = 0;
		}
		warstwa('message_layer','on',x,y);
		id3 = setTimeout("message();",czas);
		message_int = true;
	} else
	{
		if (message_int)
		{
			clearTimeout(id3);
			message_int = false;
		}
		warstwa('message_layer');
	}
}

var init_menu = false;
function menu(layer,onoff,obj,x,y)
{
	if (onoff == "on")
	{
		if (init_menu)
		{
			clearTimeout(id2);
			if (layer != init_menu)
			{
				warstwa(init_menu);
				init_menu = layer;
			}
		}
		if (obj != null)
		{
			warstwa(layer,'on',getposOffset(obj, "left")+x,getposOffset(obj, "top")+y);
		} else
		{
			warstwa(layer,'on');
		}
	}
	if (onoff == "off")
	{
		id2 = setTimeout("menu('"+layer+"')",1000);
		init_menu = layer;
	}
	if (onoff == null)
	{
		warstwa(layer);
		init_menu = false;
	}
}

function warstwa(nazwa,wlacz,pozx,pozy)
{
	// Netscape 4.x Code
	if (ns4)
	{
		objWarstwa = document.layers[nazwa];
	}
	// Netscape 6.x Code
	if (ns6)
	{
		objWarstwa = document.getElementById(nazwa).style;
	}
	// IE
	if (ie4 || ie5)
	{
		objWarstwa = document.all[nazwa].style;
	}

	if (pozx && pozy)
	{
		objWarstwa.left = pozx;
		objWarstwa.top = pozy;
	}

	if (objWarstwa && (wlacz == 'off' || wlacz == null))
	{
		if (ns4)
		{
			objWarstwa.visibility="hide";
		} else
		{
			objWarstwa.visibility="hidden";
		}
	}

	if (objWarstwa && (wlacz == 'on'))
	{
		if (ns4)
		{
			objWarstwa.visibility="show";
		} else
		{
			objWarstwa.visibility="visible";
		}
	}
}
