google.load("swfobject", "2.1");

var surl = window.location.host.split('.');
surl = surl[surl.length-1];

if(surl=='')surl='net';

var picdir='http://klf-communications.'+surl+'/DATA/s/';
targeturl='http://www.klf-communications.'+surl+'/';

if(firstplay.substr(0,1)=='*')
{
	adminmode=true;
	firstplay=firstplay.substr(1,firstplay.length);
}
else
{
	adminmode=false;
}

var vwidth=0;
var vheight=0;
var heightdiff=36;
var displaylogo='';
var piclink='';

function resizevideo()
{
	vwidth=document.body.clientWidth;
	vheight=document.body.clientHeight;

	if(vwidth>10)
	{
		if (ytplayer) {
			ytplayer.style.width=vwidth;
			ytplayer.style.height=vheight-25;
		}
	
		tempobject=document.getElementById('logo');
	
		tempobject.style.display='';
		tempobject.style.left=vwidth*0.88;
		tempobject.style.top=vwidth*0.04;
		tempobject.style.width=vwidth*0.088;
	
		tempobject=document.getElementById('blinder');
		tempobject.style.width=vwidth;
		tempobject.style.height=vheight-25;
	
		tempobject=document.getElementById('infotable');
		tempobject.style.display='';
		tempobject.style.width=vwidth;
	}
}

if (top.location != self.location)
{	
	piclink='#';
}
else
{
	piclink=targeturl;
}

if (typeof document.addEventListener != 'function' && window.XMLHttpRequest)
{
	font='klf,Impact,Arial';
	fontwieght='';
}
else
{
	font='Arial';
	fontwieght='bold';
}

document.write('<style>'+
'@font-face {'+
    'font-family: klf;'+
    'font-style:  normal;'+
    'font-weight: normal;'+
    'src: url(\''+picdir+'klf.eot\');'+
'}'+
'IMG'+
'{'+
	'Border: 0px;'+
'}'+
'*'+
'{'+
	'TEXT-DECORATION: none;'+
	'FONT-FAMILY: '+font+';'+
	'COLOR: #ffffff;'+
	'FONT-SIZE: 14px;'+
	'FONT-WEIGHT: '+fontwieght+';'+
'}'+
'BODY'+
'{'+
	'margin-left:0px;'+
	'margin-right:0px;'+
	'margin-top:0px;'+
	'margin-bottom:0px;'+
	'SCROLLBAR-ARROW-COLOR: #000;'+
	'SCROLLBAR-TRACK-COLOR: #000;'+
	'SCROLLBAR-BASE-COLOR: #000;'+
	'BACKGROUND-COLOR: #000;'+
	'scrollbar-3d-light-color: #000;'+
	'scrollbar-dark-shadow-color: #000;'+
	'CURSOR: url(\''+picdir+'klf.cur\')'+
'}'+
'A'+
'{'+
	'white-space:nowrap;'+
	'PADDING-RIGHT: 2px;'+
	'PADDING-BOTTOM: 2px;'+
	'PADDING-LEFT: 2px;'+
	'PADDING-TOP: 2px;'+
	'DISPLAY: block;'+
	'WIDTH: 100%;'+
	'CURSOR: url(\''+picdir+'klf.ani\');'+
'}'+
'INPUT'+
'{'+
	'CURSOR: url(\''+picdir+'klf.ani\')'+
'}'+
'*.b2'+
'{'+
	'COLOR: #000;'+
	'BACKGROUND-COLOR: #fff'+
'}'+
'*.b1'+
'{'+
	'COLOR: #fff;'+
	'BACKGROUND-COLOR: #000'+
'}'+
'A:link'+
'{'+
	'COLOR: #fff;'+
	'BACKGROUND-COLOR: #000'+
'}'+
'A:visited'+
'{'+
	'COLOR: #fff;'+
	'BACKGROUND-COLOR: #000'+
'}'+
'A:hover'+
'{'+
	'COLOR: #000;'+
	'BACKGROUND-COLOR: #fff'+
'}'+
'A:active'+
'{'+
	'COLOR: #000;'+
	'BACKGROUND-COLOR: #fff'+
'}'+
'</style>'+
'<body>'+
'<div id="ytapiplayer">&nbsp;</div>'+
'<iframe ID=newinfoframe name=newinfoframe style="display:none;" scrolling=no></iframe>'+
'<table id="infotable" border=0 style="display:none;position:absolute;left=0;bottom:2;">'+
	'<tr>'+
		'<td colspan=11></td>'+
		'<td>'+
			'<table Style="z-index:100;position:relative;top:25;border-collapse:collapse;height:20;width:100%" CELLPADDING="0" CELLSPACEING="0">'+
				'<tr>');

	for(x=0;x<101;x++)
	{
		document.write('<td onclick="jumpto('+x+');"></td>');
	}
	
	document.write('</tr>'+
			'</table>'+
		'</td>'+
		'<td colspan=5></td>'+
	'</tr>'+
	'<tr>'+
		'<td width="15" >&nbsp;</td>'+
		'<td width="1"><img src='+picdir+'play.gif    title="play"     onclick="play();"></td>'+
		'<td width="1"><img src='+picdir+'pause.gif   title="pause"    onclick="pause();"></td>'+
		'<td width="1"><img src='+picdir+'reward.gif  title="RW"       onclick="spool(false);"></td>'+
		'<td width="1"><img src='+picdir+'forward.gif title="FF"       onclick="spool(true);"></td>'+
		'<td width="1"><img src='+picdir+'reload.gif  title="reload"   onclick="restart();"></td>'+
		'<td width="1"><img src='+picdir+'next.gif    title="next"     onclick="next();"></td>'+
		'<td width="1"><img src='+picdir+'minus.gif   title="volume -" onclick="changevolume(false);"></td>'+
		'<td width="15" id="vinfo"><center>00</td>'+
		'<td width="1"><img src='+picdir+'plus.gif    title="volume +" onclick="changevolume(true);"></td>'+
		'<td width="15" >&nbsp;</td>'+
		'<td>'+
			'<table border="1" Style="z-index:50;position:relative;top:1;border-collapse:collapse;height:12;width:100%" CELLPADDING="0">'+
				'<tr>'+
					'<td Style="background-color: #fff" id="videotimepd2"></td>'+
					'<td Style="width:100%"></td>'+
				'</tr>'+
			'</table>'+
		'</td>'+
		'<td width="15" >&nbsp;</td>'+
		'<td width="30" id="Time1">00:00</td>'+
		'<td width="1">/</td>'+
		'<td width="30" id="Time2">00:00</td>'+
		'<td width="15" >&nbsp;</td>'+
	'</tr>'+
'</table>'+
'<div><img id=blinder src='+picdir+'blinder.gif style="position:absolute;width:1;height:1;top:0;left:0"></div>'+
'<div style="display:'+displaylogo+';"><img id=logo onclick="window.open(\''+piclink+'\',\'_self\');" src='+picdir+'tvlogo.gif style="display:none;position:absolute;top:1;left:1"></div>');

if(adminmode)
{
	document.write('<br><br><br><br><center>'+
	'<table border="1" Style="border-collapse:collapse;" CELLPADDING="5">'+
	'<colgroup>'+
		'<col width="12.5%">'+
		'<col width="12.5%">'+
		'<col width="12.5%">'+
		'<col width="12.5%">'+
		'<col width="12.5%">'+
		'<col width="12.5%">'+
		'<col width="12.5%">'+
		'<col width="12.5%">'+
	'</colgroup>'+
	'<tr>'+
		'<td>intenal ID:		</td><td id="internalid"		align="right"></td>'+
		'<td>PlaybackQuality:	</td><td id="PlaybackQuality"	align="right"></td>'+
		'<td>QualityLevels:		</td><td id="QualityLevels"		align="right"></td>'+
		'<td>Bytes Total:  		</td><td id="bytestotal"		align="right"></td>'+
	'</tr>'+
	'<tr>'+
		'<td>youTube ID:		</td><td id="youtubeid"			align="right"></td>'+
		'<td>Tracks Total:		</td><td id="TotalTracks"		align="right"></td>'+
		'<td>Duration:     		</td><td id="videoduration" 	align="right"></td>'+
		'<td>Start Bytes:  		</td><td id="startbytes" 		align="right"></td>'+
	'</tr>'+
	'<tr>'+
		'<td>Player state: 		</td><td id="playerstate"		align="right"></td>'+
		'<td>Tracks Pool:		</td><td id="TracksPool"		align="right"></td>'+
		'<td>Current Time: 		</td><td id="videotime" 		align="right"></td>'+
		'<td>Bytes Loaded: 		</td><td id="bytesloaded"		align="right"></td>'+
	'</tr>'+
	'<tr>'+
		'<td>Volume:       		</td><td id="volume" 			align="right"></td>'+
		'<td>in Percent: 		</td><td id="TracksPoolp" 		align="right"></td>'+
		'<td>in Percent: 		</td><td id="videotimep" 		align="right"></td>'+
		'<td>in Percent:  		</td><td id="bytestotalp" 		align="right"></td>'+
	'</tr>'+
	'<tr>'+
		'<td>Last Player Error:	</td><td id="PlayerError" 		align="right"></td>'+
		'<td colspan="2">'+
			'<table border="1" Style="border-collapse:collapse;height:14;width:100%" CELLPADDING="0">'+
				'<tr>'+
					'<td Style="background-color: #fff" id="TracksPoolpd"></td>'+
					'<td Style="width:100%"></td>'+
				'</tr>'+
			'</table>'+
		'</td>'+
		'<td colspan="2">'+
			'<table border="1" Style="border-collapse:collapse;height:14;width:100%" CELLPADDING="0">'+
				'<tr>'+
					'<td Style="background-color: #fff" id="videotimepd"></td>'+
					'<td Style="width:100%"></td>'+
				'</tr>'+
			'</table>'+
		'</td>'+		
		'<td colspan="2">'+
			'<table border="1" Style="border-collapse:collapse;height:14;width:100%" CELLPADDING="0">'+
				'<tr>'+
					'<td Style="background-color: #fff" id="bytestotalpd"></td>'+
					'<td Style="width:100%"></td>'+
				'</tr>'+
			'</table>'+
		'</td>'+
	'</tr>'+
	'<tr>'+
		'<td>URL:				</td><td id="yURL"			colspan="5"></td>'+
		'<td><select id="Qualityselect" class=b1 onmouseout="this.className=\'b1\'" onmouseover="this.className=\'b2\'" Style="width:100%" >'+
			'<option class=b1>default</option>'+
			'<option class=b1>small</option>'+
			'<option class=b1>medium</option>'+
			'<option class=b1>large</option>'+
			'<option class=b1>hd720</option>'+
		'</select></td>'+
		'<td ><input class=b1 onmouseout="this.className=\'b1\'" onmouseover="this.className=\'b2\'" Style="width:100%" type="button" value="set" onclick="updatePlaybackQuality();"></td>'+
	'</tr>'+
	'<tr>'+
		'<td>Titel:				</td><td id="yTitel"		colspan="6"></td>'+
		'<td ><input class=b1 onmouseout="this.className=\'b1\'" onmouseover="this.className=\'b2\'" Style="width:100%" type="button" value="test all" onclick="test_tracks(true);"></td>'+
	'</tr>'+
	'<tr>'+
		'<td valign="top">Next:				</td><td id="next"			colspan="7"></td>'+
	'</tr>'+
	'<tr>'+
		'<td colspan=3	><input class=b1 onmouseout="this.className=\'b1\'" onmouseover="this.className=\'b2\'" id="afiltervalue" Style="width:100%"></td>'+
		'<td			><input class=b1 onmouseout="this.className=\'b1\'" onmouseover="this.className=\'b2\'" Style="width:100%" type="button" value="filter" onclick="filter();"></td>'+
		'<td colspan=3	><input class=b1 onmouseout="this.className=\'b1\'" onmouseover="this.className=\'b2\'" id="loadquery" Style="width:100%"></td>'+
		'<td><input class=b1 onmouseout="this.className=\'b1\'" onmouseover="this.className=\'b2\'" Style="width:100%" type="button" value="load" onclick="load_query();"></td>'+
	'</tr>'+
		'<tr>'+
			'<td id="tracklist" colspan="8"></td>'+
		'</tr>'+
	'</table>');
}

document.write('</body>');

ystatus=Array("","DB","YP","DB+YP");
ToRemoveByPlaylist2=Array();
TempTrack = Array();
Track = Array();
thisplay = null;
playerState = null;
testmode = false;
QualityMode = 'hd720';

function initPlayer()
{
	for(y=0;y<Track.length;y++)
	{
		code	=Track[y].substring( 0,10).split("");
		Track[y]=Track[y].substring(10,Track[y].length);
	
		tempsting='';
	
		for(x=0;x<Track[y].length;x=x+10)
		{
			for(z=0;z<10;z++)
			{			
				tempsting=tempsting+Track[y].charAt(x+parseInt(code[z]));
			}
		}
	
		Track[y]=Array();
	
		if(tempsting.search(/\|/g) == -1)
		{
			Track[y][0]=unescape(tempsting.substring(22,tempsting.length)).replace(/%/g,"");
			Track[y][1]=tempsting.substring(11,22);
			Track[y][2]=tempsting.substring( 0,10);
			Track[y][3]=ystatus[tempsting.charAt(10)];
			Track[y][4]=Track[y][0];
			Track[y][0]=Track[y][0].toLowerCase().replace(/\W/g, '');
		}
		else
		{
			Track[y][0]=unescape(tempsting.substring(11,tempsting.length)).replace(/%/g,"");
			Track[y][1]='playlist';
			Track[y][2]=tempsting.substring( 0,10);
			Track[y][3]=ystatus[tempsting.charAt(10)];
			Track[y][4]=Track[y][0];
		}
	}
	
	for(y=0;y<Track.length;y++)
	{
		if(Track[y][1]=='playlist')
		{
			tempArray=Track[y][4].split("|");
	
			for(x=0;x<tempArray.length;x++)
			{
				ToRemoveByPlaylist2[tempArray[x]]='true';
	
				for(z=0;z<Track.length;z++)
				{
					if(tempArray[x]==Track[z][2])
					{
						if(Track[z][3])Track[z][3]=Track[z][3]+'+';
						Track[z][3]=Track[z][3]+''+Track[y][3]+'PL';
						
						Playlisttitle=Track[z][0];
						break;
					}
				}
			}
	
			Track[y][0]=Playlisttitle+'X';
		}
	}
	
	Track=Track.sort();
	
	if(adminmode)
	{		
		TracklistString=
				'<table border="1" Style="border-collapse:collapse;table-layout:fixed;" CELLPADDING="5" width="940">'+
					'<colgroup>'+
						'<col width="12.5%">'+
						'<col >'+
						'<col width="6.25%">'+
						'<col width="6.25%">'+
					'</colgroup>'+
					'<tr>'+
						'<td align="center">ID:</td>'+
						'<td align="center">Titel:</td>'+
						'<td align="center">Used:</td>'+
						'<td align="center">in Pool:</td>'+
					'</tr>';
		
		for(y=0;y<Track.length;y++)
		{
			TracklistString=TracklistString+
			'<tr id="row_'+Track[y][1]+'_'+Track[y][2]+'">'+
				'<td>'+Track[y][2]+'</td>'+
				'<td style="overflow:hidden;"><a href="#" onclick="load(\''+Track[y][2]+'\');">'+Track[y][4]+'</a></td>'+
				'<td align="center" id="state_'+Track[y][1]+'_'+Track[y][2]+'">'+Track[y][3]+'</td>'+
				'<td align="center" id="pic_'+Track[y][1]+'_'+Track[y][2]+'"></td>'+
			'</tr>';
		}
	
		document.getElementById("tracklist").innerHTML=TracklistString+'</table>';
	}
}

function jumpto(position)
{
	seekTo(getDuration()/100*position);
}

function test_tracks(mode)
{
	testmode = mode;
}

function filter()
{
	filtervalue=document.getElementById("afiltervalue").value.toLowerCase().split(" ");
	
	tempfiltervalue=Array();

	for(y=0;y<filtervalue.length;y++)
	{
		temp=filtervalue[y].replace(/\W/g, '');

		if(temp)
		{
			tempfiltervalue.push(temp);
		}
	}
	
	filtervalue=tempfiltervalue;

	for(x=0;x<Track.length;x++)
	{
		add=true;
		
		for(y=0;y<filtervalue.length;y++)
		{
			if(Track[x][0].search(filtervalue[y]) == -1)
			{
				add=false;
			}
		}			

		if(add)
		{
			document.getElementById('row_'+Track[x][1]+'_'+Track[x][2]).style.display = '';
		}
		else
		{
			document.getElementById('row_'+Track[x][1]+'_'+Track[x][2]).style.display = 'none';
		}
	}
}

function add_zeros(inval, zeros)
{
	for(startval=inval.toString().length;startval<zeros;startval++)
	{
		inval='0'+inval;
	}

	return inval;
}

function updateHTML(elmId, value) {
	document.getElementById(elmId).innerHTML = value;
}

function updateHTMLstyle(elmId, value) {
	document.getElementById(elmId).style.width = value+'%';
}

function setytplayerState(newState) {
	if(adminmode)updateHTML("playerstate", newState);
	playerState=newState;		
}

function onYouTubePlayerReady(playerId) {
	ytplayer = document.getElementById("myytplayer");
	setInterval(updateytplayerInfo, 250);
	updateytplayerInfo();
	ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
	ytplayer.addEventListener("onError", "onPlayerError");
}

function onytplayerStateChange(newState) {
	setytplayerState(newState);
}

function onPlayerError(errorCode) {
	if(adminmode)updateHTML("PlayerError", errorCode);
	setTimeout("checkStatus(5,"+errorCode+");",1000);
}

function checkStatus(run,errorCode)
{
	if(run)
	{
		text = "Error "+errorCode+" ("+run+")";

		if(top.location != self.location)
		{
			window.open(targeturl+'info2.php'+'?'+'target='+this.name+'&url='+escape(self.location)+'&text='+escape(text),'newinfoframe');
		}
		else
		{
			document.title = text;
		}

		if(playerState==1)
		{
			setinfo();
		}
		else
		{
			setTimeout("checkStatus("+(run-1)+","+errorCode+");",1000);
		}
	}
	else
	{
		if(adminmode)updateHTML("PlayerError", "");
		next();
	}

}

function loadNewVideo(id, startSeconds) {
	if (ytplayer) {
		ytplayer.loadVideoById(id, parseInt(startSeconds));
	}
}

function cueNewVideo(id, startSeconds) {
	if (ytplayer) {
		ytplayer.cueVideoById(id, startSeconds);
	}
}

function play() {
	if (ytplayer) {
		ytplayer.playVideo();
	}
}

function pause() {
	if (ytplayer) {
		ytplayer.pauseVideo();
	}
}

function stop() {
	if (ytplayer) {
		ytplayer.stopVideo();
	}
}

function getPlayerState() {
	if (ytplayer) {
		return ytplayer.getPlayerState();
	}
}

function seekTo(seconds) {
	if (ytplayer) {
		ytplayer.seekTo(seconds, true);
	}
}

function getBytesLoaded() {
	if (ytplayer) {
		return ytplayer.getVideoBytesLoaded();
	}
}

function getBytesTotal() {
	if (ytplayer) {
		return ytplayer.getVideoBytesTotal();
	}
}

function getCurrentTime() {
	if (ytplayer) {
		return ytplayer.getCurrentTime();
	}
}

function getDuration() {
	if (ytplayer) {
		return ytplayer.getDuration();
	}
}

function getStartBytes() {
	if (ytplayer) {
		return ytplayer.getVideoStartBytes();
	}
}

function mute() {
	if (ytplayer) {
		ytplayer.mute();
	}
}

function unMute() {
	if (ytplayer) {
		ytplayer.unMute();
	}
}

function getEmbedCode() {
	if (ytplayer) {
		return ytplayer.getVideoEmbedCode();
	}
}

function getVideoUrl() {	
	if (ytplayer) {
		return ytplayer.getVideoUrl();
	}
}

function setVolume(newVolume) {
	if (ytplayer) {
		ytplayer.setVolume(newVolume);
	}
}

function getVolume() {
	if (ytplayer) {
		return ytplayer.getVolume();
	}
}

function clearVideo() {
	if (ytplayer) {
		ytplayer.clearVideo();
	}
}

function getAvailableQualityLevels(){
	if (ytplayer) {
		return ytplayer.getAvailableQualityLevels();
	}
}

function getPlaybackQuality(){
	if (ytplayer) {
		return ytplayer.getPlaybackQuality();
	}
}

function setPlaybackQuality(suggestedQuality){
	if (ytplayer) {
		ytplayer.setPlaybackQuality(suggestedQuality);
	}
}

function updatePlaybackQuality(){
	QualityMode=document.getElementById("Qualityselect").value;
	setPlaybackQuality(QualityMode);
}

function updateytplayerInfo() {
	if((playerState=='-1')||(playerState=='0')||((testmode)&&(playerState=='1')))
	{
		next();
	}

	CurrentTime=getCurrentTime().toFixed(0);
	Duration=getDuration().toFixed(0);

	ctime = new Date(2000, 1, 1, 0, 0, CurrentTime);
	dtime = new Date(2000, 1, 1, 0, 0, Duration);

	intvolume=getVolume();
	if(intvolume>99)intvolume=99;

	tvideotimep=(getCurrentTime()/getDuration()*100);

	updateHTML("Time1", 			add_zeros(ctime.getMinutes(), 2)+':'+add_zeros(ctime.getSeconds(), 2));
	updateHTML("Time2", 			add_zeros(dtime.getMinutes(), 2)+':'+add_zeros(dtime.getSeconds(), 2));
	updateHTML("vinfo", 			add_zeros(intvolume,2));
	updateHTMLstyle("videotimepd2",	tvideotimep);

	if(adminmode)
	{
		tbytestotalp=((getStartBytes()+getBytesLoaded())/getBytesTotal()*100);

		updateHTML("videotimep", 		tvideotimep.toFixed(2)+'%');
		updateHTMLstyle("videotimepd",	tvideotimep);
		updateHTML("bytestotalp", 		tbytestotalp.toFixed(2)+'%');
		updateHTMLstyle("bytestotalpd",	tbytestotalp);
		updateHTML("bytesloaded", 		getBytesLoaded().toFixed(0));
		updateHTML("bytestotal", 		getBytesTotal());
		updateHTML("videoduration", 	getDuration().toFixed(3));
		updateHTML("videotime", 		getCurrentTime().toFixed(3));
		updateHTML("startbytes",  		getStartBytes().toFixed(0));
		updateHTML("volume", 			getVolume());
		updateHTML("QualityLevels", 	getAvailableQualityLevels());
		updateHTML("PlaybackQuality", 	getPlaybackQuality());
	}

	resizevideo();
}

function reload_TempTrack()
{
	for(y=0;y<Track.length;y++)
	{
		if(!ToRemoveByPlaylist2[Track[y][2]])
		{
			TempTrack.push(Track[y]);
			if(adminmode)updateHTML('pic_'+Track[y][1]+'_'+Track[y][2],'YES');
		}
	}

	if(adminmode)updateHTML("TotalTracks",Track.length);
	test_tracks(false);
};

function getID()
{
	if(TempTrack.length==0)
	{
		reload_TempTrack();
	}

	if(firstplay.length>0)
	{
		for(y=0;y<Track.length;y++)
		{
   			if(Track[y][2]==firstplay[0])
			{
				TempVal=Track[y];
				break;
			}
		}

		if(adminmode)
		{
			nextText='';
			nextquery='';
	
			for(z=1;z<firstplay.length;z++)
			{
				for(y=0;y<Track.length;y++)
				{
		   			if(Track[y][2]==firstplay[z])
					{
						if(nextText)nextText=nextText+'<br>';
						nextText=nextText+Track[y][4];
						if(nextquery)nextquery=nextquery+' ';
						nextquery=nextquery+Track[y][2];
						break;
					}
				}
			}
			
			updateHTML("next",nextText);	
			document.getElementById("loadquery").value=nextquery;
		}

		firstplay.splice(0,1);

		for(y=0;y<TempTrack.length;y++)
		{
			if(TempTrack[y][2]==TempVal[0])
			{
				TempTrack.splice(y,1);
				break;
			}
		}

	}
	else
	{
		Jetzt = new Date();
		pointer=(Jetzt.getSeconds()+(Jetzt.getMinutes()*60)+(Jetzt.getHours()*60*60))%TempTrack.length;
	
		TempVal=TempTrack[pointer];
		TempTrack.splice(pointer,1);
	}

	if(adminmode)
	{
		tTracksPoolp=(TempTrack.length/Track.length*100);

		updateHTML("TracksPool",  		TempTrack.length);
		updateHTML("TracksPoolp",		tTracksPoolp.toFixed(2)+'%');
		updateHTMLstyle("TracksPoolpd", tTracksPoolp);
		updateHTML('pic_'+TempVal[1]+'_'+TempVal[2],'');
	}
	
	if(TempVal[1]=='playlist')
	{
		playlist_ids=TempVal[4].split("|");

		if(firstplay)
		{
			firstplay=playlist_ids.concat(firstplay);
		}
		else
		{
			firstplay=playlist_ids;
		}

		TempVal=getID();
	}

	return TempVal;
};

function load(ids)
{
	firstplay=ids.split(" ");
	next();
}

function next()
{
	thisplay=getID();
	restart();
};

function restart()
{
	stop();
	clearVideo();
    loadNewVideo(thisplay[1], 0);
    setPlaybackQuality(QualityMode);

	if(adminmode)
	{
	    URL=getVideoUrl().split("&");
	    updateHTML("yURL", 		'<a href="'+URL[0]+'" target="_blank">'+URL[0]+'</a>');
		updateHTML("yTitel", 	thisplay[4]);
		updateHTML("youtubeid",	thisplay[1]);
		updateHTML("internalid",thisplay[2]);
	}

	setinfo();
}

function changevolume(command)
{
	intvolume=getVolume();

	if(command)
	{
		intvolume=intvolume+10;
	}
	else
	{
		intvolume=intvolume-10;
	}

	setVolume(intvolume);
}

function spool(command)
{
	seconds=getCurrentTime();

	if(command)
	{
		seconds=seconds+30;
	}
	else
	{
		seconds=seconds-30;
	}

	if(seconds<0)seconds=0;
	if(seconds>=getDuration())seconds=getDuration()-2;

	seekTo(seconds, true);
};

function load_query()
{
	load(document.getElementById("loadquery").value);
}

function loadplayer()
{
	if(firstplay)firstplay=firstplay.split(" ");

	var params = { allowScriptAccess: "always", wmode: "opaque"};
	var atts = { id: "myytplayer" };

	swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer","ytapiplayer", document.body.clientWidth, document.body.clientHeight, "8", null, null, params, atts);
};

var xmlHttpObject = false;

if (typeof XMLHttpRequest != 'undefined')
{
    xmlHttpObject = new XMLHttpRequest();
}

if (!xmlHttpObject)
{
    try
    {
        xmlHttpObject = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e) 
    {
        try 
        {
            xmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e) 
        {
            xmlHttpObject = null;
        }
    }
}

function updaterequest()
{
	xmlHttpObject.open('GET','tracks2.php?type=video');
	xmlHttpObject.onreadystatechange = handleStateChange;
	xmlHttpObject.send(null);
}

function handleStateChange()
{
	if(xmlHttpObject.readyState==4)
	{
		if(xmlHttpObject.statusText=='OK')
		{
			Track=xmlHttpObject.responseText.substring(0,xmlHttpObject.responseText.length-1).split(" ");
			initPlayer();
			loadplayer();
		}
	}
}

function setinfo()
{
	if(thisplay)
	{
		text=thisplay[4];
	}
	else
	{
		text="loading player...";
	}

	if(top.location != self.location)
	{
		window.open(targeturl+'info2.php'+'?'+'target='+this.name+'&url='+escape(self.location)+'&text='+escape(text),'newinfoframe');
	}
	else
	{
		document.title = text;
	}
}

setTimeout("updaterequest();",2000);
setTimeout("setinfo();",2000);