window.number_of_foto = 3;
window.current_foto = 0;
window.foto_id = 0;

function get_foto_cnt () {
	var s = $_('scroll_box');
	var tds = s.getElementsByTagName('TD');
	
	var cnt = 0;
	
	for (var i=0; i<tds.length; i++) {
		if (tds[i].className == 'foto') {
			cnt ++;
		}
	}
	
	return cnt;
}

function scroll_left () {
	if (window.number_of_foto > 3) {
		window.number_of_foto --;
	}
	
	set_scroll ();
}

function scroll_right(ev) {
	
	var cnt = get_foto_cnt ();
	
	if (!ev) {
		var maxPos = cnt - 2;
		if (cnt < 6) {
			return;
		}		
		ev = false;
	} else {
		var maxPos = cnt - 1;
		if (cnt < 5) {
			return;
		}		
	}
	
	if (window.number_of_foto < maxPos) {
		window.number_of_foto ++;
	}
	

	set_scroll (ev);
}

function set_scroll (ev) {
	
	var cnt = get_foto_cnt ();
	var maxPos = (!ev) ? cnt - 2 : cnt - 1;
	
	var step = (!ev) ? 132 : 136;

	
	if (window.number_of_foto > maxPos) {
		window.number_of_foto = maxPos;
	}	
	
	var pos = window.number_of_foto;
	var value = pos * step - step * 3;
	
	var cur_value = $_('scroll_box').scrollLeft;
	if (cur_value != value) {
		var step = (value - cur_value) / 10;
		if (step > 0)
			step = Math.ceil(step);  
		else
			step = Math.floor(step);
		var new_value = cur_value + step;
		$_('scroll_box').scrollLeft = new_value;
		window.setTimeout('set_scroll ('+ev+')', 30);		
	}
}

function show_foto (id, pos) {
	$_('big_foto').src = '/' + dir_name + '/' + gallery_id + '/' + id + '.jpg';
	window.number_of_foto = pos;
	window.foto_id = id;
	
	event_page = window.event_page ? true : false;
	
	set_scroll (event_page);
	
	$_('pos').innerHTML = pos;
	window.current_foto = pos;

	$_('rate_it_big').style.visibility = $_('rate_it' + id).style.visibility;

	load_comments ();

	var mark = $_('mark' + id);
	
	if (!mark) return;

	var mark = mark.innerHTML.split(';');
	mark = mark.length > 1 ? mark[1] : mark[0];
	set_rate ('_big', mark);
}

function prev () {
	var pos = window.current_foto;
	if (pos < 2) {
		return false;
	}
	pos --;
	var el = $_('pos' + pos);
	var src = $$(el, 'img')[0].src;
	var ids = src.split('=');
	show_foto (ids[1], pos);
	return false;
}

function next () {
	var pos = window.current_foto;
	if (pos >= get_foto_cnt ()) {
		return false;
	}
	pos ++;
	var el = $_('pos' + pos);
	var src = $$(el, 'img')[0].src;
	var ids = src.split('=');
	show_foto (ids[1], pos);
	return false;
}