
function toggle_anyfoto(id,cid,fw,fh,url)
{
var c = $('cont_'+cid),
     d = $('conf_'+cid),
     f = $('fotob_'+cid), t,r,nr;

//if (d.style.display != 'block')
	{
	stop_fotos();
	$('conv_'+cid).style.display = 'none';
	$('conm_'+cid).style.display = 'none';
	$('conc_'+cid).style.display = 'none';
	
	d.style.display = 'block';
	
		if (f.src.indexOf('thumb') < 0)
			{
			r = 1;
			
			if (fw > d.offsetWidth) 
				{
				nr = d.offsetWidth/fw;
				if (nr<r) r = nr;
				}
				
			if (fh > d.offsetHeight) 
				{
				nr = d.offsetHeight/fh;
				if (nr<r) r = nr;
				}
				
			fw = Math.ceil(fw*r);
			fh = Math.ceil(fh*r);
			
			if (fh < d.offsetHeight)
				{
				t = Math.round((d.offsetHeight - fh)/2);
				f.style.top = t+'px';
				}
			else
				f.style.top = '0px';
			
			if (fh < d.offsetWidth)
				{
				t = Math.round((d.offsetWidth - fw)/2);
				f.style.left = t+'px';
				}
			else
				f.style.left = '0px';
				
			c.style.display = 'none';
			//d.style.display = 'block';
			f.style.height = fh+'px';
			f.style.width = fw+'px';
			f.src=url+id;
			}
	
	fototim = setTimeout("next_animfoto("+cid+")",2000);
	}
//else
//	d.style.display = 'none';

return false;
}

var fototim = false;

function stop_fotos()
{
if (fototim) 
	{
	clearTimeout(fototim);
	fototim = false;
	}
}

function next_animfoto(id)
{
var i=$('fotob_'+id),p=i.src.split('id='),last=p[1];
ajax_request('get','index.php','action=foto&func=next&id='+last,
		function(req)
			{
			if (req.responseText != '')
				{
				var p=req.responseText.split(':');
				if (p[0] != last)
					toggle_anyfoto(p[0],id,p[1],p[2],'/index.php?action=foto&id=');
				}
			}
		,null);
}

function next_foto(id)
{
var i=$('fotob_'+id),p=i.src.split('id=');
stop_fotos();
ajax_request('get','index.php','action=foto&func=next&id='+p[1],
		function(req)
			{
			if (req.responseText != '')
				{
				var p=req.responseText.split(':');
				toggle_anyfoto(p[0],id,p[1],p[2],'/index.php?action=foto&id=');
				stop_fotos();
				}
			}
		,null);
return false;
}

function toggle_foto(id,cid,w,h)
{
stop_fotos();
var d = $('conf_'+cid);

if (d.style.display != 'block')
	return toggle_anyfoto(id,cid,w,h,'/index.php?action=foto&id=');
else
	{
	d.style.display = 'none';
	return false;
	}
}

function toggle_pfoto(id,cid,w,h)
{
return toggle_anyfoto(id,cid,w,h,'/index.php?action=foto&p=');
}

function toggle_desc(id)
{
if ($('cont_'+id).style.display != 'block')
	{
	stop_fotos();
	$('cont_'+id).style.display = 'block';
	$('conf_'+id).style.display = 'none';
	$('conm_'+id).style.display = 'none';
	$('conv_'+id).style.display = 'none';
	$('conc_'+id).style.display = 'none';
	}
else
	$('cont_'+id).style.display = 'none';
return false;
}

function toggle_com(id,frm)
{
if ($('conc_'+id).style.display != 'block')
	{
	stop_fotos();
	$('cont_'+id).style.display = 'none';
	$('conf_'+id).style.display = 'none';
	$('conm_'+id).style.display = 'none';
	$('conv_'+id).style.display = 'none';
	$('conc_'+id).style.display = 'block';
	if ($('conc_'+id).innerHTML == '')	
		{
		ajax_request('get', site_root, 'page=opinions&id='+id+'&frm='+frm,
			function(req)
			{
			replace_div('conc_'+id,req.responseText);
			},
			function(req)
			{
			alert('There was a problem with the request.(Code: ' + req.status + ')');
			});
		}
	}
else
	$('conc_'+id).style.display = 'none';
return false;
}

function toggle_video(id,src)
{
if ($('conv_'+id).style.display != 'block')
	{
	$('cont_'+id).style.display = 'none';
	$('conf_'+id).style.display = 'none';
	$('conm_'+id).style.display = 'none';
	$('conv_'+id).style.display = 'block';
	$('conc_'+id).style.display = 'none';
	$('conv_'+id).src = src;
	ajax_request('get',site_root,'action=stats&w=st_video&id='+id,null,null);
	}
else
	$('conv_'+id).style.display = 'none';
return false;
}

function toggle_map(id,src)
{
if ($('conm_'+id).style.display != 'block')
	{
	stop_fotos();
	$('cont_'+id).style.display = 'none';
	$('conf_'+id).style.display = 'none';
	$('conv_'+id).style.display = 'none';
	$('conm_'+id).style.display = 'block';
	$('conc_'+id).style.display = 'none';
	$('conm_'+id).src = src;
	ajax_request('get',site_root,'action=stats&w=st_map&id='+id,null,null);
	}
else
	$('conm_'+id).style.display = 'none';
return false;
}

function poner_com(id,frm)
{
if ($('conc_'+id).innerHTML == '')
	toggle_com(id,frm);
else
	{
	if ($('comf_'+id).style.display != 'block')
		$('comf_'+id).style.display = 'block';
	else
		$('comf_'+id).style.display = 'none';
	}
return false;
}

function enviar_com(frm,id)
{
var args='page=opinions&id='+id+form_get(frm);
setDisabled(frm,true);
$('comf_'+id).className = 'form_disabled';
$('comf_'+id).style.cursor = 'wait';	

ajax_request('get', site_root, args,
                     function(req)
						{
						$('comf_'+id).className = 'comform';
						$('comf_'+id).style.cursor = 'default';
						$('comf_'+id).disabled = false;
						replace_div('conc_'+id,req.responseText);
						},
                      function(req)
						{
						alert('There was a problem with the request.(Code: ' + req.status + ')');
						$('comf_'+id).className = 'comform';
						$('comf_'+id).style.cursor = 'default';
						$('comf_'+id).disabled = false;
						setDisabled(frm,false);
						}
                      );
return false;
}
