var index = null;
var result = null;

function displayWebCamImage(url)
{
	document.webcam.src = url;
}

function displayWebCamSeries(series_id)
{
	var ajaxRequest = new Ajax.Request('/inc/webcam.php?series_id=' + series_id, {method: 'get', onComplete: startSlideShow});
}

/* webcam ajax call */
function updateWebCam(days_ago)
{
	var ajaxRequest = new Ajax.Request('/inc/webcam.php?days_ago=' + days_ago, {method: 'get', onComplete: startSlideShow});
}

function updateWebCam2(days_ago)
{
	var ajaxRequest = new Ajax.Request('/inc/webcam2.php?days_ago=' + days_ago, {method: 'get', onComplete: startSlideShow});
}

function displayWebCam(year, month, day)
{
	var ajaxRequest = new Ajax.Request('/inc/webcam.php?year=' + year + '&month=' + month + '&day=' + day, {method: 'get', onComplete: startSlideShow});
}

function displayWebCam2(year, month, day)
{
	var ajaxRequest = new Ajax.Request('/inc/webcam2.php?year=' + year + '&month=' + month + '&day=' + day, {method: 'get', onComplete: startSlideShow});
}

function setWebCamDescription(desc)
{
	var element = document.getElementById('webcamDescription');
	element.innerHTML = desc;
}

/* load new webcam image */
function startSlideShow(request)
{
	// remove the slide shows buttons
	hideSlideShows();

	// split the result
	result = request.responseText.split(";");
	index = 0;
	loadNextImage();
}

function loadNextImage()
{
	// update the success story
	document.webcam.src = result[index];
	index++;
	
	if (index >= (result.length - 1))
	{
		showSlideShows();
	}
	else
	{	
		window.setTimeout('loadNextImage()', 1500);
	}
}

function hideSlideShows()
{
	$('slideshow_list').style.display = 'none';
	$('favorites_list').style.display = 'none';
}

function showSlideShows()
{
	$('slideshow_list').style.display = '';
	$('favorites_list').style.display = '';
}
