var moving=false;
var timerId=false;
var thumbSel=-1;

var thumbFadeOut=0.5;
var thumbFadeOver=0.7;
var thumbFadeSelect=1.0;

function scrollDown()
{
	scroll(6, 'scrollDown()');
}

function scrollUp()
{
	scroll(-6, 'scrollUp()');
}

function scroll(offset, callback)
{
	if (moving == false) {
		if (timerId != false) {
			clearInterval(timerId);
			timerId = false;
		}
	} else {
		document.getElementById('filmstrip').scrollTop += offset;
		if (timerId == false) {
			timerId = setInterval(callback, 30);
		}
	}
}

$(function(){
	$('#newspanel').jScrollPane();
	$('#fscontainer .thumb').fadeTo("fast", thumbFadeOut);

	$('#fscontainer #up').mouseover(function() {
		moving = true;
		scrollUp();
	});

	$('#fscontainer #down').mouseover(function() {
		moving = true;
		scrollDown();
	});

	$('#fscontainer #up').mouseout(function() {		
		moving = false;
	});

	$('#fscontainer #down').mouseout(function() {		
		moving = false;
	});

	$('#filmstrip .thumb').mouseover(function() {
		var id = $(this).attr("id");
		if (id == thumbSel) return;
		$('#fscontainer #'+id).fadeTo("fast", thumbFadeOver);
	});

	$('#filmstrip .thumb').mouseout(function() {
		var id = $(this).attr("id");
		if (id == thumbSel) return;
		$('#fscontainer #'+id).fadeTo("normal", thumbFadeOut);
	});

	if (thumbSel != false) {
		$('#fscontainer #'+thumbSel).fadeTo("slow", thumbFadeSelect);
	}
});

function cl(gid, pid, caption, initial)
{
		if (thumbSel != false) {
			$('#fscontainer #'+thumbSel).fadeTo("normal", thumbFadeOut);
		}
		thumbSel = 't'+pid;
		if (initial != true) {
			$('#fscontainer #'+thumbSel).fadeTo("normal", thumbFadeSelect);
		}

        img = document.getElementById('mainphoto');
        cap = document.getElementById('maincaption');
        img.src = "images/watermark.php?gid=" + gid + "&pid=" + pid;
        cap.innerHTML = caption;
}

