//otwórz stronę
function loaddoc(link) {
var link;
window.location.href=link;
}

//otwarcie zdjęcia w nowym oknie
/*
function new_img(link, width, height) 
{
var link;
var width;
var height;
window.open('window.php?bimage='+link+'', 'foto' ,'left=20,top=20, width='+width+' , height='+height+', menubar=0, resizable=1, scrollbars=1');
}
*/

var newWindow = null
function new_win(link, width, height) 
{
	var link;
	var width;
	var height;
	if (!newWindow || newWindow.closed)
	{
		pos1 = link.indexOf("page=galeria");
		pos2 = link.indexOf("page=realizacje");

		if (pos1>0 || pos2>0) //zdjecia - bez menubar i tolbar
		newWindow = window.open(''+link+'', 'window' ,'left=0, top=0, width='+width+' , height='+height+', menubar=no, resizable=yes, toolbar=no, status=no, scrollbars=yes');
		else
		newWindow = window.open(''+link+'', 'window' ,'left=20, top=0, width='+width+' , height='+height+', menubar=yes, resizable=yes, toolbar=yes, scrollbars=yes');
	}
	else
	{
		newWindow.focus();
		newWindow.location.href=link;
	}
}

//duże zdjęcie w naklejanym div
function new_img(url, width, height)
{
	f = document.getElementById('fl');
	f.style.display = "block";
	e = document.getElementById('img_show');
	e.style.width = width+"px";
	e.style.height = height+"px";
	window.scroll(0,0);

	pos = url.indexOf("window.php"); //nie ma w url'u window.php - dodaj
	if (pos==-1) url = "window.php?bimage="+url;

	advAJAX.setDefaultParameters({
	onSuccess : function(obj) { document.getElementById(obj.tag).innerHTML = obj.responseText; },
	onError : function(obj) { document.getElementById(obj.tag).innerHTML = "Bład..."; }
	});
	advAJAX.get({ url:url, tag: "img_show" });
}


//schowaj banner na stronie głównej
function zamknij()
{
	var p = document.getElementById('fl');
	p.style.display="none"
}

// by Jan Bobrowski
function draglist(id)
{
	this.root = document.getElementById(id)
	if(!this.root) return
	this.root.draglist = this
	this.scan()
}

draglist.prototype.scan = function() {
	var o = this.root.firstChild
	this.items = []
	for(var i=0; o; o=o.nextSibling) {
		if(!o.tagName) continue
		o.onmousedown = this.down
		o.dl_idx = i
		this.items[i++] = o
		o.style.cursor = "default"
	}
}

draglist.prototype.yof = function(e) {
	var y = e.offsetTop
	while(e = e.offsetParent)
		y += e.offsetTop
	return y
}

draglist.prototype.down = function(e) {
	if(!e) e = window.event
	var o=this, c,l,y

	c = o.parentNode
	l = c.draglist
	if(l.items.length<=1) return true
	document.dl_dragged = o
	l.rooty = l.yof(c)
	y = l.yof(o)
	l.prevy = e.clientY
	l.handy = e.clientY - y + c.scrollTop
	l.origy = y - l.rooty

	document.onmousemove = l.move
	document.onmouseup = l.up
	return false
}

draglist.prototype.posfor = function(y) {
	var o,a=0,b=this.items.length,i=0
	y += this.rooty
	for(;;) {
		o = this.items[i]
		if(y < this.yof(o) + o.offsetHeight/2) b = i
		else a = i
		i = a+b>>1
		if(i == a) break
	}
	return b
}

draglist.prototype.move = function(e) {
	if(!e) e = window.event
	var o,c,l,y,m,d,i

	o = this.dl_dragged
	c = o.parentNode
	l = c.draglist
	y = e.clientY - l.rooty - l.handy

	m = c.offsetHeight-o.offsetHeight
	d = e.clientY - l.prevy
	l.prevy += d
	if(d < 0) {
		if(y < 0) c.scrollTop += y
	} else {
		if(y > m) c.scrollTop += y - m
	}
	y += c.scrollTop

	i = l.posfor(y + (d<0 ? 0 : o.offsetHeight))
	if(i<o.dl_idx || i>o.dl_idx+1) {
		c.removeChild(o)
		if(i < l.items.length)
			c.insertBefore(o, l.items[i])
		else
			c.appendChild(o)
		l.origy = l.yof(o) - l.rooty - (parseInt(o.style.top)||0)
		l.scan()
	}

	if(y<0) y=0; else {
		m = c.scrollHeight-o.offsetHeight
		if(y > m) y = m
	}
	o.style.top = (y - l.origy)+"px"

	return false
}

draglist.prototype.up = function(e) {
	if(!e) e = window.event
	var o,c,l

	o = this.dl_dragged
	c = o.parentNode
	l = c.draglist
	if(l.origy+o.offsetHeight > c.scrollTop+c.offsetHeight)
		c.scrollTop = l.origy+o.offsetHeight-c.offsetHeight
	if(l.origy < c.scrollTop)
		c.scrollTop = l.origy

	this.dl_dragged = null
	this.onmousemove = null
	this.onmouseup = null

	o.style.top = "0px"
	return false
}
