function makeImg(image, path, width, height) {
	var img = new Element('img', {
		'src': path+"/"+image+"&width="+width+"&height="+height,
		'width': width,
		'height': height,
		'styles': {
			'margin': '10px'
		}
	}).addEvent('click', function() {
			$('div_top').destroy();
			$('div_bottom').destroy();
			$('div_window').destroy();
			$('div_back').destroy();
			//overflow
			$(document.body).setStyle('overflow', 'auto');
		});
	return img;
}

function makeDivTop(height, xx) {
	var div_top = new Element('div', {
		'id': 'div_top',
		'width': xx+'px',
		'height': height+20+'px'
	});
	return div_top;
}

function makeDivBottom(xx, opis) {
	var div_bottom = new Element('div', {
		'id': 'div_bottom',
		'width': xx+'px',
		'styles': {
			'color': '#000000'
		}
	});
	div_bottom.set('html', opis);
	return div_bottom;
}

function makeDivWindow(xx, yy, ss, sizex) {
	var div_window = new Element('div', {
		'id': 'div_window',
		'styles': {
			'background-color': '#ffffff',
			'opacity': 1,
			'width': '2px',
			'height': '2px',
			'position': 'fixed',
			'text-align': 'center',
			'left': sizex.x/2-1+ss.x,
			'top': sizex.y/2-1+ss.y
		}
	});
	return div_window;
}

function makeDivBack(sizex, sizey) {
	var div_back = new Element('div', {
		'id': 'div_back',
		'styles': {
			'background-color': '#000000',
			'opacity': '0',
			'width': sizex.x,
			'height': sizey.y,
			'position' : 'absolute',
			'left': '0',
			'top': '0',
			'text-align': 'center'
		}
	});
	return div_back;
}

function selZoom(image, path, width, height, opis) {
	var xx = width+20;
	if(opis == "") {
		var yy = height+20;
	} else {
		var yy = height+80;
	}
	
	/*
	if ((navigator.userAgent.indexOf("MSIE 7.0")!=-1) || (navigator.userAgent.indexOf("MSIE 8.0")!=-1) || (navigator.userAgent.indexOf("MSIE 6.0")!=-1) || (navigator.userAgent.indexOf("MSIE 5.5")!=-1)) {
		var ss = $(document.body).getScroll();
	} else {
		//var ss = $(document.body).getScroll();
		ss.x = 0;
		ss.y = 0;
	}
	*/
	var ss = $(document.body).getScroll();
	ss.x = 0;
	ss.y = 0;
	
	//overflow
	$(document.body).setStyle('overflow', 'hidden');
	
	var sizex = $(document.body).getSize();
	var sizey = $('body').getSize();
	
	//div background
	var div_back = makeDivBack(sizex, sizey);
	div_back.set('morph', {
		duration: 250,
		transition: 'quad',
		onComplete: function() {
			//div window
			var div_window = makeDivWindow(xx, yy, ss, sizex);
			
			if ((navigator.userAgent.indexOf("MSIE 8.0")!=-1) || (navigator.userAgent.indexOf("MSIE 7.0")!=-1) || (navigator.userAgent.indexOf("MSIE 6.0")!=-1) || (navigator.userAgent.indexOf("MSIE 5.5")!=-1)) {
				div_window.setStyle('position', 'absolute');
			}
			
			div_window.set('morph', {
				duration: 750,
				transition: 'quad',
				onComplete: function() {
					$('div_window').set('morph', {
						duration: 750,
						transition: 'quad',
						onComplete: function() {
							//div dla obrazka
							var div_top = makeDivTop(height, xx);
							//obrazek
							var img = makeImg(image, path, width, height);
							//div dla opisu
							var div_bottom = makeDivBottom(xx, opis);
							
							div_top.inject($('div_window'));
							img.inject($('div_top'));
							
							div_bottom.inject($('div_window'));
						}
					}).morph({
						width: xx+'px',
						left: [sizex.x/2-1+ss.x, sizex.x/2-1-xx/2+ss.x]
					});
				}
			}).morph({
				height: yy+'px',
				top: [sizex.y/2-1+ss.y, sizex.y/2-1-yy/2+ss.y]
			}) 
			
			div_window.inject($(document.body));
		}
	}).morph({
		opacity: [0, 0.5]
	});
	div_back.inject($(document.body));
}
