﻿fx.Background = Class.create();

fx.Background.prototype = Object.extend(new fx.Base(), {
    initialize: function(el, options) {
        this.el = $(el);
        this.setOptions(options);
        this.now = 0;
    },
    
    increase: function() {
        this.el.style.backgroundPosition = this.now + "px";
    },
    
    scroll: function(howMuch){
        this.clearTimer();
        this.custom(this.now, this.now + howMuch)
    }
});

var _Effect = null;
var currentPos = 1;
var scrolling = false;
var imageWidth = 1505; //Width (px) of reports.gif
var numberImage = 7; //Number of reports in report reports.gif
var scrollingTimer = null;
var duration = 500;

function LoadReport()
{
	_Effect = new fx.Background('ScrollContainer', {duration: duration});   
}
    
function ShowReport( reportNum )
{
    if(scrolling || (_Effect == null)) return;
    
    if(reportNum != currentPos)
    {
        scrolling = true;
        
        var scroll = 0;
    
        if(reportNum > currentPos)
        {
            scroll = (reportNum - currentPos)*(imageWidth / numberImage);
            
            _Effect.scroll(-scroll);
            
            scrollingTimer = setTimeout("endScroll()", duration);
        }
        else
        {
            scroll = (currentPos - reportNum)*(imageWidth / numberImage);
            
            _Effect.scroll(scroll);
            
            scrollingTimer = setTimeout("endScroll()", duration);
        }
        
        currentPos = reportNum;
    }
}

function next()
{
    if(scrolling || (_Effect == null)) return;
    
    scrolling = true;

    _Effect.scroll(-(imageWidth / numberImage));
    
    scrollingTimer = setTimeout("endScroll()", duration);
    
    currentPos++;
}

function prev()
{
    if(scrolling || (_Effect == null)) return;

    scrolling = true;
    
    _Effect.scroll((imageWidth / numberImage));

    scrollingTimer = setTimeout("endScroll()", duration);

    currentPos--;
}

function endScroll()
{
    clearTimeout(scrollingTimer);
    scrolling = false;
}

function check(id)
{
    var check = document.getElementById('Check' + id);
    check.checked = !check.checked;
}
