function titleclick(){
	var titulo = document.getElementById('titulo');
	var imglinks = titulo.getElementsByTagName('a');
	for(var i=0;i<imglinks.length;i++){
		imglinks[i].onmouseover=function(){
			var image = this.getElementsByTagName('img')[0];
			image.src=image.src.replace('0','1');
			return;
		}
		imglinks[i].onmouseout=function(){
			var image = this.getElementsByTagName('img')[0];
			image.src=image.src.replace('1','0');
			return;
		}
	}
	return;	
}

function absposition(obj){
	var pos_x = 0;
	var pos_y = 0;
	while (obj){
		pos_x+= obj.offsetLeft;
		pos_y+= obj.offsetTop;
		obj = obj.offsetParent;
	}
	return [pos_x, pos_y];
}

function photoclick(){
	
	var corpo=document.getElementById('corpo');
	var foto=document.getElementById('foto');
	var loadbox=document.getElementById('msg');
	if(!corpo || !foto) return;
	
	var comment=foto.getElementsByTagName('p')[0];
	var image=foto.getElementsByTagName('img')[0];
	
	image.onload=function(){
		hidethis(loadbox);	//Hide loadbox
		hidethis(corpo);	//Hide corpo
		hidethis(foto);		//Show foto
		//hidethis('bsld');	//Show Slideshow button
		return true;
	}
	
	var piclinks=corpo.getElementsByTagName('a');
	for(var i=0;i<piclinks.length;i++){
		piclinks[i].onclick=function(){
			var posi = absposition(corpo);
			loadbox.style.left = posi[0] + 'px';
			loadbox.style.top = posi[1] + 'px';
			hidethis(loadbox);	//Show loadbox
			if (image.src==this.href) {
				image.onload();
				return false;
			}
			image.src=this.href;
			image.alt=this.title;
			image.title='Clique para retornar ās imagens';
			while (comment.firstChild) comment.removeChild(comment.firstChild);
			comment.appendChild(document.createTextNode(this.title));
			return false;
		}
	}
	
	foto.onclick=function(){
		hidethis(foto);		//Hide foto
		hidethis(corpo);	//Show corpo
		//hidethis('bsld');	//Hide Slideshow button
		return;
	}
}

window.onload=function(){
	photoclick();
	titleclick();
}
