/*************************************************************************
*                         COPYRIGHT NOTICE                               *
*                                                                        *
*   The contents of this file is protected under the United States       *
*   copyright laws as an unpublished work, and is confidential and       *
*   proprietary to Planetography.  Its use or disclosure in whole or in  *
*   part without the expressed written permission of Planetography. is   *
*   prohibited.                                                          *
*                                                                        *
*   (c) Copyright 2003-2009 by Planetography.  All rights reserved.      *
**************************************************************************/

var IMAGE_COUNT = 8; // number of images, must be more than 1
var VIEW_TIMER = 4000;
var FADE_OUT_TIMER = 90;
var FADE_IN_TIMER = 40;
var OPACITY_INCREASE = 5;
var OPACITY_DECREASE = 7;

var MAX_OPACITY = 100;

var ANIMATE_DELAY = 1500;  // delay before start of first animation

var currentTimer;
var currentOpacity = 100;
var image_offset = 0;
var visible_image = "";

function start_fadeout_timer ()
{
//alert ("start fadeout timer");
	currentTimer = setTimeout ("reduce_opacity ()", FADE_OUT_TIMER)
}

function start_fadein_timer ()
{
//alert ("start fadein timer");
	currentTimer = setTimeout ("increase_opacity ()", FADE_IN_TIMER)
}

function start_view_timer ()
{
//alert ("start view timer");
	currentTimer = setTimeout ("start_fadeout_image ()", VIEW_TIMER)
}

function stop_timer ()
{
	clearTimeout(currentTimer);
}

function select_image ()
{
//alert ("select_image");
	currentOpacity = 0;
//	show ("sampler_image");
	set_opacity ("sampler_image",currentOpacity);
	old_image_offset = image_offset;
	while (true) {
		image_offset = Math.round(Math.random() * (image_count-1));
		if (image_offset != old_image_offset) {
			break;
		}
	}
//	image_offset = image_offset + 1;
	if (image_offset == image_count) {
		image_offset = 0;
	}
	visible_image = sampler_image_list[image_offset];
	set_image ("sampler_image", "/images/"+visible_image+"Detail.jpg");
	set_href ("sampler_anchor","/portfolios/imagedetail/"+visible_image);
	start_fadein_timer ();
}

function reduce_opacity ()
{
	if (currentOpacity <= 0){
//		hide ("sampler_image");
		select_image ();
		return;
	}
	currentOpacity -= OPACITY_DECREASE;
	if (currentOpacity < 0) {
		currentOpacity = 0;
	}
	set_opacity ("sampler_image", currentOpacity);
	start_fadeout_timer ();
}

function increase_opacity ()
{
	if (currentOpacity >= MAX_OPACITY){
//alert ("reached full opacity");
		start_view_timer ();
		return;
	}
	currentOpacity += OPACITY_INCREASE;
	if (currentOpacity > 100) {
		currentOpacity = 100;
	}
	set_opacity ("sampler_image",currentOpacity);
	start_fadein_timer ();
}

function start_fadeout_image ()
{
//alert ("start fadeout image");
	start_fadeout_timer ();
}


function start_animation ()
{
//alert (sampler_image_list[0]);
//alert ("inside start_animation");
//	set_onclick_handler ("Image0");
	start_view_timer ();
}

