
    var actualX = 0;
    var minX = -400;

    function moveCoverflow(dir,step)
    {
        actualX += dir * step ;
        document.getElementById("cf-content").style.left = actualX + "px" ;
        if(actualX <= minX)
        {
            document.getElementById("arrow-links").style.display = "none";
        }
        else
        {
            document.getElementById("arrow-links").style.display = "block";
        }
        if(actualX >= 0)
        {
            document.getElementById("arrow-rechts").style.display = "none" ;
        }
        else
        {
            document.getElementById("arrow-rechts").style.display = "block" ;
        }

    }

    function openWin(url,width,height)
    {
        Extern = window.open(url,"Extern","width=" + width + ",height=" + height + ",resizable=no,scrollbars=auto,toolbar=no,status=yes,menubar=no,locationbar=no,screenX=50,screenY=50");
        if (Extern) {
            return false;
        } else {
            return true;
        }
    }


    function checkKontaktForm()
    {
       var error = false
       if (self.document.kontaktFormular.email.value.length==0)
       {
           alert("Bitte eine g&#252;ltige E-Mail Adresse eintragen!");
           error = true;
       }
       if (!error)
       {
          self.document.kontaktFormular.submit();
       }
    }

    function openlivebookpopup(url)
    {
        var ok = window.open(url,"_blank","width=1218,height=720,status=yes,scrollbars=yes,resizable=yes")
        if (ok) {
            return false;
        } else {
            return true;
        }
    }

    function showEbookTest(event) {
        new Effect.Appear('ebook-test', { duration: 0.6 });
    }







/*  ==========================================================================================================  */
/*  The Slider
/*  ==========================================================================================================  */

    var SlidingBox = Class.create({

        // Don't like the CSS classnames? Change'em here...
        classNames : {
            slider          : 'slider',         //
            slideLeft       : 'slide-left',     //
            slideRight      : 'slide-right',    //
            slideMask       : 'slide-mask',     //
            slideContent    : 'slide-content'   //
        },

        setOptions: function(opt) {
            this.options = {
                increments: null,
                duration: 1,
                autoslide: false,
                delay: 8
            };
            Object.extend(this.options, opt || {});
        },

        initialize: function(sbox, opt) {
            // Set the options
            this.setOptions(opt);
            if (this.options.autoslide === true) this.options.infinite = true;

            // set up some vars
            this.slider         = sbox;
            this.container      = this.slider.down('.'+this.classNames.slideContent);
            this.mask           = this.slider.down('.'+this.classNames.slideMask);
            this.item           = this.container.firstDescendant('li');
            this.itemCount      = this.container.childElements('li').size();
            this.itemWidth      = this.getItemWidth();
            this.increments     = this.getIncrements();
            this.scroll_offset  = this.itemWidth * this.increments;
            this.triggerLeft    = this.slider.down('.'+this.classNames.slideLeft);
            this.triggerRight   = this.slider.down('.'+this.classNames.slideRight);

            this.triggerLeft.style.visibility = 'visible';
            this.triggerRight.style.visibility = 'visible';
            // set up the slide-container width
            this.setSlidingContainer();
            // initially disable triggers, slideLeft always...
            $$('.'+this.classNames.slideLeft).invoke('addClassName', 'inactive');
            // ... and slideRight, if there are too few items in the slider
            if (this.itemCount <= this.increments) {
                $$('.'+this.classNames.slideRight).invoke('addClassName', 'inactive');
            }
            if (this.options.autoslide === true) {
                this.horizontal_slider();
            }
        },

        getItemWidth: function() {
            var itemWidth = (this.item.getWidth()) + (parseInt(this.item.getStyle('margin-right'))) + (parseInt(this.item.getStyle('margin-left')));
            return itemWidth;
        },

        // how many items to move at a time
        getIncrements: function() {
            // Either it's declared by options
            if (this.options.increments !== null) {
                this.increments = this.options.increments;
            // or increment is set to the number of visible items
            } else {
                var maskWidth = this.mask.getWidth();
                this.increments = Math.round(maskWidth / this.itemWidth);
            }
            return this.increments;
        },

        setSlidingContainer: function() {
            var containerWidth  = (this.itemWidth * this.itemCount);
            this.container.setStyle({
                left: 0,
                width: containerWidth + 'px'
            });
            // now, bind event handler to the box
            this.slider.observe('click', this.slideBoxEvents.bindAsEventListener(this));
        },

        // figure out which element was clicked and say what happens next
        slideBoxEvents: function(event) {
            var trigger = event.element();
            if ((trigger.match('.'+this.classNames.slideLeft) || trigger.match('.'+this.classNames.slideRight))) {
                Event.stop(event); // stop default behaviour of trigger element
                if (!trigger.hasClassName('inactive')) {
                    this.horizontal_slider(trigger);
                }
            } else return;
        },

        // Same as slideRight, but separated to run in it's own scope (effect queue)
        autoSlide: function(trigger, scroll_offset, duration, lastMargin, max_position, maskSize, startOver) {
            if (this.options.autoslide) {
                window.clearTimeout(this.timeoutId);
            }

            new Effect.Move(this.container, {
                x: -(scroll_offset),
                y: 0,
                mode: 'relative',
                duration: duration,
                queue: {position: 'end', scope: 'autoslide', limit: 0}, // Do never limit this, it would destroy multiple auto-sliders with same delay
                afterFinish: function() {
                    max_position = max_position - scroll_offset - lastMargin;
                    // toggle triggers inactive-state
                    if (max_position <= maskSize) {
                        trigger.addClassName('endpoint');
                    }
                    this.triggerLeft.removeClassName('inactive');
                    this.horizontal_slider();
                }.bind(this)
            });
        },

        slideRight: function(trigger, scroll_offset, duration, lastMargin, max_position, maskSize, startOver) {
            if (this.options.autoslide) {
                window.clearTimeout(this.timeoutId);
            }
            new Effect.Move(this.container, {
                x: -(scroll_offset),
                y: 0,
                mode: 'relative',
                duration: duration,
                queue: {position: 'end', scope: 'anims', limit: 1},
                afterFinish: function() {
                    max_position = max_position - scroll_offset - lastMargin;
                    // toggle triggers inactive-state
                    if (max_position <= maskSize) {
                        if (startOver === true) {
                            trigger.addClassName('endpoint')
                        } else {
                            trigger.addClassName('inactive');
                        }
                    }
                    this.triggerLeft.removeClassName('inactive');
                    if (this.options.autoslide) {
                        this.horizontal_slider();
                    }
                }.bind(this)
            });
        },

        slideLeft: function(trigger, scroll_offset, duration) {
            var scroll_target = this.container;

            if (this.options.autoslide) {
                window.clearTimeout(this.timeoutId);
            }
            new Effect.Move(scroll_target, {
                x: scroll_offset,
                y: 0,
                mode: 'relative',
                duration: duration,
                queue: {position: 'end', scope: 'anims', limit: 1},
                afterFinish: function() {
                    actual_position = parseInt(scroll_target.getStyle('left'));
                    // toggle triggers inactive-state
                    if (actual_position >= 0) {
                        trigger.addClassName('inactive');
                    }
                    this.triggerRight.removeClassName('inactive').removeClassName('endpoint');
                    if (this.options.autoslide) {
                        this.horizontal_slider();
                    }
                }.bind(this)
            });
        },

        slideBack: function(duration) {
            new Effect.Move(this.container, {
                x: 0,
                y: 0,
                mode: 'absolute',
                duration: duration,
                queue: {position: 'end', scope: 'anims', limit: 0}, // Do never limit this, it would destroy multiple auto-sliders with same delay
                afterFinish: function() {
                    this.triggerRight.removeClassName('inactive').removeClassName('endpoint');
                    this.triggerLeft.addClassName('inactive');
                    if (this.options.autoslide === true) {
                        this.horizontal_slider();
                    }
                }.bind(this)
            });
        },

        horizontal_slider: function(trigger) {
            var maskSize        = this.mask.getWidth();
            var lastMargin      = parseInt(this.item.getStyle('margin-right'));
            var startOver       = this.options.infinite;
            var duration        = this.options.duration;
            var scroll_offset   = this.scroll_offset;
            var actual_position = (Math.abs(parseFloat(this.container.style.left)));
            var max_position    = parseInt(this.container.getStyle('width')) - actual_position;
            var containerWidth  = (this.itemWidth * this.itemCount);

            if (this.options.autoslide === true && trigger === undefined) {
                var delay     = this.options.delay;
                var trigger   = this.triggerRight;

                var sb = this.slideBack.bind(this, duration); // slideBack
                var as = this.autoSlide.bind(this, trigger, scroll_offset, duration, lastMargin, max_position, maskSize, startOver); // autoSlide

                if (max_position <= (maskSize + lastMargin)) {
                    this.timeoutId  = window.setTimeout(function() {sb();}, delay * 1000);
                } else {
                    this.timeoutId  = window.setTimeout(function() {as();}, delay * 1000);
                }
            }
            // Slide right
            else if (trigger.hasClassName(this.classNames.slideRight)) {
                var newOffset = containerWidth - maskSize - actual_position;
                if (scroll_offset > newOffset) {
                    var newInc = Math.round(newOffset / this.itemWidth);
                    scroll_offset = this.itemWidth * newInc;
                }
                // if set to infinite, start over
                if (startOver === true && trigger.hasClassName('endpoint')) {
                    this.slideBack(duration);
                }
                // standard movement
                if (max_position > maskSize) {
                    this.slideRight(trigger, scroll_offset, duration, lastMargin, max_position, maskSize, startOver);
                }
            // Slide left
            } else if (trigger.hasClassName(this.classNames.slideLeft)) {
                if (actual_position < scroll_offset) {
                    this.slideBack(duration);
                } else if (actual_position != '0') {
                    this.slideLeft(trigger, scroll_offset, duration);
                }
            }
        }
    });

function init() {
    if ($('ebook-slider')) {
        new SlidingBox($('ebook-slider'), {
            increments:1,
            duration:.5,
            autoslide: true,
            delay: 10
        });
    }
    if ($('neuheiten-slider')) {
        new SlidingBox($('neuheiten-slider'), {
            increments:1,
            duration:.5,
            autoslide: true,
            delay: 10
        });
    }
    if ($$('.slider').length) {
        $$('.slider').each(function(el) {
            new SlidingBox(el, {});
        });
    }
}


document.observe('dom:loaded', init);






