///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

var margines_gorny=0;		//odleglosc warstwy od gory strony
var wyrownanie_poziome=0;	//0 - warstwa w stalej odleglosci od lewej, 1 - wysrodkowanie, 2 - 2px od prawej
var zwloka=500;			//opoznienie przewijania (100 - 1000)
var speed=250;			//szybkosc przesuwu warstwy (25 - 500)
var id_warstwy="divCont";		//nazwa warstwy menu
var id_warstwy_2="divRight";	//nazwa warstwy linków po prawej
var offset=140;
///////////////////////////////////////////////////////////////

punkt_startowy=1;

///////////////////////////////////////////////////////////////

function znajdz_poziom(top)
{
  punkt_docelowy_y=top;
  ruch_warstwy()
}

///////////////////////////////////////////////////////////////

function wez_element(id)
{
  if (document.getElementById)
    tmp = document.getElementById(id)
  else if (document.all)
    tmp = document.all[id]
  else 
    tmp = document.layers[id];

  if(!tmp.style)
    tmp.style=tmp;

  return tmp;
}

///////////////////////////////////////////////////////////////

function ruch_warstwy()
{ 
  punkt_startowy=((1000/speed)*punkt_startowy+punkt_docelowy_y)/((1000/speed)+1);
  wez_element(id_warstwy_2).style.top=Math.round(punkt_startowy);
  wez_element(id_warstwy).style.top=Math.round(punkt_startowy);
  

  if(Math.round(punkt_startowy)!=punkt_docelowy_y)
    ruch=setTimeout("ruch_warstwy()",20)

  else ruch=0;
}

///////////////////////////////////////////////////////////////

function przesun_warstwe() 
{
winH = (bw.ns4||bw.ns6)? window.innerHeight : document.body.offsetHeight
	if(winH<540) window.resizeTo(800,600);

  if (document.all&&!window.opera)
    ofset_y_strony = document.body.scrollTop
  else
    ofset_y_strony = window.pageYOffset;

  e=wez_element(id_warstwy);
  gora_warstwy=parseInt(wez_element(id_warstwy).style.top);

  if (document.layers)
    szerokosc_warstwy = tmp.document.width
  else if (window.opera)
    szerokosc_warstwy = tmp.style.pixelWidth
  else
    szerokosc_warstwy = tmp.offsetWidth;

  if (document.all&&!window.opera)
    p = (document.body.clientWidth-szerokosc_warstwy)
  else
    p = (innerWidth-szerokosc_warstwy);

  if (wyrownanie_poziome)
    if (wyrownanie_poziome = 1)
      wez_element(id_warstwy).style.left = p/2
    else
      wez_element(id_warstwy).style.left = p-wyrownanie_poziome;
  
  if(ofset_y_strony>offset) 	
  if(gora_warstwy!=ofset_y_strony+margines_gorny)
   	znajdz_poziom(ofset_y_strony-offset);
  if(ofset_y_strony<offset)
	if(punkt_startowy!=1)znajdz_poziom(margines_gorny);
	


}

///////////////////////////////////////////////////////////////

function Begin()
{
  if (screen.height>=700)
    setInterval('przesun_warstwe()',zwloka);
}


////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////


function On(z,l)
  {
    l=document.layers?document.layers[l]:window
    l.document.images["R"+z].src="gifs/g"+z+"_on.gif";
  }

///////////////////////////////////////////////////////////////

function Off(z,l)
  {
    l=document.layers?document.layers[l]:window
    l.document.images["R"+z].src="gifs/g"+z+"_off.gif";
  }


///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////



///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////




function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}



function changeImage(imgName,imgObj) {
	document.images[imgName].src = eval(imgObj+".src")
}




//preload('sg0','g10_off.png')
//preload('sg1','g10_on.png') 





function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=lib_bwcheck()

/*** parametry które można konfigurować ***/

FoldNumber=14		//liczba linków głównych
var stayFolded = false			//zamknięcie/otwarcie submenu po kliknięciu na link główny false/true
foldImg =1;						//liczba potrzebnych obrazków (jeśli wpiszesz 0, usuń obrazki z foldera)
mainOffsetY = 0					//odstęp w pionie pomiędzy linkami w pixelach

//Domyślny obrazek.
//Pamiętaj o zmianie nazwy pliku jeśli zamierzasz użyć innego obrazka

//var unImg=new Image();
//unImg.src=''

//var exImg=new Image();					//zmienna obrazka
//exImg.src=''	//obrazek otwartego submenu

// NOTE: if you change the position of divCont from absolute to relative, you can put the foldoutmenu in a table.
// HOWEVER it will no longer work in netscape 4. If you wish to support netscape 4, you have to use absolute positioning.

/*** Nie zmieniać kodu poniżej tej linii ***/

// Jednostki miary  wyorzystane do pozycjonowania warstw.
var px = bw.ns4||window.opera?"":"px";

if(navigator.userAgent.indexOf('Opera')>-1 && document.getElementById){ //Opera 5 resize fix.
	scrX= innerWidth; scrY= innerHeight;
	document.onmousemove= function(){
		if(scrX<innerWidth-10 || scrY<innerHeight-10 || scrX>innerWidth+10 || scrY>innerHeight+10){
			scrX = innerWidth;
			scrY = innerHeight;
			initFoldout();
		}
	};
}

//konstrukcja obiektów
function makeMenu(obj,nest){
	nest= (!nest)?"":'document.'+nest+'.';
	this.el= bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):document.getElementById(obj);	
   	this.css= bw.ns4?this.el:this.el.style;
	this.ref= bw.ns4?this.el.document:document;		
	this.x= (bw.ns4||bw.opera5)?this.css.left:this.el.offsetLeft;
	this.y= (bw.ns4||bw.opera5)?this.css.top:this.el.offsetTop;
	this.h= (bw.ie||bw.ns6)?this.el.offsetHeight:bw.ns4?this.ref.height:bw.opera5?this.css.pixelHeight:0;
    this.vis= b_vis;
	this.hideIt= b_hideIt;
    this.showIt= b_showIt;
    this.moveIt= b_moveIt;
	return this
}
//metody obiektów
function b_showIt(){this.css.visibility='visible'}
function b_hideIt(){this.css.visibility='hidden'}
function b_vis(){if(this.css.visibility=='hidden' || this.css.visibility=='HIDDEN' || this.css.visibility=='hide') return true;}
function b_moveIt(x,y){this.x=x; this.y=y; this.css.left=this.x+px; this.css.top=this.y+px}

/************************************************************************************
Funkcja zwijająca i rozwijajaca submenu
************************************************************************************/
function menu(num){
	if(bw.bw){
		if (!stayFolded){
			for (var i=0; i<oSub.length; i++){
				if (i!=num){
					oSub[i].hideIt()
					//if (foldImg)oTop[i].ref["imgA"+i].src = unImg.src
				}
			}
			for(var i=1; i<oTop.length; i++){
				oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].h)
			}
		}
		if (oSub[num].vis()){
			oSub[num].showIt()
			//if (foldImg)oTop[num].ref["imgA"+num].src = exImg.src
		}else{
			oSub[num].hideIt()
			//if(foldImg)oTop[num].ref["imgA"+num].src = unImg.src
		}
		for(var i=1; i<oTop.length; i++){ 
			if (!oSub[i-1].vis()) oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].h+oSub[i-1].h+mainOffsetY) 
			else oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].h+mainOffsetY)
		}
	}
}

/*********************************************************************
Funkcja inicjująca - niczego nie modyfikować
*********************************************************************/
function initFoldout(){
	//sprawdzenie wersji Opery
	bw.opera5 = (navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?true:false
	if (bw.opera5) bw.ns6 = 0

	oTop = new Array()
	oSub = new Array()
	//tworzenie i ukrywanie
	for (var i=0; i<FoldNumber; i++){
		oTop[i] = new makeMenu('divTop'+i,'divCont')
		oSub[i] = new makeMenu('divSub'+i,'divCont.document.divTop'+i)
		oSub[i].hideIt()
	}
	
	//pozycjonowanie
	oTop[0].moveIt(0,0)
	for (var i=1; i<oTop.length; i++){
		oTop[i].moveIt(0, oTop[i-1].y+oTop[i-1].h+mainOffsetY)
	}
	
	//wyświetlanie
	oCont = new makeMenu('divCont')
	oCont.showIt()
	Begin();
}

//ładowanie
if(bw.bw) onload = initFoldout;

