g_w = 850;
g_h = 300;

var effect;
var orchestration;

/*  */
the_effect = 'Effect.Shrink';

var orc = function (i, j) {
	return Math.log(Math.abs(i)+1)/Math.log(10) * 400 + j * 50;
};






function resetSlideshow() {
	
	if ($('grid_10x10').checked) {
		g_w = 10;
		g_h = 10;
	}
	else if ($('grid_1x20').checked) {
		g_w = 1;
		g_h = 20;
	}
	else if ($('grid_20x1').checked) {
		g_w = 20;
		g_h = 1;
	}

	if ($('effect_flip').checked) {
		the_effect = 'flip';
	}
	else if ($('effect_flip_h').checked) {
		the_effect = 'flip_h';
	}
	else if ($('effect_shrink').checked) {
		the_effect = 'Effect.Shrink';
	}
	else if ($('effect_dropout').checked) {
		the_effect = 'Effect.DropOut';
	}

	if ($('orc_tl').checked) {
		orc = function (i, j) {
			return Math.log(Math.abs(i)+1)/Math.log(10) * 400 + j * 50;
		}
	}
	else if ($('orc_br').checked) {
		orc = function (i, j) {
			return Math.log(Math.abs(g_w-i+1))/Math.log(g_w) * 500 + (g_h-j) * 80;
		}
	}
	else if ($('orc_middle').checked) {
		orc = function (i, j) {
			return Math.abs(g_w/2 - i) * 80 + Math.abs(g_h/2 - j) * 80;
		}
	}
	
	document.getElementsByClassName('outerGrid').each(function (u) {
		u.parentNode.removeChild(u);
	});

	slideShow.image_element.src = 'images/demo-photos/3.jpg';
	slideShow = new SlideShow(['images/demo-photos/3.jpg', 'images/demo-photos/2.jpg'], {'tiles_x': g_w, 'tiles_y': g_h, 'transition': the_effect, 'tile_orchestration': orc});

}

function resetSlideshow2() {
	/*
	var images = Array();
	images[0] = ('slideshow/slide1.jpg');
	images[1] = ('slideshow/slide2.jpg');
	images[2] = ('slideshow/slide3.jpg');
	images[3] = ('slideshow/slide4.jpg');
	images[4] = ('slideshow/slide5.jpg');
	images[5] = ('slideshow/slide6.jpg');
	images[6] = ('slideshow/slide7.jpg');
	images[7] = ('slideshow/slide8.jpg');
	images[8] = ('slideshow/slide9.jpg');
	
	
	/*   */
	
	
	effect=Math.floor(Math.random()*10 % 4);
	effect++;
	orchestration=Math.floor(Math.random()*10 % 3);
	
	orchestration++;
	
	//alert('Effect ' + effect + '\nOrchestration ' + orchestration);
	
	switch (effect)
	{
	    case 1:
	        
	        the_effect = 'flip';
	        break;
	    case 2:
	       ;
	        the_effect = 'flip_h';
	        break;
	    case 3:
	        
	        the_effect = 'Effect.Shrink';
	        break;
	    case 4:
	    
	        the_effect = 'Effect.DropOut';
	        break;
	    
	}
	
	
	
	switch (orchestration)
	{
	    case 1:
	        orc = function (i, j) {
				return Math.log(Math.abs(i)+1)/Math.log(10) * 400 + j * 50;
			}
	        break;
	    case 2:
		    orc = function (i, j) {
				return Math.log(Math.abs(g_w-i+1))/Math.log(g_w) * 500 + (g_h-j) * 80;
			}
	        break;
	    case 3:
	        orc = function (i, j) {
				return Math.abs(g_w/2 - i) * 80 + Math.abs(g_h/2 - j) * 80;
			}
	        break;
	    
	    
	}
	
	
	
	
	
	/*  */
	
	
	/*  */
	document.getElementsByClassName('outerGrid').each(function (u) {
		u.parentNode.removeChild(u);
	});
	 /* */
	slideShow.image_element.src = 'image/slide3.jpg';
	slideShow = new SlideShow(['image/slide1.jpg', 'image/slide2.jpg','image/slide3.jpg', 'image/slide4.jpg', 'image/slide5.jpg','image/slide6.jpg','image/slide7.jpg','image/slide8.jpg','image/slide9.jpg' ], {'tiles_x': g_w, 'tiles_y': g_h, 'transition': the_effect, 'tile_orchestration': orc});
/*  */

	//ReturnSlide();
	//return slideShow.next();
}

function LoadSlideShow()
{
	
	var images = Array();
	images[0] = ('image/slide1.jpg');
	images[1] = ('image/slide2.jpg');
	images[2] = ('image/slide3.jpg');
	images[3] = ('image/slide4.jpg');
	images[4] = ('image/slide5.jpg');
	images[5] = ('image/slide6.jpg');
	images[6] = ('image/slide7.jpg');
	images[7] = ('image/slide8.jpg');
	images[8] = ('image/slide9.jpg');
	
	
	idx=Math.floor(Math.random()*10 % 9);
	
	image1 = images[idx];

	idx=Math.floor(Math.random()*10 % 9);	
	image2 = images[idx];
	
	
	//alert(image1 + '\r\n' + image2);
	g_w = 20;
	g_h = 1;
	
	var effect;
	var orchestration;
	effect=Math.floor(Math.random()*10 % 4);

	orchestration=Math.floor(Math.random()*10 % 3);
	

	
	//alert('Effect ' + effect + '\nOrchestration ' + orchestration);
	
	switch (effect)
	{
	    case 0:
	        
	        the_effect = 'flip';
	        break;
	    case 1:
	       ;
	        the_effect = 'flip_h';
	        break;
	    case 2:
	        
	        the_effect = 'Effect.Shrink';
	        break;
	    case 3:
	    
	        the_effect = 'Effect.DropOut';
	        break;
	    
	}
	
	
	
	switch (orchestration)
	{
	    case 0:
	        orc = function (i, j) {
				return Math.log(Math.abs(i)+1)/Math.log(10) * 1400 + j * 50;
			}
	        break;
	    case 1:
		    orc = function (i, j) {
				return Math.log(Math.abs(g_w-i+1))/Math.log(g_w) * 1500 + (g_h-j) * 80;
			}
	        break;
	    case 2:
	        orc = function (i, j) {
				return Math.abs(g_w/2 - i) * 80 + Math.abs(g_h/2 - j) * 80;
			}
	        break;
	    
	    
	}
	
	document.getElementsByClassName('outerGrid').each(function (u) {
		u.parentNode.removeChild(u);
	});

//	slideShow.image_element.src = image1;
//	slideShow = new SlideShow(['image/slide1.jpg', 'image/slide2.jpg','image/slide3.jpg', 'image/slide4.jpg', 'image/slide5.jpg','image/slide6.jpg','image/slide7.jpg','image/slide8.jpg','image/slide9.jpg' ], {'tiles_x': g_w, 'tiles_y': g_h, 'transition': the_effect, 'tile_orchestration': orc});
	slideShow = new SlideShow([image2 ], {'tiles_x': g_w, 'tiles_y': g_h, 'transition': the_effect, 'tile_orchestration': orc});
}

function ChangeSlide()
{
	LoadSlideShow();
	//resetSlideshow2();
	return slideShow.next();
}
