/*
// "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 sprive;
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",
                slideInterval: 4000,
                transitionDuration: 700,
                transitionText: 700,
                startIndex: 0,
                buttonOnClass: "navi-active",
                buttonOffClass: "off",
                rotateAction: "none",
                rotateActionDuration: 100,
                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: 500
                })
            }
        }
    },
    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()
        }
    },
    rotate: function () {
        curr = this.currentSlide;
        next = (curr + 1 >= this.slides.length) ? 0 : curr + 1;
		if(document.getElementById('li_slide'+(next+1)).offsetTop+73>292+document.getElementById('navi-outer').scrollTop) {
			sprive = setInterval(function(){
				if ((document.getElementById('li_slide'+(next+1)).offsetTop+73) - (292+document.getElementById('navi-outer').scrollTop) > 4) {
					//alert(Math.round(((document.getElementById('li_slide' + (next + 1)).offsetTop + 73) - (292 + document.getElementById('navi-outer').scrollTop)) / 8));
					document.getElementById('navi-outer').scrollTop += Math.round(((document.getElementById('li_slide' + (next + 1)).offsetTop + 72) - (292 + document.getElementById('navi-outer').scrollTop)) / 8);
				}
				else {
					document.getElementById('navi-outer').scrollTop+=5;
					clearInterval(sprive);
				}
			},10);
		}
		else if(document.getElementById('li_slide'+(next+1)).offsetTop<document.getElementById('navi-outer').scrollTop-1) {
			sprive = setInterval(function(){
				if((document.getElementById('navi-outer').scrollTop-1) - (document.getElementById('li_slide'+(next+1)).offsetTop)>4)
					document.getElementById('navi-outer').scrollTop -= Math.round(((document.getElementById('navi-outer').scrollTop) - (document.getElementById('li_slide'+(next+1)).offsetTop))/8);
				else {
					document.getElementById('navi-outer').scrollTop-=5;
					clearInterval(sprive);
				}
			},10);
		}
        this.showSlide(next);
        this.options.onRotate()
    },
    autoplay: function () {
        this.slideshowInt = this.rotate.periodical(this.options.slideInterval, this);
        this.options.onAutoPlay()
    },
    stop: function () {
        clearInterval(this.slideshowInt);
        this.options.onStop();
    },
    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 = 300;
var crossFadeDelay = 4000;
var crossFadeSpeed = 1000;
var CTRtext_effect = false;
var CTRtransitionText = 1000;
var navTrigger = 'click';
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() {}
