var playlist= new Array();
var count=1000, parado=-1, broielem, index, klips= new Array;

document.write('<script language="javascript" src="script/playlisti/tripode.js"></script>');

function buscar(){
var x=0;
u=document.getElementById("list");
playlist.length=0;

if(document.searchform.searchtext.value==""){
 for (i=0; i < klips.length; i++) {
      	playlist[x] = klips[i];
		x++;
 }}

else{
var searchtext = new RegExp(document.searchform.searchtext.value, "gi");
for(i=0;i<klips.length;i++){
t=klips[i].split('|');
if((t[0].search(searchtext)!=-1) || (t[5].search(searchtext)!=-1))
	playlist[playlist.length]=klips[i];
}}
u.length=0;
for(i=0;i<playlist.length;i++){
t=playlist[i].split('|');
u.options[i]=new Option(t[0],i);
}

if(broielem==u.length)
	u.selectedIndex=index;
}



function setplayer(){
var x=0, total=new Array;
klips=klipstripode;
for (i=0; i < klips.length; i++) {
		t=klips[i].split('|');
      	playlist[x] = klips[i];
		x++;
 }
t=playlist[0].split('|');
document.write('<table border="0" cellspacing="0" cellpadding="2"><tr><td rowspan="3"><iframe frameborder="0" src="http://www.youtube.com/v/'+t[1]+'&autoplay=1" id="player" width="618" height="500"></iframe></td>');

			   
document.write('<tr><td colspan="2" nowrap><form style="padding:0; margin:0" name="searchform"><input type="text" name="searchtext" onKeyUp="buscar()"> Buscar</td></tr>');
document.write('<tr><td style="color:#FFFF00" colspan="2"><select size="27" id="list" OnChange="play()">');

for(i=0;i<playlist.length;i++){
	t=playlist[i].split('|');
	document.write('<option value="'+i+'">'+t[0]+'</option>');
}
document.write('</select><br><form style="padding:0; margin:0" name="autonext"><input type="checkbox" name="autocheck" checked');
document.write(' checked');
document.write('>Siguiente leccion en: <input name=timer style="color:#FFFFFF; background-color:#000000" size=7></form></td></tr></table>');

u=document.getElementById("list");
u.selectedIndex=0; 
setTimeout("countdown()",1000);
play();
}


function countdown(){
if(count>0)count-=1000;
u=document.getElementById("autocheck");
if((count==0) && (u.checked))autoadvance();


minuti=Math.floor(count / 60000);
sekundi=Math.floor(count/1000-minuti*60);
p=document.getElementById("timer");
if(minuti<10)p.value='0';
p.value+=minuti + ':';
if(sekundi<10)p.value+='0';
p.value+=sekundi;

setTimeout("countdown()",1000);
}
	

function autoadvance(){
u=document.getElementById("list");
if(u.selectedIndex<u.length-1)
u.selectedIndex++;
play();
}


function play(){
u=document.getElementById("list");
t=playlist[u[u.selectedIndex].value].split('|');
	if (t[1].substr(0,7)!='http://')
	url='http://www.youtube.com/v/'+t[1]+'&autoplay=1';
	else {
		if(t[1].substr(0,24)=="http://viktorstudios.com") 
			url="http://viktorstudios.com/novprozorec.html?adres=interviuslavi";

		else url=t[1];		
}
p=document.getElementById("player");
p.src=url;
if(t[4]==0)
count=-2000;
else
count=t[4]*1000;
count+=1000;
broielem=u.length;
index=u.selectedIndex;
}
