function initPage()
{
	var thumbs = document.getElementById("gallery");
	active_img_id = "big1";
	allthumbs = [];
	opacity = new fx.Opacity("full" , {duration: 700, onComplete: function(){
		if(this.now == 0)
		{
			changeImage();
			this.custom(0.25,1);
		}
	}});

	if (thumbs){
		var tnodes = thumbs.getElementsByTagName("img");
		for (var i=0; i<tnodes.length; i++)
		{ 
			_parent = tnodes[i].parentNode;
			allthumbs.push(_parent.href.substr(_parent.href.indexOf("#") + 1));
			_parent.onclick = function()
			{
				fullImage(this.href.substr(this.href.indexOf("#") + 1));
			}
		}
	}
}

function fullImage(name)
{
	new_image = name;
	opacity.custom(1,0);		
}

function changeImage()
{
	var new_full = document.getElementById(new_image);
	var old_full = document.getElementById(active_img_id);	

	active_img_id = new_image;	

	if (old_full){
		old_full.className = "";
	}
	if (new_full){
		new_full.className = "active";
	}	
}

function next(){
	for (var i=0; i<allthumbs.length; i++)
	{
		if(allthumbs[i] == active_img_id)
		{
			if(allthumbs[i+1])
			{
				fullImage(allthumbs[i+1]);
			}
			else
			{
				fullImage(allthumbs[0]);				
			}
		}
	}	
}

function previous(){
	for (var i=0; i<allthumbs.length; i++)
	{
		if(allthumbs[i] == active_img_id)
		{
			if(allthumbs[i-1])
			{
				fullImage(allthumbs[i-1]);
			}
			else
			{
				fullImage(allthumbs[allthumbs.length-1]);				
			}
		}
	}	
}

if (window.attachEvent){
	window.attachEvent("onload", initPage);
	}
else if (window.addEventListener){
	window.addEventListener("load", initPage, false);
	}