function str_replace(search, replace, subject) {
    return subject.split(search).join(replace);
}

function SetEvents()
{
	selects = document.getElementsByTagName("IMG");
	details = document.getElementById('portf-details');
	
	for(I=0; I<selects.length; I++)
	{
		if((selects[I].className == "port-thumb"))
		{
			selects[I].onclick=onThumbDown;
		}
		
		if((selects[I].className == "download-thumb"))
		{
			selects[I].onclick=onDownloadDown;
		}
	}
}

function onThumbDown()
{
	var id = str_replace("thumb-","",this.getAttribute('id'));
	details = document.getElementById('portf-details');
	thumbdetails = document.getElementById('shortdesc-'+id);
	timestamp = document.getElementById('timestamp-'+id);
	title = document.getElementById('title-'+id);
	admin = document.getElementById('admin-'+id);
	
	details.innerHTML = "<h3>"+title.innerHTML+"</h3>";
	details.innerHTML = details.innerHTML + '<strong class="timestamp">' + timestamp.innerHTML + '</strong>';
	details.innerHTML = details.innerHTML + '<a class="showbig" href="images.php?id=' + id + '" rel="lightbox">View large</a>';
	if(admin)
	{
		details.innerHTML = details.innerHTML + ' | <a class="showbig" href="media.php?action=delete&amp;id=' + id + '" >Delete</a>'
	}
	details.innerHTML = details.innerHTML + "<h3>description</h3>"+thumbdetails.innerHTML;
	initLightbox();
}

function onDownloadDown()
{
	var id = str_replace("thumb-","",this.getAttribute('id'));
	details = document.getElementById('portf-details');
	thumbdetails = document.getElementById('shortdesc-'+id);
	timestamp = document.getElementById('timestamp-'+id);
	title = document.getElementById('title-'+id);
	admin = document.getElementById('admin-'+id);
	
	details.innerHTML = "<h3>"+title.innerHTML+"</h3>";
	details.innerHTML = details.innerHTML + '<strong class="timestamp">' + timestamp.innerHTML + '</strong>';
	details.innerHTML = details.innerHTML + '<a class="showbig" href="download.php?id=' + id + '" >Download</a>';
	
	if(admin)
	{
		details.innerHTML = details.innerHTML + ' | <a class="showbig" href="media.php?action=delete&amp;id=' + id + '" >Delete</a>'
	}
	
	details.innerHTML = details.innerHTML + "<h3>description</h3>"+thumbdetails.innerHTML;
	initLightbox();
}