/*

    JavaScript:
	ios_random_melbourne_image.js

    Purpose:
	Generate a random image of Melbourne.

    Copyright:
	Copyright © 2001 - 2005 Corpita Pty Ltd
	15 Bedford Street, Collingwood 3066, Australia

    History:
	24-Apr-2005 by SLJ
	    Reduce animation rate
	09-May-2003 by SLJ
	    Updated CTA version
	17-Feb-2001 by Simon L. Jackson
	    Incorporate into controlled version
	08-Jan-2001 by Brian M. Warburton
	    Initial version

*/

var ios_random_image_activations = 0; // 0=First time, +n=Post image n, -1=Animation
var ios_random_image_displayed = new Array ( 0, 0 );
var ios_random_image_num = 0;
var ios_random_image_synch = false;
var ios_random_image_timeout_id = null;

function ios_random_number () {
    return Math.floor ( Math.random () * 32 );
}

function ios_lookup_image_label ( argNum ) {
    argPic = "this is the picture label";

    var label_array = new Array (
      "Statue in Swanston Street, Melbourne",	// 00
      "Royal Exhibition Building, Carlton",
      "Detail of the roof of the Forest Garden, Melbourne Museum, Carlton",
      "Detail from facade of RMIT Swanston Street, Melbourne",
      "Melbourne Town Hall (foreground) and Manchester Unity Building, Collins St Melbourne",
      "... Melbourne Museum, Carlton",
      "Detail from Storey Hall, RMIT, Swanston St, Melbourne",
      "Trams, Victoria Pde, Carlton",
      "East end city skyline from Filnders Street Station",
      "Detail from facade of... RMIT Swanston Street, Melbourne",
      "Bourke Street-Docklands Footbridge, Melbourne",	// 10
      "Dome of Flinders Street Station",
      "Tram shelter, East Melbourne",
      "East end city skyline from Yarra Park, East Melbourne",
      "West facade, Melbourne Museum. Carlton",
      "...church , Collins Street, Melbourne",
      "Flowers Vasette facade, Fitzroy",
      "W-class tram, Collins Street, Melbourne",
      "Flinders Street Station, Melbourne",
      "City Circle Tram, Spring St. Melbourne",
      "Detail from facade, ... University of Melbourne, Parkville",	// 20
      "Dome of Royal Exhibition Building, Carlton",
      "... and Rhialto tower from Spencer Street, Melbourne",
      "Detail from facade, ... University of Melbourne, Parkville",
      "Detail of Victorian Parliament, Spring Street, Melbourne",
      "Beach shelter, Middle Park",
      "Detail from facade, ... University of Melbourne, Parkville",
      "Detail from Princess Bridge, St. Kilda Rd, Melbourne",
      "Children's Museum exterior, Carlton",
      "Domed tower of Forum Cinema, Flinders St, Melbourne",
      "...",	// 30
      "..." );

    return label_array[argNum];

}

function ios_random_image_next () {    

    image_number_string = "";

    ios_random_image_num = ios_random_number (); 
    picture_label = ios_lookup_image_label ( ios_random_image_num );

    if ( ios_random_image_num < 10 ) {
      image_number_string = "0" + ios_random_image_num.toString();
    }
    else {
      image_number_string = ios_random_image_num.toString();
    }

    random_image_src = "/common/docs/images/melbourne_" + image_number_string + ".gif";

    document.ios_random_image_image.src = random_image_src;
    document.ios_random_image_image.alt = picture_label;
    if ( typeof ( ios_random_image_displayed[ios_random_image_num] ) == 'undefined' ) {
      ios_random_image_displayed[ios_random_image_num] = 0;
    }
    ios_random_image_displayed[ios_random_image_num]++;
    if ( ios_random_image_displayed[ios_random_image_num] > 1 ) {
      document.ios_random_image_image.className = "iosrandomimagevisited";
    }
    else {
      document.ios_random_image_image.className = "iosrandomimagelink";
    }

}

function ios_random_image_function ( arg_option ) {    

    if ( ios_random_image_synch )
      return;

    ios_random_image_synch = true;

// After an image has loaded, we
// a) Schedule another image if we are in animation mode
// b) Do nothing if its not our first time
// c) Drop through and simulate a click if its the first time
    if ( arg_option == 'load' ) {
      if ( ios_random_image_activations < 0 ) {
	if ( ios_random_image_timeout_id != null )
	  clearTimeout ( ios_random_image_timeout_id );
	ios_random_image_timeout_id = setTimeout ( "ios_random_image_function ( 'dblclick' )", 500 );
      }
      if ( ios_random_image_activations != 0 ) {
	ios_random_image_synch = false;
	return;
      }
    }

// Mouseover simulates hover and stops any auto-load sequence
    if ( arg_option == 'mouseover' ) {
      if ( ios_random_image_timeout_id != null ) {
	clearTimeout ( ios_random_image_timeout_id );
	ios_random_image_timeout_id = null;
        for ( i = 0 ; i < ios_random_image_displayed.length ; i++ ) {
	  ios_random_image_displayed[i] = 0;
	}
      }
      document.ios_random_image_image.className = "iosrandomimagehover";
      ios_random_image_synch = false;
      return;
    }

    if ( arg_option == 'mousedown' ) {
      document.ios_random_image_image.className = "iosrandomimageactive";
      ios_random_image_synch = false;
      return;
    }

    if ( arg_option == 'mouseout' ) {
      if ( typeof ( ios_random_image_displayed[ios_random_image_num] ) == 'undefined' ) {
	ios_random_image_displayed[ios_random_image_num] = 0;
      }
      if ( ios_random_image_displayed[ios_random_image_num] > 1 ) {
	document.ios_random_image_image.className = "iosrandomimagevisited";
      }
      else {
	document.ios_random_image_image.className = "iosrandomimagelink";
      }
      ios_random_image_synch = false;
      return;
    }

// We get here on first load or any click

// Force continuous load on double click otherwise stop future load response
    if ( arg_option == 'dblclick' )
      ios_random_image_activations = -1;
    else
      ios_random_image_activations++;

    ios_random_image_next ();
    ios_random_image_synch = false;

}
