<?php 
$da = fsockopen("udp://239.0.2.10", 22222, $errno, $errstr);
$hora = time()."";

    fwrite($da,chr(00).chr(07).chr(00).chr(01).chr(00).chr(00).chr(00).chr(01).chr(00).chr(00).chr(00).chr(01)."var.utctime".chr(00).chr(00).chr(00).chr(00).chr(00).chr(00).chr(00).chr(00).chr(00).chr(00).chr(00).chr(00).chr(00).chr(00).chr(00).chr(00).chr(00).chr(00).chr(00).chr(00).chr(00).$hora);
    fclose($da);

include("config.php"); ?>
<html>
	<head>
		<meta http-equiv="Pragma" content="no-cache"> 
		<meta http-equiv="Expires" content="0">
        <script language="JavaScript" src="./keycodes_native.js" type="text/javascript">/*Cargar Teclas*/</script>
        <script language="JavaScript" src="VideoObject_ial.js" type="text/javascript"></script>
<style type="text/css">
<!--

body {
 color:#fff;
 margin: 0;
 padding: 0;
 font-size: 18px;
 font-weight: bold;
 border-color: #fff;
}

h1 {
 color:#fff;
}

#mainFrame {
 position: absolute;
 left: 190px;
 top: 100px;
 width: 520px;
 height: 420px;
 overflow:auto;
 border:0;
}

#infoText {
 position: absolute;
 left: 200px;
 top: 20px;
 width: 500px;
 height: 60px;
 /*background-color: #000;*/
 z-index:50;
 font-size: 35px;
 font-weight: bold
}

#fullScreenMode {
 visibility: hidden;
 position: absolute;
 left: 0px;
 top: 0px;

 /* 1080p :P */
 width: 1920px;
 height: 1024px;
 background-color: #000;
 z-index: 100;
}

#infoBox {
 position: absolute;
 left: 110px;
 top: 410px;
 width: 500px;
 height: 112px;
 visibility: hidden;
 background-image: url('./design/infoBox.png');
 text-align: center;
}

#menuBox {
 position: absolute;
 left: 272px;
 top: 200px;
 width: 166px;
 height: 162px;
 visibility: hidden;
 background-image: url('./design/menuBox.png');
 text-align: center;
 padding: 5px;

}
#menuBox div { 
  border: 1px solid #fff;
  margin-bottom: 3px;
}
-->
</style>
<script type="text/javascript">
/* Global vars */
var isFull = 0;
var txt = "";
try{var Video = new VideoObject;}catch(e){}

/* Added by Daniel */

var mCurrentPlaying;
var mPlayToggle = 0;
var mInfoBoxToggle = 0;

var mMenuBoxToggle = 0;
var mMenuBoxSelected = 0;

/* Change these to your own settings */
var mVLCAddress = "<?php echo $vlcAddress; ?>";
var mWebAddress = "<?php echo $globalServerAddress; ?>";
/* Change these to your own settings - END */

var mVideoResToggle = 0;
var mRoot = '<?php echo $globalRoot; ?>';

/* Left,Top,width,height */
var mVideoRes = [
					[0,0,720,576],	/* 4:3  */
					[0,86,720,405], /* 16:9 */		
					[44,28,648,518], /* 4:3 tiny  */
					[44,90,650,385] /* 16:9 tiny */					
				];

/* Added by Daniel - END */

/* End Global vars */


function handleErr(msg,url,l)
{
txt="There was an error on this page.\n\n";
txt+="Error: " + msg + "\n";
txt+="URL: " + url + "\n";
txt+="Line: " + l + "\n\n";
txt+="Click OK to continue.\n\n";
alert(txt);
return true;
}

function load()
{
		
		// Menu
		var list = menuItems();
		list[mMenuBoxSelected].style.border = "2px solid #fff";
		Video.videoPlayer.window.setPosition(7,121,166,120);
}

KeyHandler.process = function(c,ev)
{
	try {
		//alert(c);
		switch (c)
        {
	        case KEY_TV:
				document.location.href= "file:///home/telefonica/localpages/start.html";
				ev.consume();
				break;
			case KEY_UP:
				goUp();
				ev.consume();
				break;
			case KEY_DOWN:
				goDown();
				ev.consume();
				break;
			case KEY_SELECT:
				selectOk();
				ev.consume();
				break;
			case 0x170:
	        	toggleVideo();
				ev.consume();
	        break;
	        case 0x474:
	        	play();
				ev.consume();
	        	break;
			case 0x477:
	        	pause();
				ev.consume();
	        	break;
	        case 0x177:
				stopmedia();
				ev.consume();
				break;
	        case KEY_HELP:
				infoBox();
				ev.consume();
				break;			
			case KEY_BACK:

				goBack();
				ev.consume();
				break;
	        
			/*case BTN_BLUE:
	        playmedia(mVLCAddress);
	        break;

	        case BTN_QUESITONMARK:
	        reload(key);
	        msg("Reloaded");
	        break;
	        
	        // Left Middle Button (Go back)
	        

	        // Red button bottom
	        case BTN_RED:
	        parent.mainFrame.location = mRoot + "/listDir.php?favourites=";
	        break;

	        case BTN_E:
	        toggleVideoResolution();
	        break;
			
			case BTN_MENU:
			menuBox();
			break;*/
        }
	} catch (ex) {alert (ex + " - " + GetExceptionName(ex));}
}

function msg(msg)
{
        infoText.innerHTML = msg;
}

function reload(key)
{
        var newLocation = "/iptvgui/ExtenderGUI/start.php?url=" + key;
        top.location = newLocation;
}

function toggleVideoResolution()
{
	if(isFull == 1)
	{
		if(mVideoResToggle < mVideoRes.length-1)
        {
                mVideoResToggle++;
        }
        else
        {
                mVideoResToggle = 0;
        }
		
        /*video.window.setPosition(mVideoRes[mVideoResToggle][0],
                                 mVideoRes[mVideoResToggle][1],
                                 mVideoRes[mVideoResToggle][2],
                                 mVideoRes[mVideoResToggle][3]);*/
	}
}

function toggleVideo()
{
          
        if (isFull == 0)
        {
                document.getElementById('fullScreenMode').style.visibility = "visible";
		        /*video.window.setPosition(mVideoRes[mVideoResToggle][0],
		                                 mVideoRes[mVideoResToggle][1],
		                                 mVideoRes[mVideoResToggle][2],
		                                 mVideoRes[mVideoResToggle][3]);*/	
				Video.videoPlayer.window.setFullScreen();			
                isFull = 1;
        }
        else
        {
                document.getElementById('fullScreenMode').style.visibility = "hidden";
                Video.videoPlayer.window.setPosition(7,121,166,120);
                isFull = 0;
        }
}

function play()
{
        vlc("?play=true");

        if(mPlayToggle == 1)
        {
                playmedia(mVLCAddress);
                mPlayToggle = 1;
        }
        else
        {
                mPlayToggle = 0;
        }
}

function pause()
{
        vlc("?pause=true");
}

function playmedia(url)
{
	mCurrentPlaying = url;
    isFull = 0;
	try{
	top.Video.setChannel(top.mVLCAddress,"1","none");
	top.Video.configFull();
	}
	catch(ex) { alert(ex); }
}

function stopmedia()
{
	vlc("?stop=true");
}

function menuItems()
{
	nodes = document.getElementById( "menuBox" ).childNodes;
	menu = new Array((nodes.length-1)/2);	
	
	x = 0;
	for(i=1;x<menu.length;i+=2)
	{
		menu[x] = nodes[i]
		x++;
	}
	
	return menu;
}

function goUp()
{
	if(mMenuBoxToggle == 1)
	{
		var list = menuItems();
		
		if(mMenuBoxSelected > 0)
		{
			list[mMenuBoxSelected-1].style.border = "2px solid #fff";
			list[mMenuBoxSelected].style.border = "1px solid #fff";
			mMenuBoxSelected--;
		}			
	}
	else
	{
		parent.mainFrame.goUp();
	}
}

function goDown()
{
	if(mMenuBoxToggle == 1)
	{
		var list = menuItems();

		if(mMenuBoxSelected < list.length-1)
		{
			list[mMenuBoxSelected+1].style.border = "2px solid #fff";
			list[mMenuBoxSelected].style.border = "1px solid #fff";
			mMenuBoxSelected++;
		}			
		
	}
	else
	{
		parent.mainFrame.goDown();
	}
}

function goBack()
{
	parent.mainFrame.location = "listDir.php?favourites=";
}

function selectOk()
{
	if(mMenuBoxToggle == 1)
	{
		var list = menuItems();
		
		mainFrame.location = list[mMenuBoxSelected].title;
		menuBox();
	}
	else
	{
		parent.mainFrame.selectOk();
	}        
}

function vlc(mode)
{
	document.getElementById('url').src = mRoot + "/vlc.php" + mode;
}

function preRenderVideo(file, name)
{
	document.getElementById('infoBox').innerHTML = "- Reproduciendo - <br />" + name;
	document.getElementById('infoBox').style.visibility = "visible";
	setTimeout("hideInfoBox()", 5000);
        
	vlc("?file=" + file);
	setTimeout("playmedia('"+mVLCAddress+"')", 1000);
}

function preRenderVlc(name)
{
	document.getElementById('infoBox').innerHTML = "- Reproduciendo - <br />" + name;
	document.getElementById('infoBox').style.visibility = "visible";
	setTimeout("hideInfoBox()", 5000);
		
	// We need to play it twice to make it free of jitter... Sad, yes? :(
	setTimeout("playmedia('"+mVLCAddress+"')", 3000);
	setTimeout("playmedia('"+mVLCAddress+"')", 6000);
}

function infoBox()
{
	if(mInfoBoxToggle == 0)
	{
		document.getElementById('infoBox').style.visibility = "visible";
		mInfoBoxToggle = 1;
	}
	else
    {
		document.getElementById('infoBox').style.visibility = "hidden";
		mInfoBoxToggle = 0;
    }
}

function hideInfoBox()
{
	document.getElementById('infoBox').innerHTML = "";
	document.getElementById('infoBox').style.visibility = "hidden";
}

function menuBox()
{
        if(mMenuBoxToggle == 0)
        {
            document.getElementById('menuBox').style.visibility = "visible";
            mMenuBoxToggle = 1;
			goUp();
        }
        else
        {
			document.getElementById('menuBox').style.visibility = "hidden";
			mMenuBoxToggle = 0;
        }
}

function test()
{
	alert(parent.mainFrame.svtPlayUrl.document.getElementById('url').innerHTML);
}
</script>
</head>
<body onLoad="load()" style="color: white; font-size: large; margin: 30px 20px 20px 30px; background-image:url(./design/background.jpg)">
<div id="video" style="visibility:visible; position: absolute; left: 11px; top: 120px; height: 120px; width: 155px; z-index: 3; background-color:#003333; border-color:#FFFFFF; border-style:solid; border-width:thin;"></div>
<iframe name="url" id="url" height="0" width="0" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<iframe name="mainFrame" id="mainFrame" marginwidth="0" marginheight="0" scrolling="no" src="listDir.php?favourites="></iframe>


<div id="infoText"></div>
<div id="fullScreenMode" style="visibility:hidden; position: absolute; left: 0px; top: 0px; height: 600px; width: 800px; z-index: 3; background-color:#003333;"></div>
<div id="infoBox"></div>
<div id="menuBox">
	<div title="listDir.php">Local</div>
	<div title="svtPlay.php">SVT Play</div>
</div> 

</body>

</html>
