var W3CDOM = (document.getElementById && document.getElementsByTagName);

function reflow() {
	if (typeof(x)!="undefined") {
		x.style.display="none";
		x.style.display="block";
	}
}

function URLencode(str) {
	var result = "";
	
	for (i = 0; i < str.length; i++) {
		if (str.charAt(i) == " ") result += "+";
		else result += str.charAt(i);
	}
	
	return escape(result);
}

window.onload=Init;

var mouseOvers = new Array();
var mouseOuts = new Array();
currentThumb = 0;

// init thumbs mouseovers
function Init()
{
	if (!W3CDOM) return;
	
	nav = document.getElementById('thumbnails');
	if (nav) {
		blank = new Image();
		blank.src="grafika/pixel.gif";
		imgs = nav.getElementsByTagName('img');
		as = nav.getElementsByTagName('a');
		for (var i=0;i<imgs.length;i++)
		{
			imgs[i].onmouseover = mouseGoesOver;
			imgs[i].onmouseout = mouseGoesOut;
			imgs[i].onclick = showPhoto;
			if (i>0) imgs[i].className = "pointer";
			as[i].style.cursor = "default";
			as[i].onclick = no_action;
			var filename = imgs[i].src.replace(/\/dark_thumbnails\//g,"/thumbnails/");
			mouseOuts[i] = new Image();
			mouseOuts[i].src = imgs[i].src;
			mouseOvers[i] = new Image();
			mouseOvers[i].src = filename;
			imgs[i].number = i;
			if (i==0) imgs[0].src = mouseOvers[0].src;
		}
		ph=document.getElementById("photo");
		showPhoto();
	}
	
	x_band=document.getElementById("band-link");
}

function mouseGoesOver()
{
	this.src = mouseOvers[this.number].src;
}

function mouseGoesOut()
{
	if (this.number!=currentThumb) this.src = mouseOuts[this.number].src;
}

function bandGoesOver() {
	x_band.style.backgroundImage = "url('" + bandMouseOver.src + "')";
}
function bandGoesOut() {
	x_band.style.backgroundImage = "url('" + bandMouseOut.src + "')";
}

function no_action () {
	return false;
}

function showPhoto() {
	if (typeof(this.number)=="number") thisnumber=this.number;
	 else thisnumber=0;

	if (currentThumb!=thisnumber) {
		imgs[currentThumb].src=mouseOuts[currentThumb].src;
		imgs[currentThumb].className="pointer";
		currentThumb=thisnumber;
		ph.onclick=null;
		ph.src=blank.src;
		imgs[currentThumb].className="";
	}
	var filename = mouseOuts[thisnumber].src.replace(/\/dark_thumbnails\//g,"/normal/");
	ph.src = filename;
	ph.title="Kliknij, aby powiększyć";
	fullWidth=imgs[currentThumb].fullwidth;
	fullHeight=imgs[currentThumb].fullheight;
	ph.onclick=showFullSize;
	ph.className="pointer";
}

function showFullSize() {
	var pic_filename = this.src.substr(this.src.lastIndexOf("/normal/")+8);
	winURL = "full-size.php?img=" + URLencode(pic_filename) + "&photo_folder=" + URLencode(photo_folder);

	
	var width = fullWidth+10;
	var height = fullHeight+10;
	if (height>screen.availHeight-20) {
		height=screen.availHeight;
		width+=16;
		var scroll=1;
	} else {
		var scroll=0;
	}
	
	var x=Math.round(screen.availWidth/2 - width/2)
	var y=Math.round(screen.availHeight/2 - height/2 - 15)
	if (scroll) height-=25;
	if (x<0) var x=0
	if (y<0) var y=0

	var winName = gallery_name.replace(/-/, '') + currentThumb;
	winSettings="width="+width+ ",height="+height+ ",resizable=1,menubar=0,status=0,scrollbars=" + scroll + ",location=0,left="+x+ ",top="+y
	windowName=window.open(winURL,winName,winSettings);
	windowName.focus();
	blank = new Image();
	blank.src="grafika/pixel.gif";
}

function saveSize(thumbNo, fullWidth, fullHeight) {
	var x=document.getElementById("thumb"+thumbNo);
	x.fullwidth=fullWidth;
	x.fullheight=fullHeight;
}

function open_win(winURL) {
	var width=550;
	switch (winURL) {
		case "o_firmie.php": var height=350; var scroll=1; break;
		case "fotomodelki.php": var height=230; var scroll=0; break;
		case "portfolio.php": var height=220; var scroll=0; break;
		case "kontakt.php": var height=210; var scroll=0; break;
	}
	x=Math.round(screen.availWidth/2 - width/2)
	y=Math.round(screen.availHeight/2 - height/2)
	if (x<0) x=0
	if (y<0) y=0
	
	var winName = winURL.substring(0,winURL.lastIndexOf('.'));
	winSettings="width="+width+ ",height="+height+ ",resizable=1,menubar=1,status=0,scrollbars=" + scroll + ",location=0,left="+x+ ",top="+y
	windowName=window.open(winURL,winName,winSettings);
	windowName.focus();
}


function reklamaBank() {
	var width=635;
	var height=508;
	x=Math.round(screen.availWidth/2 - width/2)
	y=Math.round(screen.availHeight/2 - height/2)
	if (x<0) x=0
	if (y<0) y=0
	
	winSettings="width="+width+ ",height="+height+ ",resizable=1,menubar=0,status=0,scrollbars=0,location=0,left="+x+ ",top="+y
	windowName=window.open("reklama_bank_zdjec.php","rekamaBank",winSettings);
	windowName.focus();
	return false;
}
