﻿function SlideShow( containerName ) {
	this.g_animationManager = new AnimationManager( 10 );
	this.g_current_slide = 0;
	this.g_slides = new Array;
	this.begun = 0;
	this.stopped = 0;
	this.g_directions = [
		{ sx: [ -30, 0 ], ex: [ 5, 40 ], sy: [ -30, 0 ], ey: [ 5, 40 ] }, // nw -> se
		{ sx: [ 5, 40 ], ex: [ -30, 0 ], sy: [ 5, 40 ], ey: [ -30, 0 ] }, // ne -> sw
		{ sx: [ 5, 40 ], ex: [ -30, 0 ], sy: [ 5, 40 ], ey: [ -30, 0 ] }, // se -> nw
		{ sx: [ -30, 0 ], ex: [ 5, 40 ], sy: [ 5, 40 ], ey: [ -30, 0 ] } // sw -> ne
		];
	this.containerName = containerName;
	
	var ss_object = this;
	
	this.g_animationManager.on_finished = function()
	{   
	    if ( ss_object.g_slides.length > 0) {
  		    ss_object.g_current_slide++;
  		    if ( ss_object.g_current_slide >= ss_object.g_slides.length )
      	  		ss_object.g_current_slide = 0;
  		    ss_object.g_slides[ ss_object.g_current_slide ].start();
  		}
  		else {
  		    ss_object.begun = 0;
  		}
	}
}

/*
var g_animationManager = new AnimationManager( 50 );
var g_current_slide = 0;
var g_slides = [];
var g_directions = [
{ sx: [ -30, 0 ], ex: [ 5, 40 ], sy: [ -30, 0 ], ey: [ 5, 40 ] }, // nw -> se
{ sx: [ 5, 40 ], ex: [ -30, 0 ], sy: [ 5, 40 ], ey: [ -30, 0 ] }, // ne -> sw
{ sx: [ 5, 40 ], ex: [ -30, 0 ], sy: [ 5, 40 ], ey: [ -30, 0 ] }, // se -> nw
{ sx: [ -30, 0 ], ex: [ 5, 40 ], sy: [ 5, 40 ], ey: [ -30, 0 ] } // sw -> ne
];
*/

/*
this.g_animationManager.on_finished = function()
{
  this.g_current_slide++;
  if ( this.g_current_slide >= this.g_slides.length )
    this.g_current_slide = 0;
  this.g_slides[ this.g_current_slide ].start();
}
*/

SlideShow.prototype.rnd = function( start, end )
{
  return ( Math.random() * ( end - start ) ) + start;
}

SlideShow.prototype.load_slides = function( images, time )
{
  var ic = document.getElementById( this.containerName );
  this.g_slides = [];

  for( var i in images )
  {
    var img = images[i];

    var imgObj = document.createElement( 'img' );
    imgObj.style.position = 'absolute';
    imgObj.style.left = '0px';
    imgObj.style.top = '0px';
    imgObj.style.visibility = 'hidden';
    ic.appendChild( imgObj );

    var ii = new ImageInfo( img.src, imgObj );

  var szoom = this.rnd( 50, 100 );
  var ezoom = this.rnd( 70, 120 );

  var d = parseInt( ( Math.random() * this.g_directions.length ).toString() );
  var di = this.g_directions[ d ];
  var sx = this.rnd( di.sx[0], di.sx[1] );
  var sy = this.rnd( di.sy[0], di.sy[1] );
  var ex = this.rnd( di.ex[0], di.ex[1] );
  var ey = this.rnd( di.ey[0], di.ey[1] );

    this.g_slides.push( 
        new Animation( this.g_animationManager, ii, time, [new KenBurnsFader( ii, 1 )] )    
    //  new Animation( this.g_animationManager, ii, time, [new KenBurnsFader( ii, 10 )] )
    //[ new KenBurnsZoomer( ii, szoom, ezoom, ic.clientWidth, ic.clientHeight ),
    //  new KenBurnsMover( ii, sx, sy, ex, ey, ic.clientWidth, ic.clientHeight ),
    //  new KenBurnsFader( ii, 30 ) ] )
    );
  }
}

SlideShow.prototype.start_slides = function()
{
    if( this.g_slides.length > 0 )
        this.g_slides[ this.g_current_slide ].start();
}
