﻿var rotatorItemsContainer;
var tweenFx;
var myTimer;
var current = 1;

window.addEvent('domready', function() {
    rotatorItemsContainer = $('RotatorItemsContainer');
    var rotator = $('RotatorItemsContainer').getParent();
    var width = rotator.getStyle('width').toInt();
    var delay = $('RotatorDelay').getProperty('value').toInt();
    $('RotatorPosition' + current).setStyle('background-image', 'url(Images/positionBg.jpg)');

    var rotate = function() {
        tweenFx = new Fx.Tween(this, { transition: Fx.Transitions.Sine.easeOut, duration: 200 });

        $('RotatorPosition' + current).setStyle('background-image', '');

        if (this.getStyle('left').toInt() - width > $('RotatorItemsContainer').getStyle('width').toInt() * -1) {
            /*
            $$('.RotatorOverlay').each(function(element) {
                element.fade('hide');
                element.fade('in');
            });
            */
            tweenFx.start('left', this.getStyle('left').toInt() - width);
            current++;
            //this.tween('left', this.getStyle('left').toInt() - width);
        }
        else {
            tweenFx.start('left', 0);
            current = 1;
            //this.tween('left', 0);
        }

        $('RotatorPosition' + current).setStyle('background-image', 'url(Images/positionBg.jpg)');
    };

    /*
    $('RotatorBigAd').set('tween', { duration: 'short' });
    $('RotatorAdBtnExpand').addEvent('click', function() {
        $('RotatorBigAd').tween('height', 351);
    });
    $('RotatorAdBtnClose').addEvent('click', function() {
        $('RotatorBigAd').tween('height', 0);
    });

    (function() {
        $('RotatorBigAd').tween('height', 0);
        myTimer = rotate.periodical(delay, rotatorItemsContainer);
    }).delay(5000);
    */

    myTimer = rotate.periodical(delay, rotatorItemsContainer);
});

function RotateTo(location) {
    $clear(myTimer);
    $('RotatorPosition' + current).setStyle('background-image', '');
    current = location;
    $('RotatorPosition' + current).setStyle('background-image', 'url(Images/positionBg.jpg)');
    tweenFx.start('left', $('RotatorItem' + location).getStyle('left').toInt() * -1);
}