﻿window.addEvent('domready', function() {

    SetWidthOfScrollArea();
    StartScroller();
});

function SetWidthOfScrollArea() {

    var totalWidth = 0;
    var galleryImages = $$('div.galleryImage');

    galleryImages.each(function(item) {
        totalWidth += GetWidth(item);
    });

    $$('div.galleryImages').setStyle('width', totalWidth + 'px');
    $$('div.galleryLoader_bottom').setStyle('width', totalWidth + 'px');
    $$('div.galleryLoader_top').setStyle('width', totalWidth + 'px');
}

function GetWidth(item) {

    var width = item.getStyle('width');
    if (width == null || width == '') {
        return 0;
    }
    width = width.substring(0, width.length - 2);
    return parseInt(width);
}

function StartScroller() {

    var loaderWrapper = $('loaderWrapper');

    loaderWrapper.scroller = new Scroller(loaderWrapper, {
        area: 100,
        velocity: 0.2
    });

    loaderWrapper.elementScroller = new Fx.Scroll(loaderWrapper, {
        duration: 400,
        onStart: loaderWrapper.scroller.stop.bind(loaderWrapper.scroller),
        onComplete: loaderWrapper.scroller.start.bind(loaderWrapper.scroller)
    });

    loaderWrapper.scroller.start();
}

