/* 
 * Injection of the buttons (etc) required for the slide show on the project pages.
 * See also slideshow.js
 */
window.addEvent('domready',function(){
	var obj = {
		wait: 3000, 
		effect: 'fade',
		duration: 1000, 
		loop: true, 
		thumbnails: true,
		backgroundSlider: false,
		onClick: false
	}
	
	var slideshow_container = $('slideshowContainer');
	if (slideshow_container) {
		
		//set styles that only apply if slideshow is present
		var thumbnails_wrapper = $E('div.thumbnails_wrapper');
		thumbnails_wrapper.setStyle('margin-top', '-20px');
		
		var thumbnails = $('thumbnails');
		thumbnails.setStyle('overflow', 'hidden');
		
		//create the slide show
		var show = new SlideShow('slideshowContainer','slideshowThumbnail',obj);
		
		//create scroll up button
		var scroll_up_button = new Element('a', {
			'id': 'scroll_up',
			'href': '#',
			'events': {
				'click': function(e) {
					new Event(e).stop();
					show.scrollUp();
				}
			}
		});
		scroll_up_button.innerHTML = '<img src="/media/img/core/scroll_up.png" alt="Up"/>';
		scroll_up_button.inject(thumbnails, 'before');
		
		//create scroll down button
		var scroll_down_button = new Element('a', {
			'id': 'scroll_down',
			'href': '#',
			'events': {
				'click': function(e) {
					new Event(e).stop();
					show.scrollDown();
				}
			}
		});
		scroll_down_button.innerHTML = '<img src="/media/img/core/scroll_down.png" alt="Down"/>';
		scroll_down_button.inject(thumbnails, 'after');
		
		//create previous button
		var previous_button = new Element('a', {
			'id': 'previous',
			'href': '#',
			'events': {
				'click': function(e) {
					new Event(e).stop();
					show.previous();
				}
			}
		});
		previous_button.innerHTML = 'Previous';
		previous_button.inject(slideshow_container, 'after');
		
		//create play button
		var play_button = new Element('a', {
			'id': 'play',
			'href': '#',
			'events': {
				'click': function(e) {
					new Event(e).stop();
					show.play(); 
				}
			}
		});
		play_button.innerHTML = 'Play';
		play_button.inject(previous_button, 'after');
		
		//create stop button
		var stop_button = new Element('a', {
			'id': 'stop',
			'href': '#',
			'events': {
				'click': function(e) {
					new Event(e).stop();
					show.stop();
				}
			}
		});
		stop_button.innerHTML = 'Stop';
		stop_button.inject(play_button, 'after');
		
		//create next button
		var next_button = new Element('a', {
			'id': 'next',
			'href': '#',
			'events': {
				'click': function(e) {
					new Event(e).stop();
					show.next();
				}
			}
		});
		next_button.innerHTML = 'Next';
		next_button.inject(stop_button, 'after');
		
		//add event to zoom button
		var zoom_button = $('zoom');
		zoom_button.addEvent('click', function(e){
			new Event(e).stop();
			show.stop();
			var index = show.image;
			if (index == -1) {
				index = show.images.length - 1;
			}
			Slimbox.open(largeImages.map(function(i) { return [i, '']}), index);
		});
		
		//start the slide show
		show.play();
	}
});


