/*
// "Frontpage Slideshow" Module for Joomla! 1.5.x - Version 2.0.0
// Copyright (c) 2006 - 2008 JoomlaWorks. All rights reserved.
// This code cannot be redistributed without permission from JoomlaWorks - http://www.joomlaworks.gr.
// More info at http://www.joomlaworks.gr and http://www.frontpageslideshow.net
// Designed and developed by the JoomlaWorks team
// ***Last update: September 1st, 2008***
*/

var fpslideshow = null;
var jwFPSS = new Class({
	initialize: function (a, b) {
		this.container = $(a);
		if (!this.container.hasClass('hasFPSS')) {
			this.container.addClass('hasFPSS');
			this.slides = [];
			this.buttons = [];
			this.slidetexts = [];
			this.textFx = new Array();
			this.options = Object.extend({
				onRotate: Class.create(),
				onStop: Class.create(),
				onAutoPlay: Class.create(),
				onShowSlide: Class.create(),
				slidesSelector: ".slide",
				buttonsSelector: ".navbutton",
				slidetextSelector: ".slidetext",
				
				startIndex: 0,
				buttonOnClass: "navi-active",
				buttonOffClass: "off",
				rotateAction: "mouseover",
				rotateActionDuration: 1,
				autoplay: true,
				PauseText: "Pause",
				PlayText: "Play",
				text_effect: false,
				stop: false
			},
			b || {});
			this.slides = $(a).getElements(this.options.slidesSelector);
			this.buttons = $(a).getElements(this.options.buttonsSelector);
			this.slidetexts = $$(this.options.slidetextSelector);
			this.createFx();
			this.showSlide(this.options.startIndex);
			if (this.options.autoplay) this.autoplay();
			if (this.options.rotateAction != 'none') this.setupAction(this.options.rotateAction);
			return this
		} else return false
	},
	setupAction: function (c) {
		this.buttons.each(function (a, b) {
			$(a).addEvent(c, function () {
				this.slideFx.setOptions(this.slideFx.options, {
					duration: this.options.transitionDuration
				});
				if (this.currentSlide != b) this.selected(b);
				if (this.options.stop) {
					this.stop()
				}
			}.bind(this))
		},
		this);
		$(this.container.id + "_prev").addEvent(c, function () {
			this.prev();
			if (this.options.stop) {
				$(this.container.id + "_playButton").innerHTML = this.options.PlayText;
				$(this.container.id + "_playButton").addClass('pause');
				this.stop()
			}
		}.bind(this));
		$(this.container.id + "_next").addEvent(c, function () {
			this.next();
			if (this.options.stop) {
				$(this.container.id + "_playButton").innerHTML = this.options.PlayText;
				$(this.container.id + "_playButton").addClass('pause');
				this.stop()
			}
		}.bind(this));
		$(this.container.id + "_playButton").addEvent(c, function () {
			if ($(this.container.id + "_playButton").hasClass('pause')) {
				$(this.container.id + "_playButton").innerHTML = this.options.PauseText;
				$(this.container.id + "_playButton").removeClass('pause');
				this.autoplay()
			} else {
				$(this.container.id + "_playButton").innerHTML = this.options.PlayText;
				$(this.container.id + "_playButton").addClass('pause');
				this.stop()
			}
		}.bind(this))
	},
	createFx: function () {
		this.slideFx = new Fx.Elements(this.slides, {
			duration: this.options.transitionDuration
		});
		this.slides.each(function (a) {
			a.setStyle('opacity', 0)
		});
		if (this.options.text_effect) {
			for (var i = 0; i < this.slidetexts.length; i++) {
				this.textFx[i] = new Fx.Slide(this.slidetexts[i], {
					duration: 5
				})
			}
		}
	},
	showSlide: function (c) {
		var d = {};
		this.slides.each(function (a, b) {
			if (b == c && b != this.currentSlide) {
				$(this.buttons[b]).removeClass(this.options.buttonOffClass).addClass(this.options.buttonOnClass);
				d[b.toString()] = {
					'opacity': [1]
				};
				textIndex = b
			} else {
				$(this.buttons[b]).removeClass(this.options.buttonOnClass).addClass(this.options.buttonOffClass);
				d[b.toString()] = {
					'opacity': [0]
				};
				if (this.options.text_effect) this.textFx[b].slideOut()
			}
		},
		this);
		this.options.onShowSlide(c);
		this.currentSlide = c;
		this.slideFx.start(d);
		if (this.options.text_effect) {
			this.textFx[textIndex].hide();
			this.textFx[textIndex].slideIn()
		}
	},
	autoplay: function () {
		this.slideshowInt = this.rotate.periodical(this.options.slideInterval, this);
		this.options.onAutoPlay()
	},
	stop: function () {
		clearInterval(this.slideshowInt);
		this.options.onStop()
	},
	rotate: function () {
		curr = this.currentSlide;
		next = (curr + 1 >= this.slides.length) ? 0 : curr + 1;
		this.showSlide(next);
		this.options.onRotate()
	},
	next: function () {
		curr = this.currentSlide;
		next = (curr + 1 >= this.slides.length) ? 0 : curr + 1;
		clearInterval(this.slideshowInt);
		this.showSlide(next);
		this.autoplay();
		this.options.onRotate()
	},
	prev: function () {
		curr = this.currentSlide;
		prev = (curr - 1 < 0) ? this.slides.length - 1 : curr - 1;
		clearInterval(this.slideshowInt);
		this.showSlide(prev);
		this.autoplay();
		this.options.onRotate()
	},
	selected: function (a) {
		clearInterval(this.slideshowInt);
		this.showSlide(a);
		this.autoplay();
		this.options.onRotate()
	},
	show: function () {
		$(this.options.fpslideshowContainer).setStyle('visibility', 'visible');
		if (!$(this.options.fpslideshowContainer).visible()) $(this.options.fpslideshowContainer).show()
	},
	hide: function () {
		$(this.options.fpslideshowContainer).setStyle('visibility', 'hidden')
	}
});
var fpssLoaderDelay = 0;
var crossFadeDelay = 0;
var crossFadeSpeed = 1;
var CTRtext_effect = true;
var CTRtransitionText = 0;
var slideLoading = 'slide-loading';
var slideOuter = 'slide-wrapper';
var fpssPlayText = "Play";
var fpssPauseText = "Pause";
var autoslide = true;
function init_fpss() {
	if ($(slideLoading)) $(slideLoading).setStyle('display', 'none');
	else return;
	if ($(slideOuter)) $(slideOuter).setStyle('display', 'block');
	else return;
	startJWFPSS = new jwFPSS($('fpss-container'), {
		slideInterval: crossFadeDelay,
		transitionDuration: crossFadeSpeed,
		transitionText: CTRtransitionText,
		rotateAction: navTrigger,
		PlayText: fpssPlayText,
		PauseText: fpssPauseText,
		autoplay: autoslide,
		text_effect: CTRtext_effect,
		stop: false
	})
}
window.addEvent('domready', function () {
	if ($('fpss-container')) {
		setTimeout('init_fpss();', fpssLoaderDelay)
	}
});
function ppButtonClicked() {}
function clearSlide() {}
function showPrev() {}
function showNext() {}
