function id(id){return document.getElementById(id);}

////////////////////////////////////////////////////
// photo gallery
////////////////////////////////////////////////////
pid = '1'; // photo id

function gallery(photoid,imgbig,img,gitem,alt)
{
	var galitm = id('photogallery').getElementsByTagName('div');
	
	for(i=0;i<galitm.length;i++)
	{
		galitm[i].className = 'img';
	}

	// add photo id
	pid = photoid;
	
	gitem.parentNode.className = 'img selected';

	var mainimg = id('mainfoto');
	mainimg.src = imgbig;
	mainimg.alt = mainimg.title = alt;

	var mainimglink = id('mainfotolink');
	mainimglink.href = img;
	mainimglink.alt = mainimglink.title = alt;

	return false;
}

function opengallery(photonum, photoid)
{
	if (photoid == '0')
	{
		currentphoto = id('photo'+pid).href;
		currentphotoalt = id('photo'+pid).alt;
		prevphotoid = 1;
	}
	else
	{
		currentphoto = id('photo'+photoid).href;
		currentphotoalt = id('photo'+photoid).alt;
		pid = photoid;
	}
	
	if (pid > 1)
	{
		prevphotoid = pid - 1;
		prevbutton = '<img id="prev_photo" onclick="return opengallery('+photonum+','+prevphotoid+');" src="http://www.housecz.ru/core/tpl/admin/img/prev_photo.gif" title="Предыдущая фотография" />';
	}
	else
	{
		prevbutton = '<img id="prev_photo" src="http://www.housecz.ru/core/tpl/admin/img/empty_button.png" title="" class="empty_button" />';
		prevphotoid = prevphotoid - 1;
	}
	
	if (photonum > pid)
	{
		nextphotoid = prevphotoid + 2;
		nextbutton = '<img id="next_photo" onclick="return opengallery('+photonum+','+nextphotoid+');" src="http://www.housecz.ru/core/tpl/admin/img/next_photo.gif" title="Следующая фотография" />';
	}
	else
	{
		nextbutton = '<img id="next_photo" src="http://www.housecz.ru/core/tpl/admin/img/empty_button.png" title="" />';
		nextphotoid = '';
	}

	id('bigphotospace').innerHTML = '<div id="photoshade">'+'<div id="photoframe">'+'<img src="'+currentphoto+'" alt=""  title="Закрыть" onclick="return closegallery(this);" id="bigphoto">'+prevbutton+''+nextbutton+'<img src="http://www.housecz.ru/core/tpl/admin/img/close_photo.gif" alt="Закрыть" title="Закрыть" id="close_photo" onclick="return closegallery(this);">'+'</div>'+'</div>';

	return false;
}

function closegallery()
{
	var mainimg = id('mainfoto');
	
	mainimg.src = currentphoto;
	
	currentphoto = currentphoto.replace(".jpg","_m.jpg");
	currentphoto = currentphoto.replace(".jpeg","_m.jpeg");
	currentphoto = currentphoto.replace(".png","_m.png");
	currentphoto = currentphoto.replace(".gif","_m.gif");
	mainimg.src = currentphoto;
	
	id('photoshade').style.display='none';
	//$("#photoshade").fadeOut("fast");
}


function currency_convert(origin)
{
    var origin_value = eval("document.currency.c"+origin+".value");
    var euro_equivalent = rate[origin];
    var v;
    for (i=0; i<rate.length; i++)
    {
		if (i!=origin)
		{
		    v = Math.round(rate[i]*origin_value/euro_equivalent*100)/100;
		    
		    if (isNaN(v))
		    {
		    	v = 0;
		    }
		    
		    eval("document.currency.c"+i+".value = "+v);
		}
    }
    return true;
}

