// © Copyright Kenny Grant 2007 
// Released under the BSD licence

// Add rel="slideshow" to anchor links to activate
//
//
// Code inspiration from http://www.huddletogether.com/projects/lightbox2/
// particularly for greying out entire window

	
var Slideshow = {
	version				: '1.1',
	KEY_SPACE			:32,// space key
	KEY_INFO			:73, // i
	KEY_FULLSCREEN		:70, // f


	ground_opacity		:0.8,
	control_opacity 	:0.7,
	delay				:6000, 
	
	ground				:null,
	slides				:new Array,
	timer				:null,
	control_timer		:null,
	animation_effect	:null,
	
	current_slide_index :-1,
	
	// Set up the slideshow elements and listen to events
	// run on window load by function call at end of this file
	// 
	init : function () {

			
		Slideshow.set_paths()
		Slideshow.add_controls()
		Slideshow.capture_events()
		
		// Replace slide objects with a loading placeholder and store the src
		Slideshow.load_slides()
		
		// attach ourselves as observer on <a rel="slideshow"> elements
		Slideshow.attach()
		
	},
	
	
	// Store the list of slides in the document
	//
	// NB we expect the following structure
	//  .slide_container
	//     .slide_link
	//	     .slide_hover
	//     .slide
	//       .slide_content
	
	load_slides : function () {
		// Note if slides are invisible they won't be in the DOM (hopefully)
		slides_list = $(document.body).select('.slide');

		// empty the array
		Slideshow.slides.clear();
		
		slides_list.each(function(slide) {
			slide_container = slide.up();
			if (slide_container.visible())
				Slideshow.slides.push(slide);
		});
		
		
	},
	
	
	// // get hold of the relative path to site root from this html page
	//
	//
	set_paths : function () {
		
		// used by add_control to add relative links to images
		// this assumes that slideshow.js links are relative links from pages
		// we don't use '/' as it breaks when viewing site locally
		
		$$('script').each(function (s) {
			if (s.src.endsWith("mc_slideshow.js"))
				{
				Slideshow.rel_url = s.src.gsub("mc_slideshow.js","../../");
				}
		});
	},
	
	
	
/* EVENTS */	
	
	// attach ourselves to events on slideshow links
	//
	//
	attach : function () {
		
		$(document.body).select('a').each(function (link) {
		
			 var rel = String(link.getAttribute('rel'));
			 
			 if (rel == "slide_link")
				{
				Event.observe(link,'mouseover',Slideshow.respond_mouseover.bindAsEventListener(Slideshow));
				// We no longer observe mouse out for now as had problems with cancelling effects
			//	Event.observe(link,'mouseout',Slideshow.respond_mouseout.bindAsEventListener(Slideshow));
				Event.observe(link,'click',Slideshow.respond_click.bindAsEventListener(Slideshow));
				}
			else if (rel == "slideshow_cancel")
				{
				Event.observe(link,'click',Slideshow.cancel_pressed);	
				}
		
		});
		
		// We also observe the window to see if it resizes - if so 
		Event.observe(window,'resize',Slideshow.respond_window_resize);

		
		
	},

	// Respond to a resize of window 
	//
	// 
	respond_window_resize : function (event) {
		Slideshow.prepare_ground();
		Slideshow.prepare_controls();
		Slideshow.prepare_slide(Slideshow.current_slide());
	},


	// Respond to hovers on links 
	//
	// We simply show div with id slide_hover_slide_id
	respond_mouseover : function (event) {
		link = Slideshow.get_slide_link(Event.element(event));
		Slideshow.show_slide_caption(Slideshow.get_slide_id(link));	
	},
	
	
	// Respond to hovers out of links
	//
	// Hides div with id slide_hover_slide_id
	respond_mouseout : function (event) {
		link = Slideshow.get_slide_link(Event.element(event));
		Slideshow.hide_slide_caption(Slideshow.get_slide_id(link));
	},


	// Respond to clicks on links
	//
	//
	respond_click : function (event) {
		
		
	
		/* first rebuild the slides list, in case some have been made invisible */
		Slideshow.load_slides();		
			
		link = Slideshow.get_slide_link(Event.element(event))
		link_id = Slideshow.get_slide_id(link)
		
		if (Effect.Bounce)
			{// in mc_effects.js
			new Effect.Bounce(link)
			}


		//in case we have some visible
		Slideshow.hide_slides()
		
		// In case we are starting
		Slideshow.show_ground()
	
		// show the slide numbered as per link
		Slideshow.show_slide($("slide_"+link_id))
	
		// tell browser to ignore event
		event.stop();
	},
	
	playing: function() {
		return (Slideshow.timer != null);
	},
	
	animating: function() {
		return (Slideshow.animation_effect != null);
	},

	
	visible: function() {
		return (Slideshow.ground && Element.visible(Slideshow.ground));
	},
	
	
	
	capture_events: function() {
	/* watch out for the keyboard events we're interested in */
	action_delay =  Slideshow.animating() ? 1000 : 1;
		
	Event.observe(document, 'keydown', function(event)
		{ 
		 key = event.which || event.keyCode;	

			switch(key)
			{
				// for most of these events we ignore them if not playing
			
			    case Event.KEY_LEFT:
				if (Slideshow.playing() && !Slideshow.animating())
					{
					if (Slideshow.delay < 10000)
						Slideshow.delay = Slideshow.delay * 1.2; //make the delay longer for each back request
					Slideshow.flash_control("control_left");
					window.setTimeout("Slideshow.step_backward();",action_delay);	
		
					Event.stop(event);	
					}
				break;
				
			    case Event.KEY_RIGHT:
				if (Slideshow.playing() && !Slideshow.animating())
					{
					if (Slideshow.delay > 1000)
						Slideshow.delay = Slideshow.delay * 0.85; //make the delay shorter for each forward request
					Slideshow.flash_control("control_right");
					window.setTimeout("Slideshow.step_forward();",action_delay);	
					Event.stop(event);
					}
				break;	

				case Event.KEY_HOME:
				if (Slideshow.playing() && !Slideshow.animating())
					{
					Slideshow.flash_control("control_left");
					window.setTimeout("Slideshow.step_home();",action_delay);
					Event.stop(event);
					}
				break;

				case Event.KEY_END:
				if (Slideshow.playing() && !Slideshow.animating())
					{
					Slideshow.flash_control("control_right");
					window.setTimeout("Slideshow.step_end();",action_delay);
					Event.stop(event);	
					}	
				break;

				case Event.KEY_ESC:
					Slideshow.stop();
					Event.stop(event);
				break;	


				case Slideshow.KEY_FULLSCREEN:
				if (Slideshow.playing())
					{
	  				des_w = self.screen.availWidth;
					des_h = self.screen.availHeight;
					parent.window.moveTo(0,0);
					parent.window.resizeTo(des_w,des_h);
					// need to allow time for window to resize
					setTimeout("Slideshow.prepare_ground()", 10);
					Event.stop(event);
					}
				break;


				// comment this out if you don't want to capture the space key for pausing
				case Slideshow.KEY_SPACE:
			    case Event.KEY_RETURN:
					if (Slideshow.playing() && Slideshow.visible())
						{
						//make the delay longer for each pause request
						if (Slideshow.delay < 10000)				
							Slideshow.delay = Slideshow.delay * 1.2; 
						Slideshow.flash_control("control_pause");
						Slideshow.pause();
						Event.stop(event);
						}
					else if (Slideshow.visible())	
						{
						Slideshow.flash_control("control_play");
						Slideshow.play();	
						Event.stop(event);
						}
					else
						{
						// note we don't stop the event if we're not playing or visible
						}
				break;


				default:
				// could show possible key combinations here if they press some other keys and no modifiers?
				//	debug_log("key: " + key);
				break;

			}

		});

	},
		
		
/* SLIDES */		
	
	// Called when we have a hit inside a link
	// and want actual link object
	get_slide_link : function (in_hit) {
		link = in_hit;
		// normally we'll be given the thing inside the link clicked
		// walk back up parents till we meet link
		while (!link.hasClassName('slide_link'))
			{
			link = link.up();	
			}
		
		return link;
	},
	
	get_slide_id : function (slide_link) {
		return slide_link.id.gsub("slide_link_","");
	},
	
	get_slide_caption : function (slide_id) {
		return $("slide_hover_"+slide_id);
	},
	
	// Show a slide caption
	//
	//
	show_slide_caption : function (slide_id) {
		
	
		caption = Slideshow.get_slide_caption(slide_id);
		if (caption && !caption.visible() && !caption.effect)
			{
			caption.effect = new Effect.BlindDown(caption,{duration:0.3});
			
			window.setTimeout("Slideshow.hide_slide_caption("+ slide_id + ")",2000);
	
		/*	
			Unfortunatley there is no reliable way to cancel combination effects in scripaculous
			Could do this manually - investigate
			
		caption.effect = new Effect.BlindDown(caption,
						{duration:0.3,afterFinishInternal: function() {caption.effect = null;} 
						});	*/
						
			}
	},
	
	
	// Hide a specific slide caption (doesn't hide previous slide, only use at start)
	//
	//
	hide_slide_caption : function (slide_id) {
		caption = Slideshow.get_slide_caption(slide_id);
		if (caption && caption.visible())
			{
			new Effect.BlindUp(caption,{duration:0.1});
			caption.effect = null;
			}
	},
	
	//  Find slide caption within a slide div
	//
	//
	slide_caption : function (in_slide) {
		in_slide.down('.slide_caption');
	},
	

	
	// Select the given slide by setting our current index
	//
	//
	select_slide: function(slide){
		// Note the slide id probably doesn't correspond with position in our array
		i = 0;
		Slideshow.slides.each(function (s) {
			if (s == slide)
				{
				Slideshow.select_index(i);
				}
			i++;
			});
	},
	
	// Select the given index (with bounds check) - does nothing else
	//
	//
	select_index: function(i){
		Slideshow.current_slide_index = Slideshow.normalize_index(i);	
	},
	
	// Select the given index (with bounds check) and show the slide
	//
	// Hides current slide and resets timer
	select_and_show_index: function(i){
		var select_slide 	= Slideshow.slide_with_index(i)
		var current_slide	= Slideshow.current_slide()
		
		// hide current slide
		if (current_slide && (current_slide != select_slide))
			{
			// Fade out the current one
			new Effect.Fade(current_slide,{ duration: 0.5});
			new Effect.Shrink(current_slide,{ duration: 0.7});
			}
		
		// show new slide
		Slideshow.show_slide(select_slide)
		
		// reset the timer again
		Slideshow.play()
	},
	
	// return the div which contains the main part of the page, where slides are to be centered
	page_container : function() {
	 return document.body.down('div').down('div');	
	},
	
	// Position this slide (centered horizontally in containing div, 250px down vertically)
	//
	//
	position_slide : function(slide) {
		// Calculate x position - centered inside second div down in body	
		var page_container = Slideshow.page_container();
		x_offset = (page_container.getWidth() - slide.getWidth())/2;
	//	x_offset = (Slideshow.page_width() - slide.getWidth())/2;
		y_offset = 100; // start with a decent y offset

		// get the scroll position so we can adjust for that
		var offsets = Position.realOffset(slide);
		slide.style.position 	= "absolute";
		slide.style.top 		= y_offset + offsets[1] + "px";
		slide.style.left 		= x_offset + offsets[0] + "px";
		slide.style.zIndex		= "100";
	},
	
	
	// Prepare slide to become visible
	//
	//
	prepare_slide : function (slide) {
		var slide_content = slide.down('.slide_content')

		
		if (!slide_content || !slide) return;
			
		Slideshow.position_slide(slide)
			
		Slideshow.select_slide(slide)
	

		// Sort the content
	
		if (slide_content.slide_loaded)
			{
			//debug_log("preloaded"+slide.id);
			new Effect.Appear(slide_content,{duration:1.0});
			Slideshow.play();
			Slideshow.preload_slide(Slideshow.next_slide());
			Slideshow.preload_slide(Slideshow.previous_slide()); // preload previous - won't do any harm
			}
		else
			{
			
			var slide_content_link = slide.down('.slide_content_link');
			//debug_log("preparing"+slide.id+slide_content_link.href);
			
			// Note this might not be an image, should deal with embedded objects like movies too
			// but perhaps deal with those just by setting src and let them do the preloading
			var s_image = new Image();
			s_image.slide_content = slide_content;
			s_image.onload = function(){
			
			/*	This was an attempt to slide down slide content - to height of image
				but final height also dictated by other contents
				
				slide_content.hide();
				new Effect.Scale(slide_content_link, 100, Object.extend({ 
				    scaleContent: false, 
				    scaleX: false, 
				    scaleFrom: window.opera ? 0 : 1,
				    scaleMode: {originalHeight: this.height+20, originalWidth: this.width},
				    restoreAfterFinish: true,
					}, {duration:0.7})
				);
			
				*/
				
				// Swap back in the real source, now that it's loaded
				slide_content.src = slide_content_link.href;
				slide_content.slide_loaded = true;
				new Effect.Appear(slide_content,{from:0.1,duration:1.0});
				//new Effect.Grow(slide_content,{duration:0.4});
				// Now restart timer
				Slideshow.play();
				Slideshow.preload_slide(Slideshow.next_slide());// preload the next one to avoid delays
	       		Slideshow.preload_slide(Slideshow.previous_slide()); // preload previous - won't do any harm
				}
			
			//this starts a load
			if (slide_content_link)
		 		s_image.src = slide_content_link.href;
			}


	},
	
	
	// Preload slide - used to preload the next slide every time we step
	//
	// We could always run through and preload all slides at end of page load...
	// Might be an idea to avoid any delays - but could lead to excessive server load
	preload_slide : function (slide) {
		slide_content = slide.down('.slide_content');
	
		if (slide_content && !slide_content.slide_loaded)
			{
			slide_content_link = slide.down('.slide_content_link');
			s_image = new Image();
			
			// This isn't working to mark as already loaded investigate
		//  s_image.slide_content = slide_content;
		//	s_image.onload = function(){
		//		this.slide_content.slide_loaded = true;
		//	};
			
			//this starts a load
		 	s_image.src = slide_content_link.href;
			}
	
	},
	
	
	// Hide the visible slides (normally just one)
	//
	//
	hide_slides : function () {
	
	Slideshow.slides.each(function (slide) {
		if (Element.visible(slide))
			{
			new Effect.Shrink(slide,{ duration: 0.5});
			}
		});
	
	},

	// Return an index which is guaranteed to be valid
	//
	//
	normalize_index : function (i) {
		var last  = Slideshow.slides.length-1;
		var first = 0;

		// bounds checking
		if (i < first)
			i = last; 
		else if (i > last)
			i = first;
		
		return i;	
	},
	
	// Returns slide with a given index (with bounds checking)
	//
	//
	slide_with_index : function (i) {
		return Slideshow.slides[Slideshow.normalize_index(i)];	
	},

	// Returns the current visible slide
	//
	//
	current_slide : function () {
		return Slideshow.slide_with_index(Slideshow.current_slide_index);
	},
	
	// Returns the slide after the current visible slide
	//
	// Note this does not change selection
	next_slide : function () {
		return Slideshow.slide_with_index(Slideshow.current_slide_index + 1);
	},
	
	
	// Returns the slide before the current visible slide
	//
	// Note this does not change selection
	previous_slide : function () {
		return Slideshow.slide_with_index(Slideshow.current_slide_index - 1);		
	},
	
	

	
/* SLIDESHOW ACTIONS */	


	
	// Stop the slideshow, and hide slideshow content and controls
	//
	// we also play cancel button sound
	cancel_pressed : function () {
		Slideshow.stop();
	},


	

	
	// Stop the slideshow, and hide slideshow content and controls
	//
	//
	stop : function () {
		Slideshow.pause();
		Slideshow.hide_slides();
		Slideshow.hide_ground();
		Slideshow.current_slide_index = -1;
	},



	// Stop the slideshow momentarily
	//
	//
	pause : function () {
		//clear our timer
		if (Slideshow.timer)
			{
			window.clearTimeout(Slideshow.timer);
			Slideshow.timer = null;
			
			Element.hide('static_control_pause');
			Element.show('static_control_play');
			}
	},


	// Play the slideshow with timer
	//
	//
	play : function () {
		//set our timer for stepforward
		Slideshow.pause();
		Slideshow.timer = window.setTimeout("Slideshow.step_forward();", Slideshow.delay);
		
		Element.show('static_control_pause');
		Element.hide('static_control_play');
	},

	// Show a specific slide (does not hide others, but resizes controls etc)
	//
	//
	show_slide : function (in_slide) {
	
				
		if (in_slide && Slideshow.current_slide() != in_slide || Slideshow.current_slide_index == -1)
			{
				
				Slideshow.prepare_ground()
				Slideshow.prepare_slide(in_slide)
	
			Slideshow.animation_effect = new Effect.Appear(in_slide,{ duration: 0.9, afterFinish: 
				function () {Slideshow.animation_effect = null}
				});
			}	
			
			
	},
	
	step_forward : function () {
		Slideshow.select_and_show_index(Slideshow.current_slide_index + 1);
	},
	
	step_backward : function () {
		Slideshow.select_and_show_index(Slideshow.current_slide_index - 1);
	},
	

	step_home  : function () {
		Slideshow.select_and_show_index(0);
	},
	
	step_end  : function () {
		Slideshow.select_and_show_index(Slideshow.slides.length-1);
	},


/* GROUND */	



	// Draw the grey screen behind, over the normal content
	//
	// Note this relies on slideshow.css for z-index
	show_ground : function () {
	
	
		if (!$('slideshow_ground'))
			{
			Slideshow.ground = document.createElement("div");
			Slideshow.ground.setAttribute('id','slideshow_ground');
			Slideshow.ground.style.display 		= 'none';
			Slideshow.ground.style.position		= 'absolute';
			Slideshow.ground.style.top 			= "0px";
			Slideshow.ground.style.left 		= "0px";
		 	Slideshow.ground.style.zIndex		= "90";
			Slideshow.ground.onclick = function() { Slideshow.stop(); }
			Slideshow.ground.onmouseover = function() { Slideshow.hide_controls(100); }
		
			Element.insert($(document.body),{ bottom: Slideshow.ground});
			}
			
		if (Slideshow.ground && !Element.visible(Slideshow.ground))	
			{
						
			Slideshow.prepare_ground();
			new Effect.Appear(Slideshow.ground, { duration: 0.3, from: 0.0, to: Slideshow.ground_opacity })
			Element.hide('static_control_pause');
			Slideshow.prepare_static_controls();
			new Effect.Appear(Slideshow.static_controls, { duration: 0.3, from: 0.0, to: 1.0 })
			}
			
				
	},
	
	
	// Remove the grey screen behind, over the normal content, plus the static controls
	//
	//
	hide_ground : function () {
		if (Slideshow.ground)
			{
			new Effect.Fade(Slideshow.ground,{ duration: 0.8});
			
			Element.hide(Slideshow.static_controls);
			}
	},
	
	

	// Resize the grey screen behind, over the normal content
	//
	//
	prepare_ground : function () {

		Slideshow.ground.style.position 	="absolute";		
		Slideshow.ground.style.height 		= Slideshow.page_height() +"px";
		Slideshow.ground.style.width 		= Slideshow.page_width() +"px";

		// Also position static controls
		Slideshow.prepare_static_controls()
	},

	
/* SLIDESHOW CONTROLS */	

	
	// Tidy up - perhaps use a template?
	
	// Add the control div to document (containing images)
	//
	//
	add_controls : function () {
		// add a controls div plus images within that
		// initially images set to invisible
		Slideshow.controls = document.createElement("div");
		Slideshow.controls.setAttribute('id','slideshow_controls');
		Slideshow.controls.style.opacity = Slideshow.control_opacity;
		Element.hide(Slideshow.controls);
		
		// add all the control images (each initially invisible)
		// Each is added with an onclick function
		// this is so they work when clicked in control panel - see if this is worth it
		Slideshow.add_control(Slideshow.controls,'control_left',function() 
		{ Slideshow.flash_control('control_left'); Slideshow.step_backward(); } );
		Slideshow.add_control(Slideshow.controls,'control_play',function() 
		{ Slideshow.flash_control('control_play');  Slideshow.play(); } );
		Slideshow.add_control(Slideshow.controls,'control_pause',function() 
		{ Slideshow.flash_control('control_pause');  Slideshow.pause(); } );
		Slideshow.add_control(Slideshow.controls,'control_right',function() 
		{ Slideshow.flash_control('control_right');  Slideshow.step_forward(); } );
	
		document.body.appendChild(Slideshow.controls);
		
		// Now create some static controls as well which sit at the top of the page, 
		// and are always visible when playing

	    Slideshow.static_controls = document.createElement("div");
	    Slideshow.static_controls.setAttribute('id','slideshow_static_controls');
	    Slideshow.static_controls.style.opacity = Slideshow.control_opacity;
		Element.hide(Slideshow.static_controls);
		
		// add all the control images (each initially invisible)
		// Each is added with an onclick function
		// this is so they work when clicked in control panel - see if this is worth it
		Slideshow.add_control(Slideshow.static_controls,'control_left',function() 
		{ Slideshow.flash_control('control_left'); Slideshow.step_backward(); } );
		Slideshow.add_control(Slideshow.static_controls,'control_play',function() 
		{ Slideshow.flash_control('control_play');  Slideshow.play(); } );
		Slideshow.add_control(Slideshow.static_controls,'control_pause',function() 
		{ Slideshow.flash_control('control_pause');  Slideshow.pause(); } );
		Slideshow.add_control(Slideshow.static_controls,'control_right',function() 
		{ Slideshow.flash_control('control_right');  Slideshow.step_forward(); } );
	
		document.body.appendChild(Slideshow.static_controls);
	},
	
	
	// Add an image to the control div
	//
	//
	add_control : function (control_parent,control_id,control_function) {
		// doesn't work in Safari 2.0
		//control = new Image();
		var control = document.createElement("img");
		
		
		control.src = Slideshow.rel_url + "images/slideshow/"+control_id+".png"
		
		var item_id = (control_parent == Slideshow.controls) ? control_id : "static_"+control_id;
		
		control.setAttribute("id",item_id);
		var item_title = control_id.gsub("control_","").capitalize();
		control.setAttribute("title",item_title);
		
		// initially control images set to invisible
		if (control_parent == Slideshow.controls)
			Element.hide(control);
			
		control.onclick = control_function; 
		control_parent.appendChild(control);
	},


	// Show  controls
	//
	//
	show_controls : function () {
		if (Slideshow.controls  && !Element.visible(Slideshow.controls) )
			{
			Slideshow.prepare_controls();
			new Effect.Appear(Slideshow.controls,{ duration: 0.5, from: 0.0, to: Slideshow.control_opacity });
			}
	},
	
	
	// Hide all controls
	//
	//
	hide_controls : function (time) {
		
		if (Slideshow.controls)
			{
			clearTimeout(Slideshow.control_timer);	
			clearTimeout(Slideshow.control_hide_timer);	
			Slideshow.control_timer = setTimeout("Effect.Fade('slideshow_controls',{ duration: 0.5})", time);
			Slideshow.control_hide_timer = setTimeout("Slideshow.hide_all_controls();", time + 600);
			}
	},
	
	hide_all_controls : function () {
		Element.hide('control_left');
		Element.hide('control_play');
		Element.hide('control_pause');
		Element.hide('control_right'); 
		Element.hide(Slideshow.controls);
	},
	
	// Show the control mentioned to indicate action taken
	//
	//
	flash_control : function (control_id) {
		
		control = $(control_id)
		if (control)
			{
				
			// make sure all controls are invisible (including this one)
			Slideshow.hide_all_controls();
			
			new Effect.Appear(control,{from:0.1, duration: 0.5});
			Slideshow.show_controls();
	
			// set a timeout to fade out all the controls after a moment
			Slideshow.hide_controls(2000);

			}
	},
	
	// Prepare controls to become visible
	//
	//
	prepare_controls : function () {
		var body_width 		= Slideshow.page_width()
		var controls_width 	= Element.getWidth(Slideshow.controls)
		if (controls_width == 0) controls_width = 100
	
		
		var x_offset 		= (body_width - controls_width)/2
		// get the scroll position so we can adjust for that
		var y_offset		= Position.realOffset(Slideshow.controls)[1]
		
		
		Slideshow.controls.style.position 	=	"absolute"
		Slideshow.controls.style.top 		= 	y_offset + 250 + "px"
		Slideshow.controls.style.left 		= 	x_offset + "px"

	},
	
	// Prepare controls to become visible
	//
	//
	prepare_static_controls : function () {
		var body_width 		= Slideshow.page_width()
		var controls_width 	= Element.getWidth(Slideshow.static_controls)

		var x_offset 		= (body_width - controls_width)/2
		// get the scroll position so we can adjust for that
		var y_offset		= Position.realOffset(Slideshow.static_controls)[1]
			
		Slideshow.static_controls.style.position 	="absolute";	
		Slideshow.static_controls.style.top 		= y_offset + 20 + "px";
		Slideshow.static_controls.style.left 		= x_offset + "px";
	
	},
	
	

/* Page attributes (scroll, height etc) */

	// The width of page
	//
	//
	page_width : function () {
		if (window.innerWidth && window.scrollMaxX)
			return window.innerWidth + window.scrollMaxX;
		else if (document.body.scrollWidth)
			return document.body.scrollWidth;
		else if (document.documentElement.clientWidth)
			return document.documentElement.clientWidth;
	},

	// The height of page
	//
	// Safari - document.body.scrollHeight
	// Firefox - window.innerHeight + window.scrollMaxY
	// IE - ?
	page_height : function () {
		if (window.innerHeight && window.scrollMaxY)
			return window.innerHeight + window.scrollMaxY;
		else if (document.body.scrollHeight)
			return document.body.scrollHeight;
		else if (document.documentElement.clientHeight)
			return document.documentElement.clientHeight;
	}


	
};


Event.observe(window,'load',Slideshow.init,false);


		