// Archives
var listIDS = new Array(0, 0, 0, 0);
var videoLists = new Array(new Array(), new Array(), new Array(), new Array());
var End = false;
var Loading = false;

function writeList(id) {
    var out = '<table border="1" width="100%" cellspacing="0" cellpadding="0" bgcolor="#D2D2D2" height="134" bordercolor="#FFFFFF" bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">';
    var i = 0;
    var sid;
    
    while(i < 4) {
        if((listIDS[id] + i) >= (videoLists[id].length)) sid = (listIDS[id] + i) - videoLists[id].length;
        else sid = listIDS[id] + i;
        
        if(videoLists[id].length < 4 && (listIDS[id] + i) >= videoLists[id].length) break;
        
        out = out + '<tr><td bgcolor="#E4E4E4"><p style="margin-left: 2px; margin-right: 2px"><font face="Arial" size="1"><a href="videos.php?id='+videoLists[id][sid][0]+'">'+videoLists[id][sid][1]+' : '+videoLists[id][sid][2]+'</a></font></td></tr>';
        
        i++;
    }
    
    out = out + '</table>';
    document.getElementById('videoList'+id).innerHTML = out;
}
    
function up(id) {
    if(listIDS[id] > 0) listIDS[id]--;
    
    writeList(id);
}

function down(id) {
    if(Loading) return false;
    
    if(listIDS[id] == (videoLists[id].length - 1)) {
        listIDS[id] = 0;
    } else if(listIDS[id] == (videoLists[id].length - 4) && !End) {
        if(getContent('videos', (listIDS[id] + 3), id) != false) {
            Loading = true;
        } else {
            End = true;
            down(id);
        }
    } else {
    	listIDS[id]++;
	}
    
    writeList(id);
}
