var tresc = "<div style=\"position:absolute; left:0; top:0; width:100%; height:100%; background-color: #000000; display:none;\" id=\"picturebox_div_01\"></div><div style=\"position:absolute; left:0; top:0; width:100%; height:100%; display:none;\" id=\"picturebox_div_02\"><br><TABLE BORDER=\"0\" WIDTH=\"100%\" HEIGHT=\"95%\"><TR><TD ALIGN=\"CENTER\" VALIGN=\"bottom\"><table border=\"0\" CELLPADDING=\"0\" CELLSPACING=\"10\" bgcolor=\"black\"><tr><td><table width=\"210\" height=\"220\" bgcolor=\"black\" 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 = 0;
var slideshow_time = 5000;
var images_path = "./img/"


// 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 = 0;		// 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;
	} else {
		document.getElementById('picturebox_table_02').style.height = 50;
		var text = picture_title;
		document.getElementById('picturebox_text').innerHTML = '<p style="font-size: 11;font-family: Tahoma;color: white;font-weight: normal;">' + text + '</p>';

		if (flaga == 0) {
			document.getElementById('picturebox_close').innerHTML = '<img src="' + images_path + 'close.gif" 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.gif" 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.gif" 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.gif" OnClick="close_picurebox()" alt="close picture" title="close picture" style="cursor: pointer;" border="0">';
				document.getElementById('picturebox_previous').innerHTML = '<img src="' + images_path + 'previous.gif" 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.gif" OnClick="close_picurebox()" alt="close picture" title="close picture" style="cursor: pointer;" border="0">';
				document.getElementById('picturebox_previous').innerHTML = '<img src="' + images_path + 'previous.gif" OnClick="album_previous()" alt="previous picture" title="previous picture" style="cursor: pointer;" border="0">';
				document.getElementById('picturebox_next').innerHTML = '<img src="' + images_path + 'next.gif" 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;
	document.getElementById("picturebox_div_01").style.top = 0;
	document.getElementById("picturebox_div_01").style.height = document.body.scrollHeight;
	document.getElementById("picturebox_div_01").style.width = document.body.scrollWidth;

	document.getElementById("picturebox_div_02").style.left = window_scroll[0];
	document.getElementById("picturebox_div_02").style.top = window_scroll[1];

	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;
	document.getElementById("picturebox_div_01").style.top = 0;
	document.getElementById("picturebox_div_01").style.height = document.body.scrollHeight;
	document.getElementById("picturebox_div_01").style.width = document.body.scrollWidth;

	document.getElementById("picturebox_div_02").style.left = window_scroll[0];
	document.getElementById("picturebox_div_02").style.top = window_scroll[1];

	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;
			y_table_dim = y_picture_dim;
		} else {
			document.getElementById('picturebox_table_01').style.height = y_table_dim + 25;
			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;
			y_table_dim = y_picture_dim;
		} else {
			document.getElementById('picturebox_table_01').style.height = y_table_dim - 25;
			y_table_dim = y_table_dim - 25;
		}

	} else {
		clearInterval(timer_id);
		timer_id = setInterval("mutacja_x();",20);
	}

}

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;
			x_table_dim = x_picture_dim;
		} else {
			document.getElementById('picturebox_table_01').style.width = x_table_dim + 25;
			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;
			x_table_dim = x_picture_dim;
		} else {
			document.getElementById('picturebox_table_01').style.width = x_table_dim - 25;
			x_table_dim = x_table_dim - 25;
		}

	} else {
		clearInterval(timer_id);
		window.document.images.picturebox_loader.width = x_picture_dim;
		window.document.images.picturebox_loader.height = y_picture_dim;
		window.document.images.picturebox_loader.src = picture.src;
		timer_id = setInterval("pasek();",50);
	}

}

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.gif">';

		document.getElementById('picturebox_table_02').style.height = 0;
		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()',100);
	}

}


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">';
		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;
	document.getElementById("picturebox_div_01").style.left = 0;

	// 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];
	} else {
		document.getElementById("picturebox_div_01").style.height = document.body.scrollHeight;
	}
	
	document.getElementById("picturebox_div_01").style.width = document.body.scrollWidth;

	document.getElementById("picturebox_div_02").style.left = window_scroll[0];
	document.getElementById("picturebox_div_02").style.top = window_scroll[1];

	document.getElementById("picturebox_div_01").style.display="";
	timer_id = setInterval("fade_in();",1);


}
