var kw=400;

function loadrest (id) {
    var list = document.getElementById(id).getElementsByTagName("img");
    if (! list)
        return;
    for (var i = 0; i < list.length; ++i)
					{
					if(list[i].id!="leasing")
						{
						list[i].style.opacity=1.0;
						list[i].style.filter = 'alpha(opacity=' + 100 + ')';
						list[i].onmouseover = mover;
						list[i].onmouseout = mout;
						}
					}
}

function loadrest_bg(id) {
    var list = document.getElementById(id).getElementsByTagName("li");
    if (! list)
        return;
    for (var i = 0; i < list.length; ++i)
					{
					if(list[i].className=='podemnu')
						{
						list[i].onmouseover = mover_bg_und;
						list[i].onmouseout = mout_bg_und;
						}
						else
						{
						if(list[i].id!="leasing")
							{
							list[i].onmouseover = mover_bg;
							list[i].onmouseout = mout_bg;
							}
						}
					}
}


function eventTrigger (e) {
    if (! e)
        e = event;
    return e.target || e.srcElement;
}

function mover(e)
{
 var obj = eventTrigger (e);
	obj.style.opacity=0.75;
	obj.style.filter = 'alpha(opacity=' + 75 + ')';
 return true;
}

function mout(e)
{
 var obj = eventTrigger (e);
	obj.style.opacity=1.0;
	obj.style.filter = 'alpha(opacity=' + 100 + ')';
 return true;
}

function mover_bg(e)
{
 var obj = eventTrigger (e);
	obj.style.background="url('img/but_und2or.png') 7px 0px no-repeat";
 return true;
}

function mout_bg(e)
{
 var obj = eventTrigger (e);
	obj.style.background="url('img/but_und1or.png') 7px 0px no-repeat";
 return true;
}


function mover_bg_und(e)
{
 var obj = eventTrigger (e);
	
 return true;
}

function mout_bg_und(e)
{
 var obj = eventTrigger (e);
	
 return true;
}


function next(id)
{
if(stan2<(plik.length-1))
	{stan2++;
show_photo('pliki/fotki/'+plik[stan2]+'.jpg');}
}

function prev(id)
{
if(stan2>0) 
	{
	stan2--;
	show_photo('pliki/fotki/'+plik[stan2]+'.jpg');
	}
}
 
function prev_pic(id)
{
if(pos>0) pos--;
pokaz_obr(id)
}
		
function next_pic(id)
{
if(pos<(plik.length-1)) pos++;
pokaz_obr(id)
}

		
function pokaz_obr(id)
{
var okno=document.getElementById('galeria');	
var img = new Image();
img.src='pliki/fotki/'+plik[pos]+'.jpg';
if(!img.complete)
		{
		okno.innerHTML='<img src="img/loading.gif" />';
			imgWait=setTimeout('pokaz_obr("'+id+'")', 250);
		}
		else
		{
		okno.innerHTML='';
		okno.appendChild(img);
		if((img.height>img.width)&&(img.height>kw))
						{
						dziel=img.width / img.height;
						img.height=kw;
						img.width=img.height*dziel
						}
						else
			if((img.width>img.height)&&(img.width>kw))
						{
						dziel=img.height / img.width;
						img.width=kw;
						img.height =dziel * img.width;
						}
						else
			if((img.width==img.height)&&(img.height>kw))
					{
					img.width=kw;
					img.height=kw;
					}
		if(img.height>0)
		var margin=(kw-img.height)/2;
		if(margin>0)
				img.style.marginTop=margin+"px";
		var okno2=document.getElementById('stan_gal');
		okno2.innerHTML=' zdjęcie <b>'+(pos+1)+'</b>/'+(plik.length);
		}
var gal_pasek=document.getElementById('wiersz_galerie');	
	if(window.plik===undefined)
			{
			gal_pasek.style.display='none'
			}
			else
			if(window.plik.length<=1)
				{
				gal_pasek.style.display='none'
				}
}
		

function pokaz_duzy_obr()
{
stan2=pos
show_photo('pliki/fotki/'+plik[pos]+'.jpg')
}


window.onload = function(e)
	{
	loadrest('baner');
	loadrest_bg('menu_right');
	pokaz_obr('galeria')
	}
	
var fotos=document.getElementById('wiersz_galerie').getElementsByTagName("img");
fotos[0].onclick=function(e)	
	{pokaz_duzy_obr(); }
fotos[1].onclick=function(e)	
	{prev_pic('galeria');}
fotos[2].onclick=function(e)
	{next_pic('galeria');}	
