var tresc = "<div style=\"position:absolute; left:0px; top:0px; width:100%; height:100%; background-color: #000000; display:none;\" id=\"picturebox_div_01\"></div><div style=\"position:absolute; left:0px; top:0px; width:100%; height:100%; display:none;\" id=\"picturebox_div_02\"><br /><table border=\"0\" width=\"100%\" height=\"95%\"><tr><td align=\"center\" valign=\"top\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"10\" bgcolor=\"white\"><tr><td><table width=\"210\" height=\"220\" bgcolor=\"white\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" id=\"picturebox_table_01\"><tr><td align=\"center\" valign=\"middle\"><span id=\"picturebox_content\"><span></td></tr><tr><td><table id=\"picturebox_table_02\" border=\"0\" cellpadding=\"0\"cellspacing=\"0\" width=\"100%\"><tr><td align=\"left\" valign=\"top\"><span id=\"picturebox_text\"><span></td><td width=\"25\" valign=\"middle\"><span id=\"picturebox_previous\"><span></td><td width=\"25\" valign=\"middle\"><span id=\"picturebox_next\"><span></td><td width=\"25\" valign=\"middle\"><span id=\"picturebox_close\"><span></td></tr></table></td></tr></table></td></tr></table></td></tr></table></div>";





document.write(tresc);



// Parametry do modyfikacji

var stopien_zaciemnienia = 75;

var slideshow_time = 5000;

var images_path = "./images/picturebox/"





// Zmienne ktorych nie modyfikujemy



var x_table_dim = 210, y_table_dim = 220;

var x_picture_dim = 0, y_picture_dim = 0;

var x_picture_rd = 0, y_picture_rd = 0;



var picture;

var picture_title;

var picture_url;

var picture_group;



var timer_id, time_id_slideshow;

var aktualny_stopien_zaciemnienia = 0;

var pasek_h = 0;



window_dim = new Array(4);

window_scroll = new Array(2);



album = new Array();

album_opis = new Array();

var album_pozycja = 0;



var flaga = 1;		// jesli zostanie wybrana opcja album lub slideshow (ale bedzie tam tylko jedno zdjecie) to flaga ustawiana jest na 0 i zdjecie jest wyswietlane jako pojedyncze picturebox

var slideshow = 0;	// jesli slidshow == 1 to album zamienia sie w pokaz slajdow



function keyend(e) {

	return false;

}



function kp(e) {

   if (typeof(Event)=='function') { //NN

      var kod=e.which;

      var shift=e.modifiers & Event.SHIFT_MASK;

      var alt=e.modifiers & Event.ALT_MASK;

      var ctrl=e.modifiers & Event.CONTROL_MASK;

   } else { //IE

      var kod=event.keyCode;

      var shift = event.shiftKey;

      var alt = event.altKey;

      var ctrl = event.ctrlKey;

   }



	if (album_pozycja == 0) {

		if (kod == 39) {

			album_next();

			document.onkeyup = keyend;

		} else if (kod == 27 || kod == 88) {

			close_picurebox();

		} else {

			// inny klawisz

		}

	} else if (album_pozycja == (album.length - 1)) {

		if (kod == 37) {

			album_previous();

			document.onkeyup = keyend;

		} else if (kod == 27 || kod == 88) {

			close_picurebox();

		} else {

			// inny klawisz

		}

	} else {

		if (kod == 37) {

			album_previous();

			document.onkeyup = keyend;

		} else if (kod == 39) {

			document.onkeyup = keyend;

			album_next();

		} else if (kod == 27 || kod == 88) {

			close_picurebox();

		} else {

			// inny klawisz

		}

	}

}



function getPageSize(){

   

   var xScroll, yScroll;

   

   if (window.innerHeight && window.scrollMaxY) {   

      xScroll = document.body.scrollWidth;

      yScroll = window.innerHeight + window.scrollMaxY;

   } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac

      xScroll = document.body.scrollWidth;

      yScroll = document.body.scrollHeight;

   } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari

      xScroll = document.body.offsetWidth;

      yScroll = document.body.offsetHeight;

   }



  

   var windowWidth, windowHeight;

   if (self.innerHeight) {   // all except Explorer

      windowWidth = self.innerWidth;

      windowHeight = self.innerHeight;

   } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode

      windowWidth = document.documentElement.clientWidth;

      windowHeight = document.documentElement.clientHeight;

   } else if (document.body) { // other Explorers

      windowWidth = document.body.clientWidth;

      windowHeight = document.body.clientHeight;

   }



   

   // for small pages with total height less then height of the viewport

   if(yScroll < windowHeight){

      pageHeight = windowHeight;

   } else {

      pageHeight = yScroll;

   }



   // for small pages with total width less then width of the viewport

   if(xScroll < windowWidth){   

      pageWidth = windowWidth;

   } else {

      pageWidth = xScroll;

   }





   arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)

   return arrayPageSize;

}



function getScrollXY() {

  var scrOfX = 0, scrOfY = 0;

  if( typeof( window.pageYOffset ) == 'number' ) {

    //Netscape compliant

    scrOfY = window.pageYOffset;

    scrOfX = window.pageXOffset;

  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {

    //DOM compliant

    scrOfY = document.body.scrollTop;

    scrOfX = document.body.scrollLeft;

  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {

    //IE6 standards compliant mode

    scrOfY = document.documentElement.scrollTop;

    scrOfX = document.documentElement.scrollLeft;

  }



   polozenie = new Array(scrOfX,scrOfY)

   return polozenie;

}







function close_picurebox() {

	album = new Array();

	album_opis = new Array();

	document.onkeyup = keyend;

	if (slideshow == 1) {

		clearInterval(time_id_slideshow);

	}

	document.getElementById("picturebox_div_02").style.display="none";

	album_pozycja = 0;

	slideshow = 0;

	flaga = 0;

	timer_id = setInterval("fade_out()",50);





}



function pasek() {

	if (pasek_h < 50) {

		pasek_h = pasek_h + 10;

		document.getElementById('picturebox_table_02').style.height = pasek_h + 'px';

	} else {

		document.getElementById('picturebox_table_02').style.height = 50 + 'px';

		var text = picture_title;

		document.getElementById('picturebox_text').innerHTML = '<span style="font-size: 11px;font-family: Tahoma;color: black;font-weight: normal;">&nbsp;' + text + '&nbsp;</span>';



		if (flaga == 0) {

			document.getElementById('picturebox_close').innerHTML = '<img src="' + images_path + 'close.jpg" onclick="close_picurebox()" alt="close picture" title="close picture" style="cursor: pointer;" border="0" />';

		} else {

			document.onkeyup=kp;

			if (album_pozycja == 0) {

				document.getElementById('picturebox_close').innerHTML = '<img src="' + images_path + 'close.jpg" onclick="close_picurebox()" alt="close picture" title="close picture" style="cursor: pointer;" border="0" />';

				document.getElementById('picturebox_previous').innerHTML = '';

				document.getElementById('picturebox_next').innerHTML = '<img src="' + images_path + 'next.jpg" onclick="album_next()" alt="next picture" title="next picture" style="cursor: pointer;" border="0" />';

				if (slideshow == 1) {

					time_id_slideshow = setTimeout('album_next()',5000);		

				}

			} else if (album_pozycja == (album.length - 1)) {

				document.getElementById('picturebox_close').innerHTML = '<img src="' + images_path + 'close.jpg" onclick="close_picurebox()" alt="close picture" title="close picture" style="cursor: pointer;" border="0" />';

				document.getElementById('picturebox_previous').innerHTML = '<img src="' + images_path + 'previous.jpg" OnClick="album_previous()" alt="previous picture" title="previous picture" style="cursor: pointer;" border="0" />';

				document.getElementById('picturebox_next').innerHTML = '';

				if (slideshow == 1) {

					time_id_slideshow = setTimeout('close_picurebox()',5000);		

				}

			} else {

				document.getElementById('picturebox_close').innerHTML = '<img src="' + images_path + 'close.jpg" onclick="close_picurebox()" alt="close picture" title="close picture" style="cursor: pointer;" border="0" />';

				document.getElementById('picturebox_previous').innerHTML = '<img src="' + images_path + 'previous.jpg" onclick="album_previous()" alt="previous picture" title="previous picture" style="cursor: pointer;" border="0" />';

				document.getElementById('picturebox_next').innerHTML = '<img src="' + images_path + 'next.jpg" onclick="album_next()" alt="next picture" title="next picture" style="cursor: pointer;" border="0" />';

				if (slideshow == 1) {

					time_id_slideshow = setTimeout('album_next()',5000);		

				}

			}

		}



		pasek_h = 0;

		clearInterval(timer_id);

	}

}



function album_next() {

	if (slideshow == 1) {

		clearInterval(time_id_slideshow);

	}



	album_pozycja ++;



	picture = new Image();

	picture.src = album[album_pozycja]



	x_picture_dim = 0;

	y_picture_dim = 0;



	window_scroll= getScrollXY();

	window_dim = getPageSize();



	picture_title =  "<b>Album - " + picture_group + ": " + (album_pozycja + 1) + "/" + album.length+ "</b> - " + album_opis[album_pozycja]



	// wyswietlenie warstwy

	document.getElementById("picturebox_div_01").style.top = 0 + 'px';

	document.getElementById("picturebox_div_01").style.top = 0 + 'px';

	document.getElementById("picturebox_div_01").style.height = document.body.scrollHeight + 'px';

	document.getElementById("picturebox_div_01").style.width = document.body.scrollWidth + 'px';



	document.getElementById("picturebox_div_02").style.left = window_scroll[0] + 'px';

	document.getElementById("picturebox_div_02").style.top = window_scroll[1] + 'px';



	timer_id = setInterval("fade_in();",1);

	

}



function album_previous() {

	if (slideshow == 1) {

		clearInterval(time_id_slideshow);

	}



	album_pozycja --;



	picture = new Image();

	picture.src = album[album_pozycja]



	x_picture_dim = 0;

	y_picture_dim = 0;



	window_scroll= getScrollXY();

	window_dim = getPageSize();



	

	picture_title =  "<b>Album - " + picture_group + ": " + (album_pozycja + 1) + "/" + album.length + "</b> - " + album_opis[album_pozycja]



	// wyswietlenie warstwy

	document.getElementById("picturebox_div_01").style.top = 0 + 'px';

	document.getElementById("picturebox_div_01").style.top = 0 + 'px';

	document.getElementById("picturebox_div_01").style.height = document.body.scrollHeight + 'px';

	document.getElementById("picturebox_div_01").style.width = document.body.scrollWidth + 'px';



	document.getElementById("picturebox_div_02").style.left = window_scroll[0] + 'px';

	document.getElementById("picturebox_div_02").style.top = window_scroll[1] + 'px';



	timer_id = setInterval("fade_in();",1);

}





function mutacja_y() {



	if (y_picture_dim > y_table_dim) {



		if ((y_picture_dim - y_table_dim) < 25) {

			document.getElementById('picturebox_table_01').style.height = y_picture_dim + 'px';

			y_table_dim = y_picture_dim;

		} else {

			document.getElementById('picturebox_table_01').style.height = (y_table_dim + 25) + 'px';

			y_table_dim = y_table_dim + 25;

		}



	} else if (y_picture_dim < y_table_dim) {



		if ((y_table_dim - y_picture_dim) < 25) {

			document.getElementById('picturebox_table_01').style.height = y_picture_dim + 'px';

			y_table_dim = y_picture_dim;

		} else {

			document.getElementById('picturebox_table_01').style.height = (y_table_dim - 25) + 'px';

			y_table_dim = y_table_dim - 25;

		}



	} else {

		clearInterval(timer_id);

		timer_id = setInterval("mutacja_x();",1);

	}



}



function mutacja_x() {



	if (x_picture_dim > x_table_dim) {



		if ((x_picture_dim - x_table_dim) < 25 ) {

			document.getElementById('picturebox_table_01').style.width = x_picture_dim + 'px';

			x_table_dim = x_picture_dim;

		} else {

			document.getElementById('picturebox_table_01').style.width = (x_table_dim + 25) + 'px';

			x_table_dim = x_table_dim + 25;

		}



	} else if (x_picture_dim < x_table_dim) {



		if ((x_table_dim - x_picture_dim) < 25 ) {

			document.getElementById('picturebox_table_01').style.width = x_picture_dim + 'px';

			x_table_dim = x_picture_dim;

		} else {

			document.getElementById('picturebox_table_01').style.width = (x_table_dim - 25) + 'px';

			x_table_dim = x_table_dim - 25;

		}



	} else {

		clearInterval(timer_id);

		//window.document.images.picturebox_loader.width = x_picture_dim + 'px';

		//window.document.images.picturebox_loader.height = y_picture_dim + 'px';

		document.getElementById('picturebox_content').innerHTML = '<img width="' + x_picture_dim + '" height="' + y_picture_dim + '" src="' + picture.src + '" alt="" />';

		//window.document.images.picturebox_loader.src = picture.src;

		timer_id = setInterval("pasek();",1);

	}



}



function fade_out() {

	if (0 < aktualny_stopien_zaciemnienia) {

		document.getElementById('picturebox_div_01').style.MozOpacity = (aktualny_stopien_zaciemnienia / 100); // Mozilla i FireFox

		document.getElementById('picturebox_div_01').style.KhtmlOpacity = (aktualny_stopien_zaciemnienia / 100); // Safari < 1.2

		document.getElementById('picturebox_div_01').style.opacity = (aktualny_stopien_zaciemnienia / 100); // Safari 1.2, nowszy FireFox i Mozilla

		document.getElementById('picturebox_div_01').style.filter = "alpha(opacity=" + aktualny_stopien_zaciemnienia + ")"; // Internet Explorer

		aktualny_stopien_zaciemnienia = aktualny_stopien_zaciemnienia - 20;

	} else {

		aktualny_stopien_zaciemnienia = 0;

		document.getElementById("picturebox_div_01").style.display="none";

		clearInterval(timer_id);

	}



}





function fade_in() {

	if (aktualny_stopien_zaciemnienia < stopien_zaciemnienia) {

		document.getElementById('picturebox_div_01').style.MozOpacity = (aktualny_stopien_zaciemnienia / 100); // Mozilla i FireFox

		document.getElementById('picturebox_div_01').style.KhtmlOpacity = (aktualny_stopien_zaciemnienia / 100); // Safari < 1.2

		document.getElementById('picturebox_div_01').style.opacity = (aktualny_stopien_zaciemnienia / 100); // Safari 1.2, nowszy FireFox i Mozilla

		document.getElementById('picturebox_div_01').style.filter = "alpha(opacity=" + aktualny_stopien_zaciemnienia + ")"; // Internet Explorer

		aktualny_stopien_zaciemnienia = aktualny_stopien_zaciemnienia + 20;

	} else {

		aktualny_stopien_zaciemnienia = (stopien_zaciemnienia - 1);

		clearInterval(timer_id);

		document.getElementById("picturebox_div_02").style.display="";

		document.getElementById('picturebox_content').innerHTML = '<img src="' + images_path + 'loading_pw.jpg" alt="loading ..." title="loading ..." />';



		document.getElementById('picturebox_table_02').style.height = 0 + 'px';

		document.getElementById('picturebox_text').innerHTML = '';

		document.getElementById('picturebox_close').innerHTML = '';

		document.getElementById('picturebox_previous').innerHTML = '';

		document.getElementById('picturebox_next').innerHTML = '';

		timer_id = setTimeout('picture_load()',20);

	}



}





function picture_load() {

	if (picture.complete) {

		var show_area = 0;

		y_picture_rd = picture.height;

		x_picture_rd = picture.width;



		// dopasowujemy do rozmiarow okna

		show_area = window_dim[2]-100;

		if (x_picture_rd > show_area) {

			y_picture_dim = Math.round((y_picture_rd * show_area) / x_picture_rd);

			x_picture_dim = show_area;

		} else {

			y_picture_dim = y_picture_rd;

			x_picture_dim = x_picture_rd;

		}



		show_area = window_dim[3]-150;

		if (y_picture_dim > show_area) {

			x_picture_dim = Math.round((x_picture_dim * show_area) / y_picture_dim);

			y_picture_dim = show_area;

		} else {

			y_picture_dim = y_picture_dim;

			x_picture_dim = x_picture_dim;

		}



		document.getElementById('picturebox_content').innerHTML = '<img src="' + images_path + 'loading.gif" name="picturebox_loader" id="picturebox_loader" alt="" />';

		timer_id = setInterval("mutacja_y();",20);

	} else {

		timer_id = setTimeout('picture_load()',100);		

	}

}





function picturebox_start(obiekt) {



	// uzyskanie adresu obrazka do powiekszenia z id obiektu img

	var indeks_01 = obiekt.id.indexOf("(");

	var indeks_02 = obiekt.id.indexOf(")");

	indeks_01 = indeks_01 + 1;

	var picture_url_click = obiekt.id.substring(indeks_01,indeks_02);

	picture_url = picture_url_click;



	// uzyskanie grupy tematycznej z id obiektu img

	indeks_01 = obiekt.id.indexOf("[");

	indeks_02 = obiekt.id.indexOf("]");

	indeks_01 = indeks_01 + 1;

	var picture_group_click = obiekt.id.substring(indeks_01,indeks_02);

	picture_group = picture_group_click;



	// zmienne potrzebne do sprawdzenia jak ma byc wysietlany obrazek - przy uzyciu wyr regularnych

	var picturebox_01 = /^album.*$/i;

	var picturebox_02 = /^slideshow.*$/i;

	// var picturebox_03 = /^picturebox.*$/i;



	if (picturebox_01.test(obiekt.id)) {

		// opcje dla - album

		var m = 0;

		for (var j=0; j < document.images.length; j++) {

			if (picturebox_01.test(document.images[j].id)) {

				indeks_01 = document.images[j].id.indexOf("[");

				indeks_02 = document.images[j].id.indexOf("]");

				indeks_01 = indeks_01 + 1;

				picture_group_click = document.images[j].id.substring(indeks_01,indeks_02);

				if (picture_group_click == picture_group) {

					indeks_01 = document.images[j].id.indexOf("(");

					indeks_02 = document.images[j].id.indexOf(")");

					indeks_01 = indeks_01 + 1;

					album[m] = document.images[j].id.substring(indeks_01,indeks_02);

					album_opis[m] = document.images[j].title;

					if (picture_url_click == album[m]) {

						album_pozycja = m;

					}

					m++;

				} else {

					// alert("ten obrazek nie nalezy do wybranej grupy tematycznej");

				}

			} else {

				// alert("ten obrazek nie nalezy do grupy - album");

			}

		}



		if (album.length == 1) {

			flaga = 0;

			picture_title = obiekt.title;

		} else {

			flaga = 1;

			picture_title = "<b>Album - " + picture_group + ": " + (album_pozycja + 1) + "/" + album.length + "</b> - " + obiekt.title;

		}



	} else if (picturebox_02.test(obiekt.id)){

		// opcje dla - slideshow

		slideshow = 1;



		var m = 0;

		for (var j=0; j < document.images.length; j++) {

			if (picturebox_02.test(document.images[j].id)) {

				indeks_01 = document.images[j].id.indexOf("[");

				indeks_02 = document.images[j].id.indexOf("]");

				indeks_01 = indeks_01 + 1;

				picture_group_click = document.images[j].id.substring(indeks_01,indeks_02);

				if (picture_group_click == picture_group) {

					indeks_01 = document.images[j].id.indexOf("(");

					indeks_02 = document.images[j].id.indexOf(")");

					indeks_01 = indeks_01 + 1;

					album[m] = document.images[j].id.substring(indeks_01,indeks_02);

					album_opis[m] = document.images[j].title;

					if (picture_url_click == album[m]) {

						album_pozycja = m;

					} 

					m++;

				} else {

					// alert("ten obrazek nie nalezy do wybranej grupy tematycznej");

				}

			} else {

				// alert("ten obrazek nie należy do grupy - slideshow");

			}

		}





		if (album.length == 1) {

			flaga = 0;

			picture_title = obiekt.title;

		} else {

			flaga = 1;

			picture_title = "<b>Album - " + picture_group + ": " + (album_pozycja + 1) + "/" + album.length + "</b> - " + obiekt.title;

		}



	} else {

		// kazdy inny obrazek jest wysietlany w standardowy sposob

		flaga = 0;

		picture_title = obiekt.title;

	}





	var widocznosc = 0;



	picture = new Image();

	picture.src = picture_url;



	window_scroll= getScrollXY();

	window_dim = getPageSize();



	//ustawienie przezroczystosci na "0"

	document.getElementById('picturebox_div_01').style.MozOpacity = (widocznosc / 100); // Mozilla i FireFox

	document.getElementById('picturebox_div_01').style.KhtmlOpacity = (widocznosc / 100); // Safari < 1.2

	document.getElementById('picturebox_div_01').style.opacity = (widocznosc / 100); // Safari 1.2, nowszy FireFox i Mozilla

	document.getElementById('picturebox_div_01').style.filter = "alpha(opacity=" + widocznosc + ")"; // Internet Explorer



	// wyswietlenie warstwy

	document.getElementById("picturebox_div_01").style.top = 0 + 'px';

	document.getElementById("picturebox_div_01").style.left = 0 + 'px';



	// gdy dokument jest nizszy niz wielkosc okna - to tlo jest wielkosci okna

	if (document.body.scrollHeight < window_dim[3]) {

		document.getElementById("picturebox_div_01").style.height = window_dim[3] + 'px';

	} else {

		document.getElementById("picturebox_div_01").style.height = document.body.scrollHeight + 'px';

	}

	

	document.getElementById("picturebox_div_01").style.width = document.body.scrollWidth + 'px';



	document.getElementById("picturebox_div_02").style.left = window_scroll[0] + 'px';

	document.getElementById("picturebox_div_02").style.top = window_scroll[1] + 'px';



	document.getElementById("picturebox_div_01").style.display="";

	timer_id = setInterval("fade_in();",1);





}
