// funkcje do obsługi zakładek

function ZakladkiClass(id)
{
	this.zakladki = Array();
	this.wybrana = null;
	this.id = id;
	this.ident = 'ZCID' + Math.floor(Math.random() * 1000000);
}

ZakladkiClass.prototype.klasa = function(typ, stan)
{
	if (typeof stan == 'undefined' || stan == '')
		return 'tab_' + this.id + '_tab_' + typ;

	if (stan == 'SF' && typ == 'left')
		return 'tab_' + this.id + '_tab_' + typ + '_selected_first';

	if (stan == 'S' || stan == 'SF')
		return 'tab_' + this.id + '_tab_' + typ + '_selected';

	if (stan == 'H')
		return 'tab_' + this.id + '_tab_' + typ + '_hover';
}

ZakladkiClass.prototype.ustawZakladke = function(id, stan)
{
	getElement(id + 'L').className = this.klasa('left', stan);
	getElement(id + 'M').className = this.klasa('middle', stan);
	getElement(id + 'R').className = this.klasa('right', stan);
}

ZakladkiClass.prototype.podswietlZakladke = function(id, over)
{
	if (id == this.wybrana)
	{
	    if (this.zakladki[0] == this.ident + id)
			var stan = 'SF';
	    else
			var stan = 'S';
	}
	else if (over)
		var stan = 'H';
	else
		var stan = '';

	getElement(this.ident + id + 'L').className = this.klasa('left', stan);
	getElement(this.ident + id + 'M').className = this.klasa('middle', stan);
//	getElement(this.ident + id + 'R').className = this.klasa('right', stan);
}

ZakladkiClass.prototype.poczatekListyZakladek = function(width, align)
{
	if (typeof width == 'undefined' || width == null)
		width = '100%';

	if (typeof align == 'undefined' || align == null)
		align = '';

	document.write('<TABLE ALIGN="' + align + '" WIDTH="' + width + '" CLASS="tab_' + this.id + '" CELLPADDING="0" CELLSPACING="0" BORDER="0">');

	document.write('<TR>');
//	document.write('<TD WIDTH="2"><IMG SRC="gfx/pixel.gif" WIDTH="2" HEIGHT="1" BORDER="0"></TD>');

//	if (getCookie('wybranaZakladka' + this.id))
//            this.zakladka = getCookie('wybranaZakladka' + this.id);
}

ZakladkiClass.prototype.koniecListyZakladek = function()
{
	document.write('<TD WIDTH="1" STYLE="display: block;" ID="' + this.ident + '_end" CLASS="' + this.klasa('left', (this.zakladki.length == 1 ? 'S' : '')) + '"><IMG SRC="gfx/pixel.gif" STYLE="width: 1px; height: 1px;" BORDER="0"></TD>');
	document.write('<TD WIDTH="100%"><IMG SRC="gfx/pixel.gif" WIDTH="1" HEIGHT="1" BORDER="0"></TD>');
	document.write('</TR>');
	document.write('</TABLE>');
}

ZakladkiClass.prototype.wstawZakladke = function(id, nazwa)
{
	this.zakladki.push(this.ident + id);

	if (this.zakladki.length == 1)
	{
                if (getCookie('wybranaZakladka' + this.id))
                    this.wybrana = getCookie('wybranaZakladka' + this.id);
		else
		    this.wybrana = id;
	}

	document.write('<TD ID="' + this.ident + id + 'L" WIDTH="' + (this.wybrana == id ? '11' : '1') + 
	'" CLASS="' + this.klasa('left', (this.wybrana == id ? 'SF' : '')) + 
	'"><IMG ID="' + this.ident + id + 'L_spacer" SRC="gfx/pixel.gif" STYLE="width: ' + (this.wybrana == id ? '11' : '1') + 'px; height: 1px;" BORDER="0"></TD>');
	
	document.write('<TD ID="' + this.ident + id + 'M" ONCLICK="' + this.id + '.pokazZakladke(\'' + id + '\');" CLASS="' + this.klasa('middle', (this.wybrana == id ? 'S' : '')) + '" ONMOUSEOVER="' + this.id + '.podswietlZakladke(\'' + id + '\', true);" ONMOUSEOUT="' + this.id + '.podswietlZakladke(\'' + id + '\', false);">&nbsp;&nbsp;&nbsp;' + nazwa + '&nbsp;&nbsp;&nbsp;</TD>');
	document.write('<TD ID="' + this.ident + id + 'R" WIDTH="11" STYLE="display: ' + (this.wybrana == id ? 'block' : 'none') + ';" CLASS="' + this.klasa('right', (this.wybrana == id ? 'S' : '')) + '"><IMG ID="' + this.ident + id + 'R_spacer" SRC="gfx/pixel_11x37.gif" STYLE="width: 11px; height: 37px;" BORDER="0"></TD>');
}

ZakladkiClass.prototype.wstawLink = function(id, nazwa, link)
{
	this.zakladki.push(this.ident + id);

	if (this.zakladki.length == 1)
	{
                if (getCookie('wybranaZakladka' + this.id))
                    this.wybrana = getCookie('wybranaZakladka' + this.id);
		else
		    this.wybrana = id;
	}

	document.write('<TD ID="' + this.ident + id + 'L" WIDTH="' + (this.wybrana == id ? '11' : '1') + 
	'" CLASS="' + this.klasa('left', (this.wybrana == id ? 'SF' : '')) + 
	'"><IMG ID="' + this.ident + id + 'L_spacer" SRC="gfx/pixel.gif" STYLE="width: ' + (this.wybrana == id ? '11' : '1') + 'px; height: 1px;" BORDER="0"></TD>');
	
	document.write('<TD ID="' + this.ident + id + 'M" ONCLICK="setCookie(\'wybranaZakladka' + this.id + '\', \'' + id + '\'); window.location.href = \'' + link + '\'" CLASS="' + this.klasa('middle', (this.wybrana == id ? 'S' : '')) + '" ONMOUSEOVER="' + this.id + '.podswietlZakladke(\'' + id + '\', true);" ONMOUSEOUT="' + this.id + '.podswietlZakladke(\'' + id + '\', false);">&nbsp;&nbsp;&nbsp;' + nazwa + '&nbsp;&nbsp;&nbsp;</TD>');
	document.write('<TD ID="' + this.ident + id + 'R" WIDTH="11" STYLE="display: ' + (this.wybrana == id ? 'block' : 'none') + ';" CLASS="' + this.klasa('right', (this.wybrana == id ? 'S' : '')) + '"><IMG ID="' + this.ident + id + 'R_spacer" SRC="gfx/pixel_11x37.gif" STYLE="width: 11px; height: 37px;" BORDER="0"></TD>');
}

ZakladkiClass.prototype.wstawTekst = function(nazwa)
{
	document.write('<TD CLASS="tab_' + this.id + '_tekst">' + nazwa + '</TD>');
}

ZakladkiClass.prototype.poczatekTresciZakladek = function(width, align)
{
	if (typeof width == 'undefined' || width == null)
		width = '100%';

	if (typeof align == 'undefined')
		align = '';

	document.write('<TABLE ALIGN="' + align + '" WIDTH="' + width + '" CLASS="tab_' + this.id + '_tabela" CELLPADDING="0" CELLSPACING="0" BORDER="0">');

//	document.write('<TR><TD CLASS="tab_' + this.id + '_tabela_left"><IMG SRC="gfx/pixel.gif" WIDTH="1" HEIGHT="1" BORDER="0"></TD><TD CLASS="tab_' + this.id + '_tabela_tresc">');
	document.write('<TR><TD CLASS="tab_' + this.id + '_tabela_tresc">');
}

ZakladkiClass.prototype.koniecTresciZakladek = function()
{
//	document.write('</TD><TD CLASS="tab_' + this.id + '_tabela_right"><IMG SRC="gfx/pixel.gif" WIDTH="1" HEIGHT="1" BORDER="0"></TD>');
	document.write('</TD>');
	document.write('</TR>');
	document.write('</TABLE>');
}

ZakladkiClass.prototype.poczatekZakladki = function(id)
{
	if (this.zakladki[0] == this.ident + id)
		document.write('<DIV CLASS="tab_' + this.id + '_menu" ID="' + this.ident + id + '" STYLE="display: block;">');
	else
		document.write('<DIV CLASS="tab_' + this.id + '_menu" ID="' + this.ident + id + '" STYLE="display: none;">');
}

ZakladkiClass.prototype.koniecZakladki = function()
{
	document.write('</DIV>');
}

ZakladkiClass.prototype.pokazZakladke = function(zakladka)
{
	getElement(this.ident + this.wybrana + 'L').style.width = '1px';
	getElement(this.ident + this.wybrana + 'L_spacer').style.width = '1px';

	getElement(this.ident + this.wybrana + 'R').style.display = 'none';

	getElement(this.ident + '_end').style.display = this.ident + this.wybrana == this.zakladki[this.zakladki.length - 1] ? 'block' : 'none';

	//

	if (typeof zakladka == 'undefined' || zakladka == '')
	{
		if (getCookie('wybranaZakladka' + this.id))
			zakladka = getCookie('wybranaZakladka' + this.id);
		else
			zakladka = this.wybrana;
	}

	setCookie('wybranaZakladka' + this.id, zakladka)

	this.wybrana = zakladka;

	for (i = 0; i < this.zakladki.length; i++)
	{
		getElement(this.zakladki[i]).style.display = this.ident + zakladka == this.zakladki[i] ? 'block' : 'none';

		this.ustawZakladke(this.zakladki[i], this.ident + zakladka == this.zakladki[i] ? 'S' + (this.ident + zakladka == this.zakladki[0] ? 'F' : '') : '');
	}

	//

	getElement(this.ident + this.wybrana + 'L').style.width = '11px';
	getElement(this.ident + this.wybrana + 'L_spacer').style.width = '11px';
	getElement(this.ident + this.wybrana + 'R').style.width = '11px';
	getElement(this.ident + this.wybrana + 'R_spacer').style.width = '11px';

	getElement(this.ident + this.wybrana + 'R').style.display = 'block';

	getElement(this.ident + '_end').style.display = this.ident + this.wybrana == this.zakladki[this.zakladki.length - 1] ? 'none' : 'block';
}
