
var profile_images_tmb = new Array();
var profile_images_img = new Array();
var profile_images_start = 0;
var profile_images_max_height = 500;

function profile_images_load( userid )
	{
	ajaxpack.getAjaxRequest( 'profile_images_data.php', 'user=' + userid + '&json=1', profile_images_process_ajax, 'txt' );
	}

function profile_images_process_ajax()
	{
	var myajax=ajaxpack.ajaxobj
	var myfiletype=ajaxpack.filetype
	if (myajax.readyState == 4)
	{ //if request of file completed
	if ( myajax.status == 200 || window.location.href.indexOf("http")==-1) 
	{ //if request was successful or running script locally
	
	// Code here - BEGIN

	var data = myajax.responseText.parseJSON();
	
	if ( data.error ) 
		{
		if ( data.nbpics == 1 )
			if ( data.img1.substr( 0, 17 ) == "profile_images_no" ) data.nbpics = 0;
		
		for( i = 0; i < data.nbpics; i++ )
			{
			profile_images_img[i] = data['img'+(i+1)];
			profile_images_tmb[i] = data['tmb'+(i+1)];
			if ( ( data['img'+(i+1)+'mbo'] ) || ( data['img'+(i+1)+'pdv'] ) )
				{
				profile_images_img[i] = 'dom/bakala.org/img/profile_images_no.png';
				profile_images_tmb[i] = 'dom/bakala.org/img/profile_images_no_tmb.png';
				}
			}
		}

	if ( data.nbpics == 0 )
		{
		var cell_image = document.getElementById( 'cell_image' );
		cell_image.innerHTML = '<IMG BORDER=0 SRC="dom/default/img/showpic.gif" STYLE="height: ' + profile_images_max_height + 'px; width: 500px;">';
		cell_image.style.backgroundImage = 'url( dom/bakala.org/img/profile_images_no.png )';
		cell_image.style.backgroundRepeat = 'no-repeat';
		cell_image.style.backgroundPosition = 'center top';
		}

	if ( data.nbpics > 1 ) profile_images_display_thumbs();
	if ( data.nbpics >= 1 ) profile_images_show_image( 0 );

	// Code here - END
	} 
	}
	}

function profile_images_display_thumbs()
	{
	var row_thumbs = document.getElementById( "row_thumbs" );

	while( row_thumbs.cells.length > 0 ) row_thumbs.deleteCell( -1 );

	if ( profile_images_img.length > 6 )
		{
		cell = row_thumbs.insertCell( -1 );
		if ( profile_images_start > 0 )
			cell.innerHTML = '<A HREF="javascript:profile_images_start--; profile_images_display_thumbs();"><IMG BORDER=0 SRC="\dom/bakala.org/img/profile_images_left.png"></A>';
			else cell.innerHTML = '<IMG SRC="dom/bakala.org/img/profile_images_left_disabled.png">';
		}

	for( i = profile_images_start; i < Math.min( profile_images_start + 6, profile_images_img.length ); i++ )
		{
		cell = row_thumbs.insertCell( -1 );
		cell.innerHTML = '<A HREF="javascript:profile_images_show_image( ' + i + ' );"><IMG BORDER=0 SRC="dom/default/img/showpic.gif" STYLE="height: 60px; width: 60px;"></A>';
		cell.style.backgroundRepeat = 'no-repeat';
		cell.style.backgroundPosition = 'center center';
		cell.style.backgroundImage = 'url( ' + profile_images_tmb[i] + ' )';
		}

	if ( profile_images_img.length > 6 )
		{
		cell = row_thumbs.insertCell( -1 );
		if ( profile_images_start + 6 < profile_images_img.length ) 
			cell.innerHTML = '<A HREF="javascript:profile_images_start++; profile_images_display_thumbs();"><IMG BORDER=0 SRC="dom/bakala.org/img/profile_images_right.png"></A>';
			else cell.innerHTML = '<IMG SRC="dom/bakala.org/img/profile_images_right_disabled.png">';
		}

	}

function profile_images_show_image( index )
	{
	var cell_image = document.getElementById( 'cell_image' );
	
	cell_image.innerHTML = '<IMG BORDER=0 SRC="dom/default/img/showpic.gif" STYLE="height: ' + profile_images_max_height + 'px; width: 500px;">';
	cell_image.style.backgroundImage = 'url( ' + profile_images_img[index] + ' )';
	cell_image.style.backgroundRepeat = 'no-repeat';
	cell_image.style.backgroundPosition = 'center top';
	}


