/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * @category  Symmetrics
 * @package   Symmetrics_DasGibtsNurEinmal
 * @author    symmetrics gmbh <info@symmetrics.de>
 * @author    Eric Reiche <er@symmetrics.de>
 * @author    Eugen Gitin <eg@symmetrics.de>
 * @copyright 2009-2010 symmetrics gmbh
 * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 * @link      http://www.symmetrics.de/
 */

brandsShown = 4; //Simultaniously
brandHeight = 55;
position = 0;

document.observe('dom:loaded', function() {
    
    function brandsCanDown() {
        return (position > -1 * brandHeight * (brandsCount - brandsShown));
    }
    function brandsCanUp() {
        return (position < 0);
    }

    downHover = function(evt) {
        if(brandsCanDown()) {
            this.style.backgroundPosition = '0';
            this.style.cursor = "pointer";
        }
    }
    upHover = function(evt) {
        if(brandsCanUp()) {
            this.style.backgroundPosition = '0';
            this.style.cursor = "pointer";
        }
    }
    downMouseout = function(evt) {
        this.style.backgroundPosition = '-78px';
        this.style.cursor = "auto";
    }
    upMouseout = function(evt) {
        this.style.backgroundPosition = '-78px';
        this.style.cursor = "auto";
    }
    
    brandsDown = function () {
        if (brandsCanDown()){
            position = position - scrollAmount * brandHeight;
            new Effect.Move( slideElement, { y: position, mode: 'absolute' });
        }
    }
    brandsUp = function () {
        if(brandsCanUp()) {
            position = position + scrollAmount * brandHeight
            new Effect.Move( slideElement, { y: position, mode: 'absolute' });
        }
    }
    
    arrowUp = $('brands-arrow-up');
    arrowDown = $('brands-arrow-down');

    if(brandsUp) {
        arrowUp.observe('click', brandsUp);
    }
    if(brandsDown) {
        arrowDown.observe('click', brandsDown);
    }
    if(upHover) {
        arrowUp.observe('mouseover', upHover);
    }
    if(downHover) {
        arrowDown.observe('mouseover', downHover);
    }
    if(upMouseout) {
        arrowUp.observe('mouseout', upMouseout);
    }
    if(downMouseout) {
        arrowDown.observe('mouseout', downMouseout);
    }
});

document.observe('dom:loaded', function() {
    HoverBrand = function(evt) {
        this.style.backgroundPosition = '-200px';
    }
    HoverBrandOut = function(evt) {
        this.style.backgroundPosition = '0';
    }
    
    brandLis = $$('.block-brands .block-content .slide-wrapper ul li');
    brandsCount = 0;
    
    for (var i = 0; i < brandLis.length; ++i) {
        brandLi = brandLis[i];
        brandLi.observe('mouseover', HoverBrand);
        brandLi.observe('mouseout', HoverBrandOut);
        brandsCount++;
    }
        
});
document.observe('dom:loaded', function() {
    //teaser scrolling
    teaserElement = $$('.big-teaser .teaser-bg')[0];
    teaserButtons = $$('.big-teaser .teaser-buttons li');
    teaser_position = 0;
    teaser_step = 1;
    teaser_stop = false;
    
    teaser_cycle = function() {
        if(!teaser_stop) {
            if(teaser_step < teaser_amount) {
                teaser_position = -1 * teaser_step * teaser_width;
                teaser_step++;
            }
            else {
                teaser_position = 0;
                teaser_step = 1;
            }
            new Effect.Move( teaserElement, { x: teaser_position, mode: 'absolute' });
        }
    }
    if(teaser_interval) {
        new PeriodicalExecuter(teaser_cycle, teaser_interval);
    }
    teaser_skip = new Array();
    for (var j = 0; j < teaserButtons.length; ++j) {
        teaserButtons[j].observe('mouseover', function(evt) {
            this.style.backgroundPosition = '-202px bottom';
        });
        teaserButtons[j].observe('mouseout', function(evt) {
            this.style.backgroundPosition = '0 bottom';
        });
        teaserButtons[j].observe('click', function(evt) {
            evt.stop();
            teaser_stop = true;
            teaser_step = parseInt(this.className) - 1;
            teaser_position = -1 * teaser_step * teaser_width;
            new Effect.Move( teaserElement, { x: teaser_position, mode: 'absolute' });
        });
    }
    
});
document.observe('dom:loaded', function() {
    teaserButtonsOverall = $$('.block-offers .teaser-buttons li');
    
    for (var j = 0; j < teaserButtonsOverall.length; ++j) {
        teaserButtonsOverall[j].observe('mouseover', function(evt) {
            this.style.backgroundPosition = '-202px bottom';
        });
        teaserButtonsOverall[j].observe('mouseout', function(evt) {
            this.style.backgroundPosition = '0 bottom';
        });
    }
    
});


document.observe('dom:loaded', function() {
    
    tpButtons = $$('.cms-home .hover');
    
    for (var j = 0; j < tpButtons.length; ++j) {
        tpButtons[j].observe('mouseover', function(evt) {
            this.style.backgroundPosition = '0 -32px';
        });
        tpButtons[j].observe('mouseout', function(evt) {
            this.style.backgroundPosition = ' 0 0';
        });
    }
    
    rightbarbtns = $$('.block-present .hover');
    
    for (var j = 0; j < rightbarbtns.length; ++j) {
        rightbarbtns[j].observe('mouseover', function(evt) {
            this.style.backgroundPosition = '0 -32px';
        });
        rightbarbtns[j].observe('mouseout', function(evt) {
            this.style.backgroundPosition = ' 0 0';
        });
    }
});

