//=====================================================================||
//               NOP Design Media Cycling Script                       ||
//                                                                     ||
// For more information on SmartSystems, or how NOPDesign can help you ||
// Please visit us on the WWW at http://www.nopdesign.com              ||
//                                                                     ||
// The media cycler is available as freeware from NOP Design, under the||
// GNU Public License.  You must keep this comment unchanged in your   ||
// code.  For more information contact Scott@NopDesign.com             ||
//                                                                     ||
// MediaCyle Script Module, V.1.0.0                                    ||
//=====================================================================||
//---------------------------------------------------------------------||
// INTERNAL GLOBAL VARIABLES                                           ||
// PURPOSE:     Internal use only, do not modify.                      ||
//---------------------------------------------------------------------||
var xMediaContent  = new Array();
var xMediaImage    = new Image;
var iCurrentImage  = 0;
var iInternalCount = 5000;
var xTimerHandle   = null;
var bTimerRunning  = false;


//---------------------------------------------------------------------||
// USER DEFINED VARIABLES                                              ||
// PURPOSE:     Set these variables to customize your script           ||
//              TimeInSecondsBetweenCycles - Seconds to wait before    ||
//                                           cycling to the next image ||
//              LoadInNewWindow            - When true, the link will  ||
//                                           be opened in a new window ||
//                                           otherwise, it will load in||
//                                           the current window.       ||
//              WrapAtEnd                  - Wraps to start at end.    ||
//                                                                     ||
//              MEDIAIMAGE                - Needs defined in your HTML ||
//                                           page as an image name.    ||
//---------------------------------------------------------------------||
var TimeInSecondsBetweenCycles = 10.0;
var LoadInNewWindow = false;
var WrapAtEnd       = true;


//---------------------------------------------------------------------||
// MEDIA FILES TO LOAD                                                 ||
// PURPOSE:     This is the image that you wish displayed, followed by ||
//              the URL to link to.  All images should be on even      ||
//              numbered lines, URLS on odd.  Pay careful attention to ||
//              increment the counter inside of the [] symbols when you||
//              add more images.  There is no maximum to the amount of ||
//              images you can load.                                   ||
//---------------------------------------------------------------------||
xMediaContent[0] = "photos/flowers/D0001256b.jpg";
xMediaContent[1] = "flowers.html";

xMediaContent[2] = "photos/niagara/D0000478b.jpg";
xMediaContent[3] = "niagara.html";

xMediaContent[4] = "photos/usa/P0001361b.jpg";
xMediaContent[5] = "usa.html";

xMediaContent[6] = "photos/europe/P0005153b.jpg";
xMediaContent[7] = "europe.html";

xMediaContent[8] = "photos/animals/D0000408b.jpg";
xMediaContent[9] = "animals.html";

xMediaContent[10] = "photos/flowers/P0004331b.jpg";
xMediaContent[11] = "flowers.html";


//---------------------------------------------------------------------||
// FUNCTION:    MediaStop                                              ||
// PARAMETERS:                                                         ||
// RETURNS:                                                            ||
// PURPOSE:     Moves the media                                        ||
//---------------------------------------------------------------------||
function MediaStop()
{
    if( bTimerRunning )
        clearTimeout( xTimerHandle );

    bTimerRunning = false;
}


//---------------------------------------------------------------------||
// FUNCTION:    MediaGoBack                                            ||
// PARAMETERS:                                                         ||
// RETURNS:                                                            ||
// PURPOSE:     Moves the media                                        ||
//---------------------------------------------------------------------||
function MediaGoBack()
{
    MediaStop();

    if (WrapAtEnd)
      (iCurrentImage == 0) ? iCurrentImage = (xMediaContent.length - 2) : iCurrentImage-=2;
    else
      (iCurrentImage == 0) ? iCurrentImage = 0 : iCurrentImage-=2;

    document.MEDIAIMAGE.src = xMediaContent[iCurrentImage];
}


//---------------------------------------------------------------------||
// FUNCTION:    MediaGoForward                                         ||
// PARAMETERS:                                                         ||
// RETURNS:                                                            ||
// PURPOSE:     Moves the media                                        ||
//---------------------------------------------------------------------||
function MediaGoForward()
{
    MediaStop();

    if (WrapAtEnd)
      (iCurrentImage == (xMediaContent.length - 2)) ? iCurrentImage = 0 : iCurrentImage+=2;
    else
      (iCurrentImage == (xMediaContent.length - 2)) ? iCurrentImage = iCurrentImage : iCurrentImage+=2;

    document.MEDIAIMAGE.src = xMediaContent[iCurrentImage];
}


//---------------------------------------------------------------------||
// FUNCTION:    MediaInternalCycle                                     ||
// PARAMETERS:                                                         ||
// RETURNS:                                                            ||
// PURPOSE:     Internal media cycle routine                           ||
//---------------------------------------------------------------------||
function MediaInternalCycle()
{
    (iCurrentImage == (xMediaContent.length - 2)) ? iCurrentImage = 0 : iCurrentImage+=2;
    if( document.MEDIAIMAGE ) document.MEDIAIMAGE.src = xMediaContent[iCurrentImage];

    xTimerHandle   = setTimeout("MediaInternalCycle()", iInternalCount);
    bTimerRunning  = true;
}


//---------------------------------------------------------------------||
// FUNCTION:    MediaStart                                             ||
// PARAMETERS:                                                         ||
// RETURNS:                                                            ||
// PURPOSE:     Starts the media cycling. Call with 'OnLoad' from body ||
//              tag to have an image start cycling on page load.       ||
//---------------------------------------------------------------------||
function MediaStart()
{
    iInternalCount = TimeInSecondsBetweenCycles * 1000;
    MediaStop();
    MediaInternalCycle();
}


//---------------------------------------------------------------------||
// FUNCTION:    MediaClick                                             ||
// PARAMETERS:                                                         ||
// RETURNS:                                                            ||
// PURPOSE:     Clicks straight through to your media URL              ||
//---------------------------------------------------------------------||
function MediaClick()
{
    if( LoadInNewWindow ) {
        URL = xMediaContent[iCurrentImage+1];
        win=window.open(URL,"NewWindow","");
        if (!win.opener)win.opener=self;
    } else
        document.location.href = xMediaContent[iCurrentImage+1];
}


//---------------------------------------------------------------------||
// FUNCTION:    MediaClickWithInfo                                     ||
// PARAMETERS:                                                         ||
// RETURNS:                                                            ||
// PURPOSE:     Clicks to the URL you have listing in your media, plus ||
//              the value passed in as 'ADDITIONAL INFO'.  This is     ||
//              useful if you have defined your media URL's as         ||
//              directories, and have multiple files in those directori||
//---------------------------------------------------------------------||
function MediaClickWithInfo( AdditionalInfo )
{
    if( LoadInNewWindow ) {
        URL = xMediaContent[iCurrentImage+1] + AdditionalInfo;
        win=window.open(URL,"NewWindow","");
        if (!win.opener)win.opener=self;
    } else
        document.location.href = (xMediaContent[iCurrentImage+1] + AdditionalInfo);
}

function right(e) {
    if (navigator.appName == 'Netscape' && 
	(e.which == 3 || e.which == 2))
	return false;
    else if (navigator.appName == 'Microsoft Internet Explorer' && 
	(event.button == 2 || event.button == 3)) {
    alert("This site © 2005 BSA Troop 939, all rights reserved.  No form of reproduction, including copying, downloading, and/or saving of digital image files, or the alteration or manipulation of image files is permitted.  Any unauthorized use of these images will be prosecuted to the fullest extent of federal and international copyright laws.  Thank you for your cooperation.");
	return false;
	}
    return true;
}

document.onmousedown=right;
document.onmouseup=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
window.onmousedown=right;
window.onmouseup=right;

