
function ajax_loader( obj ) 
{
	obj = obj || document.getElementById('ajax_loader');
	
	obj.style.display = 'block';
	obj.style.visibility = 'visible';
	obj.style.top = (document.body.offsetHeight / 2) + (window.pageYOffset || document.body.scrollTop)
	
	if( ! obj.loader ) {
		offset = 0;
		timer = setInterval( function() {
			obj.style.backgroundPosition = 'left -' + offset + 'px';
			offset = offset == 440 ? 0 : offset + 40;
		}, 50);
		obj.loader = timer;
	}
	
	return obj;
}

function onDOMready( handler )
{
	loading = setInterval(function(){
		if( document.getElementById('loaded') ){
			clearInterval( loading );
			handler();
		}
	}, 500);
}

onDOMready(
	function()
	{
		alpha = document.getElementById('alpha_bgc');
		image = document.getElementById('sshot');
		sshots = document.getElementById('images').getElementsByTagName('a');
		
		alpha.onclick = function()
		{
			this.style.display = 
			image.style.display = 
			window.loader.style.display = 'none'
		}
		
		for( i in sshots )
		{
			a = sshots[i];
			a.index = parseInt(i);
			a.onclick = function()
			{
				with( image.style )
				{
					left = Math.round( document.body.clientWidth/2 ) + 'px'
					top = Math.round( document.body.clientHeight/2 + (window.pageYOffset || document.body.scrollTop) ) - 40 + 'px'
				}
		
				window.loader = ajax_loader();
				
				thumb = this.firstChild;
				index = this.index;
				
				loader.style.visibility = 'visible';
				alpha.style.display = 'block'
				
				img = new Image;
				img.onload = function()
				{
					window.loader.style.visibility = 'hidden';
		
					img_show = image.getElementsByTagName('span')[0]
					img_show.alt = thumb.alt
					img_show.innerHTML = ''
					img_show.appendChild( this );
					img_show.onclick = function()
					{
						index = index < sshots.length - 1 ? index + 1 : 0 ;
						sshots[index].onclick();
					}
					
					image.getElementsByTagName('em')[0].innerHTML = (index + 1) +'. '+ thumb.alt;
					if( alpha.style.display == 'block' ) image.style.display = 'block'
				}
				img.src = this.href;
				
				return false;
			}
		}
	}
);

