

/*  A Macromedia function  //v3.0  */
function preload_images() { 
  var d=document; if(d.images){ if(!d.preloaded_images) d.preloaded_images=new Array();
    var i,j=d.preloaded_images.length,a=preload_images.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.preloaded_images[j]=new Image; d.preloaded_images[j++].src=a[i];}}
}


/*  Toggle the visibility of the two specified panels.  */

function highlight_panel(deselected_id, selected_id) { 
    //alert('in hightlight_panel, swapping ' + deselected_id + ' and ' + selected_id) ; 
    $('div#' + deselected_id).toggleClass('not_selected') ; 
    $('div#' + selected_id).toggleClass('not_selected') ; 
}


/*  Run the panel animation.

    Calls highlight_panel() to actually change a panel, 
    and then makes a recursive call to itself, specifying the next panel in the sequence.

    The set of panels is defined within this function, as an associative array, 
    with keys of integers (1, 2, 3, etc.) whose values are the HTML element IDs of 
    the panels that are part of the animation.
    
    Whether it stops when it gets to the last panel or repeats from the beginning 
    is based on the value of the repeat argument.

    current_index - A number that describes the panel to start from (typically 1 
                    if you are calling this the first time.) 

		    Note that if you do not specify the panel that is currently 
		    visible, then the actually visible panel will stay visible, 
		    and the animation will proceed below the original panel. 

    timeout -  the delay, in milliseconds, to wait before changing panels

    repeatTimeout - a boolean that indicates whether to loop the animation or stop 
             when the last panel is reached.  If an integer is used, when repeating 
			 the wait will be increased by 2000ms each cycle until it is > repeatTimeout
*/
function animate_panel(current_index, timeout, repeatTimeout) {

    var panels={'1':'panel_one',
		'2':'panel_two',
		'3':'panel_three',
		'4':'panel_four',
		'5':'panel_five'} ;
    var how_many_panels = Object.keys(panels).length ;     
    var next_index = parseInt(current_index) + 1 ; 

    if (next_index > how_many_panels) { 
	if (repeatTimeout) { 
		next_index = 1 ;
		if(repeatTimeout > timeout) {
			timeout = parseInt(timeout) + 2000;
		} 
	}
	else { return ; } 
    }

    var current_id = panels[current_index] ; 
    var next_id = panels[next_index] ; 

    var function_call = "highlight_panel('" + current_id + "','" + next_id + "');" + 
	"animate_panel('" + next_index + "','" + timeout + "'," + repeatTimeout + ")" ;
    setTimeout(function_call, timeout) ; 
}


$(document).ready(function(){

    //alert('in homepage.js document.ready') ; 

    /*  Set the handlers for mouseover links in the Workflow imagemap  */

    $("#workflow li a").hover(
	function() { 
	    var old_src = $('.diagram').attr('src') ;
	    var new_src = 'graphics/workflow-diagram-' + $(this).attr('name') + '.png' ; 
	    $('.diagram').attr("src", new_src) ;
	    //alert('changed src of ' + $('.diagram') + ' from ' + old_src + ' to ' + new_src) ; 
        },
	function() { 
	    var old_src = 'graphics/workflow-diagram.png' ; 
	    $('.diagram').attr("src", old_src) ;  
	    //alert('changed src of ' + $('.diagram') + ' to ' + old_src) ; 
      }
    );

    //alert('preloading images') ; 

    preload_images('pictures/notebooks.jpg', 
		   'pictures/scratching-head.jpg', 
		   'pictures/paper.jpg', 
		   'pictures/examining.jpg', 
		   'pictures/car-interior.jpg') ;
    animate_panel('1', '4000', '10000') ; 

});

