// JavaScript Document
// Combines Fade and Slide effects.
//
FadeSlide = function(element, options)
{
	Spry.Effect.Cluster.call(this, options);
	var duration = 1000;
	var from = 0;
	var to = 100;
	var transition = Spry.fifthTransition;
	var toggle = false;
	if (options)
	{
		if (options.duration != null) duration = options.duration;
		if (options.from != null) from = options.from;
		if (options.to != null) to = options.to;
		if (options.transition != null) transition = options.transition;
	}
	var fadeEffect = new Spry.Effect.Fade(element, {duration: duration, from: from, to: to, transition: transition, toggle: toggle});
	var blindEffect = new Spry.Effect.Blind(element, {duration: duration, from: from, to: to, transition: transition, toggle: toggle});
	this.addParallelEffect(fadeEffect);
	this.addParallelEffect(blindEffect);
};
FadeSlide.prototype = new Spry.Effect.Cluster();
FadeSlide.prototype.constructor = FadeSlide;

//
//Combines Fade and Grow effects
//
FadeGrow = function(element, options)
{
	Spry.Effect.Cluster.call(this, options);
	var duration = 1000;
	var from = 0;
	var to = 100;
	var transition = Spry.fifthTransition;
	var toggle = false;
	if (options)
	{
		if (options.duration != null) duration = options.duration;
		if (options.from != null) from = options.from;
		if (options.to != null) to = options.to;
		if (options.transition != null) transition = options.transition;
		if (options.toggle != null) toggle = options.toggle;
	}
	var fadeEffect = new Spry.Effect.Fade(element, {duration: duration, from: from, to: to, transition: transition, toggle: toggle});
	var growEffect = new Spry.Effect.Grow(element, {duration: duration, from: from, to: to, transition: transition, toggle: toggle});
	this.addParallelEffect(fadeEffect);
	this.addParallelEffect(growEffect);
};
FadeGrow.prototype = new Spry.Effect.Cluster();
FadeGrow.prototype.constructor = FadeGrow;

//
//Multiple slide effect. Slide visible out and new selected panel in.
//
var observer = {};

observer.nextEffect = false;
observer.onPostEffect = function(e){
	if (this.nextEffect)
	{
		var eff = this.nextEffect;
		setTimeout(function(){eff.start();}, 10);
	}

	this.nextEffect = false;
}

function myPanelsSlides(currentPanel)
{
    // The list of all the panels that need sliding
	//var panels = ['slide0','slide1','slide2','slide3','slide4','slide5','slide6','slide7','slide8','slide9'];
	var opened = -1;

	// Let's check if we have an effect for each of these sliding panels
	if (typeof effects == 'undefined')
		effects = {};

	for (var i=0; i < panels.length; i++)
	{
		if (typeof effects[panels[i]] == 'undefined'){
			effects[panels[i]] = new Spry.Effect.Slide(panels[i], {from: '0%', to: '100%', toggle: true});
			effects[panels[i]].addObserver(observer);
		}
		 
		if (effects[panels[i]].direction == Spry.forwards && currentPanel != panels[i])
			opened = i;

		//prevent too fast clicks on the buttons
		if (effects[panels[i]].direction == Spry.backwards && effects[panels[i]].isRunning)
		{
			observer.nextEffect = effects[currentPanel];
			return;
		}
	}

	if (opened != -1)
	{
		observer.nextEffect = effects[currentPanel];
		effects[panels[opened]].start();
	} 
	else if (effects[currentPanel].direction != Spry.forwards)
	{
		effects[currentPanel].start();
	}
};