
function MoveSpettacoli() {
        this.selected_div_id = 'selected_div_id';
        this.div_count = 'div_count';
        this.indicator_prefix = "ind_";
        this.container_name = "#mycarousel"; 
        this.margins = 10;
        this.div_width = 443;
}

function MoveEvents() {
        this.selected_div_id = 'events_selected_div_id';
        this.div_count = 'events_div_count';
        this.indicator_prefix = "events_ind_";
        this.container_name = "#events_window"; 
        this.margins = 10;
        this.div_width = 228;
}

function MoveHistory() {
        this.selected_div_id = 'history_selected_div_id';
        this.div_count = 'history_div_count';
        this.indicator_prefix = "history_ind_";
        this.container_name = "#history_window"; 
        this.margins = 10;
        this.div_width = 731;
}

MoveSpettacoli.prototype.shiftTo = shiftTo;
MoveSpettacoli.prototype.go_right = goRight;
MoveSpettacoli.prototype.go_left = goLeft;

MoveEvents.prototype.go_right = goRight;
MoveEvents.prototype.shiftTo = shiftTo;
MoveEvents.prototype.go_left = goLeft;

MoveHistory.prototype.go_right = goRight;
MoveHistory.prototype.shiftTo = shiftTo;
MoveHistory.prototype.go_left = goLeft;

function shiftTo(ind) 
{
    var current_div = document.getElementById(this.selected_div_id);
    var v = current_div.value;

    if (v == ind) return; 
    var total_div_number = document.getElementById(this.div_count).value;
    var indicator_id = this.indicator_prefix + v;
    var el = document.getElementById(indicator_id);
    el.className = 'select_indicator';
   
    if (v > ind) {
        var shift_by = (v-ind)*this.div_width;
        $(this.container_name).animate({"left": "+="+shift_by+"px"}, "slow");
        current_div.value = ind;
    } else {
        var shift_by = (ind-v)*this.div_width;
        $(this.container_name).animate({"left": "-="+shift_by+"px"}, "slow");
        current_div.value =  ind;
    }
    indicator_id = this.indicator_prefix + current_div.value;
    el = document.getElementById(indicator_id);
    el.className = 'select_indicator_active';
}

function goRight()
{
    var current_div = document.getElementById(this.selected_div_id);
    var v = current_div.value;
    var total_div_number = document.getElementById(this.div_count).value;
    var indicator_id = this.indicator_prefix + v;
    var el = document.getElementById(indicator_id);
        
    el.className = 'select_indicator';
    if (v== total_div_number) {
        var shift_by = (total_div_number -1)*this.div_width;
        $(this.container_name).animate({"left": "+="+shift_by+"px"}, "slow");
         current_div.value = 1;
    } else { 
        $(this.container_name).animate({"left": "-="+this.div_width+"px"}, "slow");
        current_div.value =  parseFloat(v) + 1;
    }
    indicator_id = this.indicator_prefix + current_div.value;
    el = document.getElementById(indicator_id);
    el.className = 'select_indicator_active';
}

function goLeft()
{ 
    var current_div = document.getElementById(this.selected_div_id);
    var v = current_div.value;
    var indicator_id = this.indicator_prefix + v;
    var total_div_number = document.getElementById(this.div_count).value;
    var el = document.getElementById(indicator_id);
    el.className = 'select_indicator';
    if (v== 1) {
      var shift_by = (total_div_number -1)*this.div_width;      
      $(this.container_name).animate({"left": "-="+shift_by+"px"}, "slow");
      current_div.value = total_div_number;
    } else {
      $(this.container_name).animate({"left": "+="+this.div_width+"px"}, "slow");  
      current_div.value =  parseFloat(v) - 1;
    }
    indicator_id = this.indicator_prefix + current_div.value;
    el = document.getElementById(indicator_id);
    el.className = 'select_indicator_active';
}

MoveSpettacoliObj = new MoveSpettacoli();
MoveEventsObj = new MoveEvents();
//MoveHistoryObj = new MoveHistory();

