var big_timeout = new Array();
big_timeout[0] = null;
big_timeout[1] = null;
big_timeout[2] = null;

var fade = new Array();
fade[0] = true;
fade[1] = true;
fade[2] = true;

var current_items_big = new Array();
current_items_big[0] = 0;
current_items_big[1] = 0;
current_items_big[2] = 0;


function startFading() {
    var temp = new Image();
    
    for(i=0;i<3;i++) {
        if(items_big.length != 1) {
            temp.src = items_big[i][1]['image'];
            big_timeout[i] = setTimeout('fadeTimeout(' + i + ')', 7000);
        }
    }
}
 
function fadeTimeout(id) {
    clearTimeout(big_timeout[id]);
    
    if(fade[id] && ($('#bubble_' + items_big[id][current_items_big[id]]['id'] + items_big[id][current_items_big[id]]['content_type']).css('display') != 'block') && ($('#fastorder_form').css('display') != 'block' || $('#fastorder_id').val() != items_big[id][current_items_big[id]]['id'] || $('#fastorder_type').val() != items_big[id][current_items_big[id]]['content_type'])) {
        var past_current = current_items_big[id];
    
        if((current_items_big[id] + 1) == (items_big[id].length)) {
            current_items_big[id] = 0;    
        }
        else {
            current_items_big[id]++;
        }
    
        $('#items_big_' + id + '_' + past_current).fadeOut(1000, showBig(id));
    }
    else {
        big_timeout[id] = setTimeout('fadeTimeout(' + id + ')', 7000);    
    }
}

function showBig(id) {
    $('#items_big_' + id + '_' + current_items_big[id]).fadeIn(1000, startFadeTimeout(id));    
}

function startFadeTimeout(id) {
    var temp = new Image();
    
    if((current_items_big[id] + 1) >= (items_big[id].length)) {
        temp.src = items_big[id][0]['image'];  
    }
    else {
        temp.src = items_big[id][(current_items_big[id] + 1)]['image'];
    }
    
    big_timeout[id] = setTimeout('fadeTimeout(' + id + ')', 7000);
}

function bigOver(id) {
    fade[id] = false;    
}

function bigOut() {
    fade[id] = true;    
}
