var splash = {
  images : ['two_way_candleholder.jpg', 'high_stool.jpg', 'inout_pitcher.jpg', 'marblewood_collection_1.jpg', 'marblewood_collection_5.jpg', 'pebble_bowls.jpg'],
  alt: ['Two way candleholder', 'High stool', 'Inout pitcher', 'Marblewood collection 1', 'Marblewood collection 5', 'Pebble bowls'],
  href: ['products/living_collection/07_two_way_candleholder.html', 'products/home_accessories/10_high_stool.html', 'products/living_collection/06_inout_pitcher.html', 'products/living_collection/09_marblewood_collection.html', 'products/living_collection/09_marblewood_collection.html', 'products/living_collection/04_pebble_bowls.html'],
  dir: 'images/splash/',
  
  write: function() {
    document.write(this.random_image());
  },

  random_image: function() {
    var i = random(this.images.length-1)
    return '<a href="'+this.href[i]+'" title="'+this.alt[i]+'"><img src="'+this.dir+this.images[i]+'" width="510" height="593" alt="'+this.alt[i]+'" /></a>';
  },
  
  start: function(){
    this.write();
    new PeriodicalExecuter(this.write.bind(this), 4);
  }
  
}

var statements = {
  texts : ['the sustainable home accessories brand', 'the sustainable home accessories brand', 'the sustainable home accessories brand', 'protection of human rights', 'freedom of association','reducing child labour','non-discrimination','better working conditions','protecting the environment','celebrate local crafts'],

  write: function() {
    document.write(this.random_statement());
  },
  
  random_statement: function() {
    return this.texts[random(this.texts.length-1)];
  }
  
}

function random(n) {
  return Math.round((n)*Math.random())
}


/* Slideshow */

var slideShow = Class.create();
slideShow.prototype = {
	interval: 6,
	target: 0,
	delayer: null,
	
	initialize: function() {
		new PeriodicalExecuter(this.getNextSlide.bind(this), this.interval);
		//this.delayer = new PeriodicalExecuter(this.startDelayed.bind(this), this.interval/2);
	},
	
	startDelayed: function() {
	  this.delayer.stop();
    new PeriodicalExecuter(this.getNextStatement.bind(this), this.interval);	  
	},
	
	next_target: function() {
	  return 'slide_' + this.target;
	},
	
	getNextSlide: function() {

		//this.swapSlides();
		
		//$(this.next_target()).innerHTML = '';
		//$(this.next_target()).innerHTML = splash.random_image();	

		$('slide_'+this.target).fade({ duration: 2.0 })
		this.target = (this.target == 0) ? 1 : 0;
		$('slide_'+this.target).appear({ duration: 2.0 })

	},
	
	getNextStatement: function() {
	  $('statement').innerHTML = statements.random_statement();
	},	
				
	swapSlides: function() {
	  var mem = $('slide_0').style.zIndex;
	  $('slide_0').style.zIndex = $('slide_1').style.zIndex;
	  $('slide_1').style.zIndex = mem;
	}	
}


/* Slides */

var slides = {
  
  show: function(index) {
    var images = $$("img.slide");
    if (images.length > 0) {
      images.each(function(img){ Element.hide(img) });
      Element.show(images[index]);
    }      
  }
  
}