HOST_NAME = 'http://' + window.location.hostname + '/';

load_img = new Image();
load_img.src = HOST_NAME + 'moduls/gallery/images/loader.gif';

img2 = new Image();
img2.src = HOST_NAME + 'moduls/gallery/images/back.jpg';

img3 = new Image();
img3.src = HOST_NAME + 'moduls/gallery/images/forward.jpg';

img4 = new Image();
img4.src = HOST_NAME + 'moduls/gallery/images/close.jpg';

loader = '<div id="loading">' +

			'<a href="javascript:close();">' +

				'<img src="' + HOST_NAME + 'moduls/gallery/images/loader.gif" alt="loading..." border="0" />' +

			'</a>' + 

		'</div>';

document.write('<div id="gallery"></div>');
document.write(loader);
document.write('<div id="shadow"></div>');

var div = document.getElementById('gallery');
var loading = document.getElementById('loading');
var shadow = document.getElementById('shadow');

function gallery(image, id){
	div.style.opacity = 0;
	div.style.filter = "alpha(opacity=0)";

	// begin next image and previous image
	is_next_image = false;
	is_prev_image = false;
	if (id != 0) {
		try {
			var next_element = document.getElementById('image' + (id + 1));
			next_image = next_element.getAttribute("src");
			next_image = next_image.replace('_', '_w_');
			is_next_image = true;
		} catch (e) { }	
		
		try {
			var prev_element = document.getElementById('image' + (id - 1));
			prev_image = prev_element.getAttribute("src");
			prev_image = prev_image.replace('_', '_w_');
			is_prev_image = true;
		} catch (e) { }
	}
	// end next and previous image

	var ScrollPosition = document.documentElement.scrollTop; 
	shadowHeight = document.body.clientHeight;
	if(shadowHeight < document.documentElement.clientHeight){
		shadowHeight = document.documentElement.clientHeight;
	}	
	shadow.style.height = shadowHeight + "px";
	shadow.style.display = 'block';
	
	var object = document.getElementsByTagName('object');
	for(i=0;i<object.length;i++){
		object[i].style.visibility = 'hidden';
	}
	
	img = new Image();
 	img.src = image;

	if(navigator.appName == 'Netscape' || navigator.appName == 'Opera'){
		ScreenHeight_half = Math.round(window.innerHeight/2);
	}
	else if(navigator.appName == 'Microsoft Internet Explorer'){
		ScreenHeight_half = Math.round(document.documentElement.clientHeight/2);
	}
	else{
		ScreenHeight_half = Math.round(window.innerHeight/2);
	}
	
	loading.style.top = ScreenHeight_half + ScrollPosition - 8 + 'px';
	loading.style.display = 'block';

	var n=0;

	function galleryAlpha(){
		n += 0.1;
		div.style.opacity = n;
		div.style.filter = "alpha(opacity=" + n*100 + ")";
		if(n>1){
			if(meter != "undefined"){
				clearInterval(meter);
			}
		}
	}
	
	function ShowImage(){
		var ImgWidth  = img.width+20;
		var ImgHeight = img.height;
		var ImgBorder = 25;

		ImgWidth_half  = Math.round(ImgWidth/2);
		ImgHeight_half = Math.round(ImgHeight/2);

		div.style.top = ScreenHeight_half + ScrollPosition - ImgHeight_half - ImgBorder + 'px';
		div.style.marginLeft = '-'+ImgWidth_half+'px';
		div.innerHTML = '<a href="javascript:close();"><img class="g_image" src="'+image+'" /></a>';
		div.innerHTML += 
			'<a class="gallery_close" href="javascript:close();">' + 
				'<img border="0" src="' + HOST_NAME + 'moduls/gallery/images/close.jpg" alt="close" />' +
			'</a>';
			
		if (is_next_image) {
			div.innerHTML += 
				'<a class="gallery_button2" href="javascript:gallery(\'' + next_image + '\', ' + (id + 1) + ');">' + 
					'<img src="' + HOST_NAME + 'moduls/gallery/images/forward.jpg" alt="back" border="0" />' + 
				'</a>';
		}
		
		if (is_prev_image) {
			div.innerHTML += 
				'<a class="gallery_button1" href="javascript:gallery(\'' + prev_image + '\', ' + (id - 1) + ');">' + 
					'<img src="' + HOST_NAME + 'moduls/gallery/images/back.jpg" alt="forward" border="0" />' + 
				'</a>';
		}

		loading.style.display = 'none';
		div.style.display = 'block';
		
		meter = setInterval(galleryAlpha,50);
	}

	if(img.complete){
		ShowImage();
	}
	else{
		img.onload = function(){
			ShowImage();
		}
	}
}

function close(){
	div.innerHTML = '';
	loading.style.display = 'none';	
	div.style.display = 'none';
	shadow.style.display = 'none';
	div.style.opacity = 0;
	div.style.filter = "alpha(opacity=0)";
	shadow.style.opacity = 0.6;
	shadow.style.filter = "alpha(opacity=60)";
	
	var object = document.getElementsByTagName('object');
	for(i=0;i<object.length;i++){
		object[i].style.visibility = 'visible';
	}
}

