//funkcje do podmiany zdjec
function fon(n){document.images[n].src='grafika/'+n+'1.gif';}
function foff(n){document.images[n].src='grafika/'+n+'.gif';}

//funkcja do wyswietlania popupu
var okno_pop='';
function popup(wi,he,uerel,alignx,aligny,scrol)
{
	// Bartosz Szczecinski
	// 20.04.2006
	// Opera 8.x nie obsluguje !okno_pop.closed
	if(okno_pop && okno_pop.closed==false) {
		okno_pop.close()
	}
	if(wi=='100%'){wi=screen.availWidth-30}
	if(he=='100%'){he=screen.availHeight-0}
	if(alignx=='left'){xx=0}
	else if(alignx=='right'){xx=(screen.availWidth-wi)-10}
	else{xx=(screen.availWidth-wi)/2}
	if(aligny=='top'){yy=0}
	else if(aligny=='bottom'){yy=(screen.availHeight-he)}
	else{yy=(screen.availHeight-he)/2}
	okno_pop=window.open(uerel, '_blank', 'scrollbars='+scrol+',height='+he+',width='+wi+',top='+yy+',left='+xx);
}

function blurall() {
	var links = document.getElementsByTagName('a');
	for (var i=0;i<links.length;i++){
		links[i].onfocus = blurme;
	}
}

function blurme()
{
	this.blur();
}


function printversion(id,path)
{
	var okno='';
	(okno && !okno.closed)?okno.close():'';
	he=400;
	wi=730;
	xx=(screen.availHeight-he)/2-10;
	yy=(screen.availWidth-wi)/2;
	okno=window.open('print_version.php?id='+id, '_blank', 'menubar=yes,scrollbars=yes,height='+he+',width='+wi+',top='+xx+',left='+yy);
}


/*ladowanie do casch-u zdjec
foto=new Array('pl','en');
menuA=new Array();menuB=new Array();
for(n=0;n<foto.length;n++){
menuA[n]=new Image();
menuA[n].src='grafika/'+foto[n]+'.gif';
menuB[n]=new Image();
menuB[n].src='grafika/'+foto[n]+'1.gif';
}
*/


function send_on(id) {
	document.getElementById('send_ok').style.display='none';
	document.getElementById('send_table').style.display='block';
	document.getElementById('send').style.display='block';
	if(document.getElementById('expand')) {
		document.getElementById('expand').value = id;
	}
}

function send_off() {
	document.getElementById('send').style.display='none';
}

function send_mail() {
	document.getElementById('send_table').style.display='none';
	document.getElementById('send_ok').style.display='block';

	if(document.getElementById('expand')) {
		var expand_value = document.getElementById('expand').value;
	}
	else {
		var expand_value = 0;
	}

	advAJAX.get({
		url: "ajax_backend.php",
		reciver_email : document.getElementById('f_email').value,
		sender_email : document.getElementById('f_nadawca_email').value,
		sender_name : document.getElementById('f_nadawca').value,
		content : document.getElementById('f_tresc').value,
		expand : expand_value,
		onSuccess : function(obj) {
			document.getElementById('send_table').style.display='none';
			document.getElementById('send_ok').style.display='block';
		},
		onError : function(obj) {

		}
	});

}

function expand(element) {
	var id = element.split('_');
	var arrow = document.getElementById('a_'+id[1]);
	var row = document.getElementById('row_'+id[1]);
	if(document.getElementById('row_'+id[1]).style.display=='block') {
		row.style.display='none';
		arrow.src = 'grafika/arrow_right.gif';
	}
	else {
		row.style.display='block';
		arrow.src = 'grafika/arrow_down.gif';
	}
}


function background_change(el, bg) {
	document.getElementById(el).style.backgroundImage = 'url('+bg+')';
}

function change_images(el, img) {
	el.src = img;
}

function flang(elem, img) {
	elem.src = 'grafika/'+img;
}

function showRSSHelp(obj) {
	document.getElementById('rssHelpA').href = obj.href;
	//document.getElementById('rssHelp').style.display='block';
	var el = $('rssHelp');
	if(el.style.display=='none') {
		el.style.display='block';
		el.slide.down(350, 10, 1);
	}
}


function slide(_el) {

	this.me = _el;
	this.speed = 1;
	this.frequency = 100;
	this.direction = 1;

	this.down = function(pixels, speed, frequency) {
		this.direction = 1;
		if(speed && speed != 0) this.speed = speed;
		if(frequency && frequency != 0) this.frequency = frequency;
		this.me.style.height = '0px';
		this.to = pixels;
		this.process();
	},

	this.up = function(pixels, speed, frequency) {
		this.direction = -1;
		if(speed && speed != 0) this.speed = speed;
		if(frequency && frequency != 0) this.frequency = frequency;
		this.to = pixels;
		this.process();
	}

	this.process = function() {

		var self = this;
		if((parseInt(self.me.style.height) * self.direction) < self.to) {
			self.me.style.height = parseInt(self.me.style.height) + (self.direction * self.speed) + 'px';
			setTimeout(function() { self.process(); }, self.frequency);
		}
	}
}

function $(elName) {
	var _el = document.getElementById(elName);
	_el.slide = new slide(_el);
	return _el;
}

var currentFloor = null;
function showFloor(floor) {
	var d = document.getElementById('lista_mieszkan').getElementsByTagName('DIV');
	for(var i = 0 ; i < d.length ; i++) {
		d[i].className = 'js';
	}
	
	var a = document.getElementById('lista_mieszkan').getElementsByTagName('A');
	for(var i = 0 ; i < a.length ; i++) {
		if(a[i].className.indexOf('floor') > -1) a[i].className = 'floor';
	}
		
	if(currentFloor != floor) {
		d[floor].className = '';
		document.getElementById('floor'+(floor+1)).className = 'floorOn';		
		currentFloor = floor;
	}
	else {
		currentFloor = null;
	}	
	
}