var hl;
var sp;
var img;
var la;
var ra;
var loaded = false;
var lastn = 0;

function photo_write() {
	document.write('<div class="hide_layer" id="hide_layer"></div><div class="bigphotos_out" id="bigphotos"><center><div class="bigphotos"><div class="bigphotos_in"><img src="images/left_off.png" id="left_arrow" onclick="nextphoto(-1);"><img src="images/right_off.png" id="right_arrow" onclick="nextphoto(1);"><div class="bigphotos_area"><a href="#" class="close" onclick="close_layer(); return false;">закрыть</a><img src="images/n.gif" id="image"></div></div></div></center></div>');
}

function photo_init() {
	hl = document.getElementById('hide_layer');
	sp = document.getElementById('bigphotos');
	img = document.getElementById('image');
	la = document.getElementById('left_arrow');
	ra = document.getElementById('right_arrow');
	loaded = true;
}

function showphoto(n) {
	if (!loaded)
		return false;
	img.src = 'flat/0'+n+'.jpg';
	hl.style.display = 'block';
	sp.style.display = 'block';
	lastn = n;
	update_arrow();
}

function close_layer() {
	hl.style.display = 'none';
	sp.style.display = 'none';
	img.src = 'images/n.gif';
	lastn = 0;
}

function nextphoto(d) {
	if (d == -1 && lastn > 1)
		showphoto(lastn - 1);
	if (d == 1 && lastn < 5)
		showphoto(lastn + 1);
}

function update_arrow() {
	if (lastn == 1)
		la.src = 'images/left_off.png';
	else
		la.src = 'images/left_on.png';
	if (lastn == 5)
		ra.src = 'images/right_off.png';
	else
		ra.src = 'images/right_on.png';
}
