﻿var columnsmax;
var play = 1;
var sid;
var name;
var userid;
var now;
var mediatype;
var digit = 0;
var last = 0;

function init() {
        start();
}

function pauseVoteSpy() {
        var playimg = document.getElementById("vsplay");
        var pauseimg = document.getElementById("vspause");

        playimg.src = "images/play_up.gif";
        playimg.alt = "Click to Play";
        pauseimg.src = "images/pause_down.gif";
        pauseimg.alt = "Paused...";

        pause();
}

function playVoteSpy() {
        var playimg = document.getElementById("vsplay");
        var pauseimg = document.getElementById("vspause");

        playimg.src = "images/play_down.gif";
        playimg.alt = "Playing...";
        pauseimg.src = "images/pause_up.gif";
        pauseimg.alt = "Click to Pause";

        resume();
}

function pause() {
	play = 0;		
}

function resume() {
	play = 1;
}
		
function start() {
	setTimeout("processDB()", 2000);
	
}


function GET_zips_CB(result) {
	var parts = result.split(" | ");
	name = parts[0];
	sid = parts[1];
	userid = parts[2];
	now = parts[3];
	mediatype = parts[4];
	push();
}

function processDB() {

	x_GET_zips(digit, GET_zips_CB);
	digit++;
	setTimeout("start()", 2000);

}

function push() {
	
	if (play == 0) {
                setTimeout("push()", 1000);
                return;
	}

	var cell;
	var cellnext;
	var text;
	var style = "";
	var idlink = "";
	
	if (mediatype == "podshows"){
	idlink = "sid";
	} else {
	idlink = "iid";
	}
	
if (now != last) {

	text = "<table width=\"600\">"
	text += "<tr valign=\"top\">";
	text += "<td width=\"200\"><a href='http://www.podcastdirectory.com/"+mediatype+"/index.php?"+idlink+"="+sid+"'>"+name+"</a></td>";
	text += "<td width=\"80\">" + userid + "</td>";	
	if (mediatype == 'podcasts') {
	text += "<td width=\"80\"><img src = 'http://www.podcastdirectory.com/spy/images/podcasts.png'></td>";	
	} else {
	text += "<td width=\"80\"><img src = 'http://www.podcastdirectory.com/spy/images/podshows.png'></td>";	
	}
	text += "<td width=\"150\">" + now + "</td>";
	text += "</tr>";
	text += "</table>";
	last = now;
} else {
text = "";
}



	Element.setOpacity('comment-1', 0.0);

	for (i = (columnsmax - 1); i >= 1; i--) {
              	cell = document.getElementById("comment-" + i);
               	cellnext = document.getElementById("comment-" + (i + 1));
		if (cell.innerHTML != "") {
                	cellnext.innerHTML = cell.innerHTML;
		}
        }

       document.getElementById("comment-1").innerHTML = text;

        Effect.Appear('comment-1', { duration: 1.5 });

	if (pollids.length > 0) {
		setTimeout("push()", 1550);
	}
	else {
		setTimeout("start()", 3000);
       	}
}
