Slideflow.setup = function(){
	Slideflow.starting_index = 1;
	Slideflow.x_space_modifier = 15;
	Slideflow.slide_width = 600; 
	Slideflow.delay = 60;
};

Slideflow.update_caption = function(){
			// No captions
};

// Respond to a click on a slide
//
//
Slideflow.respond_click = function(event){
	slide = event.element().up('a');
	index = slide.getAttribute('slide_index');
	
	if (index == Slideflow.current_index)
		{
		// respond to click by selecting next
		new_index = Slideflow.current_index +1;
		
		if (new_index > Slideflow.slide_count())
			new_index = 1;
			
		Slideflow.select_slide_index(new_index);
		
		// deal with overflow by going back to start
		}
	else
		{
		// respond to click by selecting slide	
		Slideflow.select_slide_index(index);	
		}
},



// Run through our slides and calculate desired positions
// based on current_index and desired gap
// we store those desired positions in attributes of slides themselves
//
//
Slideflow.update_slide_positions = function(){
	
	// store dimensions of container
	var container_width = Element.getWidth(Slideflow.container);  
/*	var slides_width 	= Slideflow.slide_count() * Slideflow.slide_width;
	// Now we trim the nominal container width, if we have not enough slides to fill it
	// so that they bunch in the middle
	if (slides_width < container_width)
		container_width = slides_width;*/
	
	      
	var container_height = Element.getHeight(Slideflow.container);
	var container_midpoint = container_width * 0.5;


	Slideflow.x_spacing = (container_width / (Slideflow.slide_count()*Slideflow.x_space_modifier));
	Slideflow.y_spacing = (container_height / (Slideflow.slide_count()*Slideflow.y_space_modifier));
	
	
	// Walk through slides setting desired position and size
	// for animation routine to aim towards
	Slideflow.slides.each(function(slide, index){
		
		var slide_index = index + 1;// note index is zero based, we want 1 based
		
	
		// work out the offset from the selected slide (- is before + after)
		var slide_distance_from_current = slide_index - Slideflow.current_index;

	/*	

		var slide_yoffset = Slideflow.y_spacing * slide_distance_from_current;
		// for y we always want distance to be negative
		slide_yoffset = Math.abs(slide_yoffset);
		
		var desired_height = Math.round(Slideflow.slide_width - slide_yoffset*1.3);
		
		
		// round off to the nearest multiple of two
		desired_height = desired_height - (desired_height % 2);
		
		// Round up to Slideflow.slide_width if very close
		if (desired_height > (Slideflow.slide_width - 2))
			desired_height = Slideflow.slide_width;
		
		slide.setAttribute("desired_height",desired_height);
		
		
		// here we really need the *target* width 
		// - assuming slides are square we use height, as that defines width for us
		//var slide_width = slide.getWidth();
		var slide_width = desired_height;	
		
*/	
//		var slide_xoffset = Slideflow.x_spacing * slide_distance_from_current;
		
		var desired_left = Math.round((slide_distance_from_current*800));

		
		slide.setAttribute("desired_left",desired_left);
		slide.setAttribute("desired_top",0);
		
	});
};

// Resize a slide, given desired attributes attached to it
//
//
Slideflow.resize_slide= function(slide,desired_left,desired_top,desired_height){

	// set slide position
	slide.setStyle({
			left: desired_left + "px",
            top:  desired_top + "px"  
		});	

	// now set size of image (and reflection if we have one)
/*
	slide.flow_slide_image.setStyle({
		height:desired_height + "px",
		width:desired_height + "px" // be explicit in assumption that they are square
	});

	// we need to also adjust the reflection height, if there is one
	if (slide.flow_slide_reflection)
		{
		// note the reflection width must have 2px knocked off for borders if we have them
		var reflection_width = desired_height;
		if(slide.hasBorder)
			reflection_width += 2;

		// First set actual reflection canvas element width
		slide.flow_slide_reflection.setStyle({
			width:reflection_width + "px"// NB this assumes the width is same as height
		});

		slide.flow_reflect_container.setStyle({
			width:reflection_width + "px"// NB this assumes the width is same as height
		});
		}*/
};
