document.all ? ie=true: ie=false;

var big_photo=null;
var closeBigPhoto=null;
var zoom_photo=null;
var thumbs_div=null;
var thumbs=null;
var dimed=$('dimed');
var main=$('main');
var pre_img = new Image();

pre_img.onload=function(){
	if (this.ob){
		this.ob.className="big_photo";
		this.ob.src=pre_img.src;
	}
}


function ini(){
big_photo_ini();

if ($('menu_div')) {
	var poz=$('menu_div').childNodes;
	for (var i=0;i<poz.length;i++) {
		if (poz[i].nodeType==1) {
			if (poz[i].className!='menu_el_selected'){
				poz[i].onmouseover=function(){this.className='menu_el_hover'}
				poz[i].onmouseout=function(){this.className='menu_el'}
				poz[i].style.cursor="pointer";
			}
			poz[i].onclick=function(){document.location=this.getElementsByTagName('A')[0].href}
		}	
	}
}

if ($('zoom_photo')) {
	zoom_photo=$('zoom_photo');
	zoom_photo.onclick=ZamknijBigPhoto;
}

if ($('closeBigPhoto')) {
	closeBigPhoto=$('closeBigPhoto');
	closeBigPhoto.onclick=ZamknijBigPhoto;
}


if ($('thumbs_div')) {
	$('gallery_table').style.display="block";
	thumbs_div=$('thumbs_div');
	thumbs_div.loadPart=th_divLoadPart;
	thumbs_div.myOnscroll=th_divMyOnscroll;
	thumbs_div.onscroll=thumbs_div.myOnscroll;
	thumbs=thumbs_div.getElementsByTagName('IMG');
	thumbs_div.thumbs=thumbs;
	thumbs_div.ile=thumbs.length;
	thumbs_div.ile=thumbs.length;
	thumbs_div.zamieniono=0;
	thumbs_div.loadPart(0,10);
}
}	

function big_photo_ini(){
if ($('big_photo')) {
	big_photo=$('big_photo');
	big_photo.zoom=big_photoZoom;
	big_photo.change=big_photoChange;
	big_photo.onclick=big_photo.zoom;
	big_photo.style.cursor="pointer";
}
}


function $(id){
return document.getElementById(id);
}

function th_divMyOnscroll(){
this.onscroll=function(){}
for (var i=0;i<this.ile;i++){
	if (!this.thumbs[i].zamieniono) {
		var thTop=this.thumbs[i].offsetTop;
		var scrlPoz=this.scrollTop;
		var divH=this.offsetHeight;
		if ((thTop>(scrlPoz-300) && thTop<(scrlPoz+divH+300)) || (thTop>-120 && thTop<(divH+300))){
			this.thumbs[i].zamieniono=1;
			this.zamieniono++;
			this.thumbs[i].src=this.thumbs[i].getAttribute('src2');
			this.thumbs[i].style.cursor="pointer";
			if (this.zamieniono==this.ile) this.onscroll=function(){};
		}
	}
}
this.onscroll=this.myOnscroll;
}

function th_divLoadPart(from,ile){
var src2;
for (var i=from;i<(from+ile);i++){
	if (this.thumbs[i]){
		src2=this.thumbs[i].getAttribute('src2');
		if (!this.thumbs[i].zamieniono) {
		this.zamieniono++;
		this.thumbs[i].zamieniono=1;
		this.thumbs[i].src=src2;
		this.thumbs[i].style.cursor="pointer";
		}		
	}
}

}

function ZamknijBigPhoto(){
$('dimed').style.display='none';
$('main').style.opacity=1;
$('main').style.filter='alpha(opacity=100)';
if ($('gallery_table')) $('gallery_table').style.filter='alpha(opacity=100)';//stupid IE
}

function big_photoZoom(){
ob=this;
var main=$('main');
var dimed=$('dimed');
var popupphoto=$('popupphoto');
var zoom_photo=$('zoom_photo');

zoom_photo.src=ob.alt;
zoom_photo.onload=function(){
	main.style.opacity=0.2;
	if (ie){
		main.style.filter='alpha(opacity=20)';
		if ($('gallery_table')) $('gallery_table').style.filter='alpha(opacity=20)';
	}
	dimed.style.display='block';
	var height100=$('x100x100').offsetHeight;
	var heightZoom=zoom_photo.offsetHeight;
	if (height100>heightZoom){
		zoom_photo.style.marginTop=parseInt((height100-heightZoom)/2)+'px';
	} else {
		zoom_photo.style.marginTop="4px";
	}
}
}

function big_photoChange(src){
var srcget=src;
var imgWidth,imgHeight;
if (arguments[1]){
	imgWidth=arguments[1];
	srcget='thumb.php?maxw='+imgWidth+'&img='+src;
	if (arguments[2]){
		imgHeight=arguments[2];
		srcget+='&maxh='+imgHeight;
	}
}

ob=this;

ob.className="loader";
ob.alt=src;
pre_img.ob=ob;
ob.src='./res/loader.gif';
pre_img.src=srcget;
}