function openProfile( pURL )
{
	var windowopts = "height=600,location,menubar,resizable,scrollbars,status,toolbar,width=800";
	var viewPath = window.location.pathname;
	
	if( viewPath.indexOf( "!" ) > 0 )
	{
		viewPath = viewPath.substring( 0, viewPath.lastIndexOf( "!" ) );
	}
	
	if( window.name == "profile" )
	{
		window.open( viewPath + "/" + pURL, "profile1", windowopts );
	}
	else
	{
		window.open( viewPath + "/" + pURL, "profile", windowopts );
	}
}

function closeProfile()
{
	if( opener.closed )
	{
		window.open( document.getElementById( 'refer' ).value );
		self.close();
	}
	else
	{
		self.close();
	}
}

function prevPage()
{
	var prevLink;
	
	if( document.getElementById )
	{
		prevLink = document.getElementById( "prevLink" );
		
		if( prevLink == null )
		{
			alert( "You are already at the beginning of the search results." );
			return false;
		}
		else if( prevLink.click )
		{
			prevLink.click();
			return true;
		}
		else
		{
			var plOnClick = prevLink.getAttributeNode( "onclick" );
			
			if( plOnClick != null )
			{
				eval( plOnClick.value );
				return true;
			}
		}
	}
	
	return false;
}

function nextPage()
{
	var nextLink;
	
	if( document.getElementById )
	{
		nextLink = document.getElementById( "nextLink" );
		
		if( nextLink == null )
		{
			alert( "You are already at the end of the search results." );
			return false;
		}
		else if( nextLink.click )
		{
			nextLink.click();
			return true;
		}
		else
		{
			var nlOnClick = nextLink.getAttributeNode( "onclick" );
			
			if( nlOnClick != null )
			{
				eval( nlOnClick.value );
				return true;
			}
		}
	}
	
	return false;
}

function goPrev()
{
	var oplinks;
	var urlPath;
	var currentProfile;
	var i;
	
	if( !opener )
	{
		return;
	}
	
	if( typeof opener.plinks == "undefined" )
	{
		setTimeout( "goPrev()", 1250 );
		return;
	}
	
	oplinks = opener.plinks;
	urlPath = window.location.href;
	
	i = urlPath.lastIndexOf( "/" );
	if( i > -1 )
	{
		currentProfile = urlPath.substring( i + 1 );
		urlPath = urlPath.substring( 0, i + 1 );
	}
	else
	{
		// ... the URL is messed up
		return;
	}
	
	i = oplinks.indexOf( currentProfile );
	
	if( i == 0 )
	{
		if( opener.prevPage() )
		{
			attempts = 0;
			// give the parent 1.5 secs to load
			setTimeout( "loadPrev( '" + urlPath + "', '" + currentProfile + "' )", 1250 );
			return;
		}
	}
	else
	{
		if( i < 0 )
		{
			//setTimeout( "goPrev()", 1000 );
			//window.location.href = urlPath + oplinks[oplinks.length - 1];
		}
		else
		{
			window.location.href = urlPath + oplinks[i - 1];
		}
	}
}

function goNext()
{
	var oplinks;
	var urlPath;
	var currentProfile;
	var i;
	
	if( !opener )
	{
		return;
	}
	
	if( typeof opener.plinks == "undefined" )
	{
		setTimeout( "goNext()", 1250 );
		return;
	}
	
	oplinks = opener.plinks;
	urlPath = window.location.href;
	
	i = urlPath.lastIndexOf( "/" );
	if( i > -1 )
	{
		currentProfile = urlPath.substring( i + 1 );
		urlPath = urlPath.substring( 0, i + 1 );
	}
	else
	{
		// ... the URL is messed up
		return;
	}
	
	i = oplinks.indexOf( currentProfile );
	
	if( i == oplinks.length - 1 )
	{
		if( opener.nextPage() )
		{
			attempts = 0;
			// give the parent 1.5 secs to load
			setTimeout( "loadNext( '" + urlPath + "', '" + currentProfile + "' )", 1250 );
			return;
		}
	}
	else
	{
		window.location.href = urlPath + oplinks[i + 1];
	}
}

function loadPrev( urlPath, currentProfile )
{
	var oplinks;
	var i;
	
	if( !opener )
	{
		return;
	}
	
	if( typeof opener.plinks == "undefined" )
	{
		setTimeout( "loadPrev( '" + urlPath + "', '" + currentProfile + "' )", 750 );
		return;
	}
	
	oplinks = opener.plinks;
	i = oplinks.indexOf( currentProfile );
	
	if( i < 0 )
	{
		window.location.href = urlPath + oplinks[oplinks.length - 1];
	}
	else if( i == ( oplinks.length - 1 ) )
	{
		window.location.href = urlPath + oplinks[oplinks.length - 2];
	}
	else
	{
		if( attempts++ > 5 )
		{
			return;
		}
		else
		{
			setTimeout( "loadPrev( '" + urlPath + "', '" + currentProfile + "' )", 750 );
			return;
		}
	}
}

function loadNext( urlPath, currentProfile )
{
	var oplinks;
	var i;
	
	if( !opener )
	{
		return;
	}
	
	if( typeof opener.plinks == "undefined" )
	{
		setTimeout( "loadNext( '" + urlPath + "', '" + currentProfile + "' )", 750 );
		return;
	}
	
	oplinks = opener.plinks;
	i = oplinks.indexOf( currentProfile );
	
	if( i > 0 )
	{
		if( attempts++ > 5 )
		{
			return;
		}
		else
		{
			setTimeout( "loadNext( '" + urlPath + "', '" + currentProfile + "' )", 750 );
			return;
		}
	}
	else if( i == 0 )
	{
		window.location.href = urlPath + oplinks[1];
	}
	else
	{
		window.location.href = urlPath + oplinks[0];
	}
}


function apl( pURL )
{
// addProfileLink function
	plinks[plinks.length] = pURL;
}

var plinks = new Array();
var attempts = 0;
