/*************************************************************************
*                         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-2006 by Planetography.  All rights reserved.      *
**************************************************************************/

(document.all) ? allobject=true : allobject=false;
(document.getElementById) ? dom=true : dom=false;

var IMAGE_WIDTH = 300; // size of each image, has to be fixed by width, not height as in most places
var IMAGE_GAP = 20; // pixels between images
var TOTAL_IMAGE_SIZE = IMAGE_WIDTH + IMAGE_GAP;

if (allobject) {
	var IMAGE_SHIFT = 1; // amount to scroll each iteration
} else if (dom) {
	var IMAGE_SHIFT = 1; // amount to scroll each iteration
} else {
	var IMAGE_SHIFT = 1; // amount to scroll each iteration
}
var IMAGE_COUNT = 9; // number of images
var DELAY_IMAGE_COUNT = IMAGE_COUNT;
var SCROLL_DELAY = 20;  // milliseconds timeout between scroller invocation
var ANIMATE_DELAY = 1500;  // delay before start of first animation
var ON_SCREEN_IMAGE_COUNT = 5;  // There are at most 5 images visible at one time
var pixel_offset = 0; // pixel offset from the base position for the 'leader' image

var ie5 = (document.getElementById&&document.all);
if (!ie5) {
/*
IMAGE_SHIFT = 80;
SCROLL_DELAY = 2000;
ANIMATE_DELAY = 0;
DELAY_IMAGE_COUNT = 0;
*/
}

// left-most image index currently visible, randomize start image
var lead_image_index = Math.round(Math.random() * (IMAGE_COUNT-1));
//var lead_image_index = 1;

// Array for scrollers for each image that is on the screen.
var scrollers = new Array (ON_SCREEN_IMAGE_COUNT);

var image_count = 0;  // used to count the images that have been loaded before triggering the logo

var TimeOutID;	// handle for timer
var triggerTimeouts = true;

function count_images ()
{
//alert ("in the image counter");
	if (++image_count >= IMAGE_COUNT) {
		trigger_logo ();
		window.setTimeout('delay_complete ();',ANIMATE_DELAY);
	}
}

function delay_complete ()
{
//alert ("animate delay complete");
	set_visible_images ();
	start_scrolling_timer (); // Start the scrolling timer
}

// Use a one-time timer because we want to complete the scroll before the next timer interval is started
function start_scrolling_timer ()
{
//alert ("start timer");
triggerTimeouts = true;
//	TimeOutID = window.setInterval('scroller();',SCROLL_DELAY);
TimeOutID = window.setTimeout('scroller();',SCROLL_DELAY);
}

function stop_scrolling_timer ()
{
	clearTimeout(TimeOutID);
//alert ("clear out the timer "+pixel_offset);
triggerTimeouts = false;
}

// Get the Ids of the images to be manipulated and store this information in the set of
// temporary variables. This list is a potential subset of the number of images in the image array,
// since some of the images will be off the screen completely and do not need to be scrolled.
// We are really only interested in the 'left' position of the image so that the Scroller can
// change the value.
function set_visible_images()
{
	var local_image_index;
	var i;
//var index_offset_walker = 0; // walk through each scroller using image width

	for (i=0; i<ON_SCREEN_IMAGE_COUNT; i++) {
		local_image_index = i+lead_image_index;
//alert ("local "+local_image_index+" lead "+lead_image_index+"  i "+i);
		// If at end of image list, wrap to beginning
		if (local_image_index >= IMAGE_COUNT) {
			local_image_index -= IMAGE_COUNT;
		}
		scrollers[i] = "Image"+local_image_index;
		show (scrollers[i]);
	}
}


// For each image that is on the screen, decrement left position by increasing the negative offset.  
// When the image goes off the left side (because the negative offset is equal to the image size), 
// reset the image list and the offset counters.
function scroller()
{
	var index_offset_walker = 0; // walk through each scroller using image width
	// Update the scrollers with the new value.
	for (var i=0; i<ON_SCREEN_IMAGE_COUNT; i++) {
		setLeftPosition(scrollers[i],pixel_offset+index_offset_walker+"px");
		index_offset_walker += TOTAL_IMAGE_SIZE;
	}
	// If we are at the right edge of am image, reset the offset counter and set a new lead image
	if (pixel_offset <= -TOTAL_IMAGE_SIZE) {
//stop_scrolling_timer ();
		hide (scrollers[0]);
setLeftPosition(scrollers[0],"-640px");
//setLeftPosition(scrollers[0],"300px");
//setTopPosition(scrollers[0],"360px");
		pixel_offset = 0;
		lead_image_index += 1;
		// If at the end of the image list, start over
		if (lead_image_index == IMAGE_COUNT) {
			lead_image_index=0;
		}
		set_visible_images ();
	}
	// Adjust the position of the offset now
	pixel_offset -= IMAGE_SHIFT;
	// Restart the timer now that the movement has been done
	if (triggerTimeouts) {
		start_scrolling_timer ();
	}
}

