


var zoom=0;

function swapimg(obj, url, url2, url_opis) {
	//obj = $(obj);
	//obj.src = url;
	if (zoom) {obj2 = obj; obj=my_img; }
	if ($(obj).src.replace(/.*\//, '') != url.replace(/.*\//, '')) {
		new Effect.Opacity(obj, {duration:0.5, from:1.0, to:0.0, afterFinish:function() {
			o = $(obj);
			Element.extend(o);
			o.setStyle({opacity: 0});
			o.hide();
			o.onload = function(){
				if (indicator) indicator.hide();
				o.setStyle({opacity: 0});
				new Effect.Opacity(obj, {duration:0.5, from:0.0, to:1.0, afterFinish:function() {
					o.style.opacity=1;
				},afterUpdate:function(){if(o.getStyle('opacity')>0.15)o.show();}
			});};
			if (url_opis) new Ajax.Updater('gal-desc', url_opis);
			if (zoom) {
				indicator.show();
				o.src = url2;
				$(obj2).src=url;
			} else {
				o.src = url;
				o.onclick = function(){zoomimg(url2);};
			}
		}
		});
	}	
}

var my_img=null;
var indicator=null;

function zoomimg(url) {
	//obj = $(obj);
	//obj.src = url;
	//var topobj = $('produktzoom');
	var topobj = $('bigimg');
	var bottomobj = $('gal-scrollerx');
	var top = Position.cumulativeOffset(topobj);
	var bottom = Position.cumulativeOffset(bottomobj);
	topleft = [top[0]-1,top[1]];
	//topleft = [top[0]-1,100];
	bottomright = [top[0]+bottomobj.offsetWidth, bottom[1]];
	var my_div = document.createElement('div');
	Element.extend(my_div);
	document.body.appendChild(my_div);
	my_div.hide();
	my_div.setStyle({
		position: 'absolute',
		left: topleft[0]+'px',
		top: topleft[1]+'px',
		width: (bottomright[0]-topleft[0]+5)+'px',
		height: (bottomright[1]-topleft[1])+'px',
		background: '#fff',
		opacity: 0,
		zIndex: 400
	});
	
	//alert(topleft+' '+bottomright);
	new Effect.Opacity(my_div, {duration:0.5, from:0.0, to:1.0, afterFinish:function() {
		my_div.setStyle({opacity: 1});
		indicator = document.createElement('img');
		Element.extend(indicator);
		indicator.src = 'cms-core/img/indicator.gif';
		indicator.setStyle({position:'absolute', top:topleft[1]+200+'px', left: topleft[0]+365+'px'});
		document.body.appendChild(indicator);
		my_img = document.createElement('img');
		Element.extend(my_img);
		my_img.setStyle({opacity: 0.0, cursor:'pointer'});
		my_img.hide();
		Element.hide('powieksz');
		my_div.appendChild(my_img);
		Event.observe(my_img, 'mouseover', function(event){Element.show('zmniejsz');followmouse('zmniejsz',event);}, false);
		Event.observe(my_img, 'mouseout', function(event){Element.hide('zmniejsz')}, false);
		Event.observe(my_img, 'mousemove', function(event){Element.show('zmniejsz');followmouse('zmniejsz',event)}, false);
		my_img.onload = function(){indicator.hide();new Effect.Opacity(my_img, {duration:0.5, from:0.0, to:1.0, afterFinish:function() {
				my_img.setStyle({opacity: 1});
			},afterUpdate:function(){if(my_img.getStyle('opacity')>0.15)my_img.show();}
		});};
		my_div.onclick = function(){
			new Effect.Opacity(my_img,{from:1,to:0,duration:0.5,afterFinish:function(){
				my_img.hide();
				Element.hide('zmniejsz');
				new Effect.Opacity(my_div, {from:1,to:0,duration:0.5,afterFinish:function(){
					my_div.hide();
				}});
				//$('bigimg').onmouseover = function(){alert(1);}
			} });
			zoom = 0;
		};
		my_img.src = url;
				
		
	},afterUpdate:function(){if(my_div.getStyle('opacity')>0.15)my_div.show();}
	});
	zoom = 1;
	return false;	
}



var isloaded=0;

if (!window.onloadlist) { window.onloadlist = "";}
window.onloadlist += "";
window.onload = function() { eval(window.onloadlist); }  

