<?php

	$actions = array('new', 'top', 'dload');	

	(key_exists('action', $_GET) && $_GET['action']<>'' && in_array($_GET['action'], $actions) && session_is_registered('mobile_logged_in')) ? $action = $_GET['action'] : $action = '';
	(key_exists('i', $_GET) && $_GET['i']<>'') ? $i = $_GET['i'] : $i = 1;
	
	if(session_is_registered('mobile_logged_in') && session_is_registered('mobile_page_video') && $_SESSION['mobile_page_video']!=0)
	{
		$nastranu = $_SESSION['mobile_page_video'];
	}
	else
	{
		$nastranu = 9;
	}
	
	if($action=='top') 
	{
		$final_query = "SELECT * FROM mobile_video ORDER BY priemer DESC limit 0, $videa_charts";
	}

	if($action=='dload') 
	{
		$final_query = "SELECT * FROM mobile_video WHERE dload>0 ORDER BY dload DESC limit 0, $videa_charts";
	}
	
	if($action=='new') 
	{
		$final_query = "SELECT * FROM mobile_video ORDER BY ID DESC limit 0, $videa_charts";
	}
	
	if($action=='')
	{
		$query = "SELECT * FROM mobile_video"; 
		$chunk = $dba->GetLimit($query);
		$lim = $chunk[0];
    	$max = $chunk[1];
    	$stranok = $chunk[2];
		$final_query = "SELECT * FROM mobile_video ORDER BY nazov ASC limit $lim, $nastranu";
		if(!session_is_registered('mobile_logged_in')) $final_query = "SELECT * FROM mobile_video ORDER BY nazov ASC limit $lim, 5";
	}

	$nadpisy = array
	(
		'new' => 'NEW '.$videa_charts.' videá',
		'top' => 'TOP '.$videa_charts.' videá',
		'dload' => 'TOP DOWNLOAD '.$videa_charts.' videá',
	);
	
	function  fnVypisVidea($result)
	{
		global $blocked_dloads;
		
		if($result)
		{
			InitialzeReklama();
			echo "
			<script language='javascript' type='text/javascript'>\n
			function play(id)\n
			{\n
				window.open('video_player.php?id=' + id, 'player', 'width=200, height=170, menubar=no, directories=no, toolbar=no, top=100, left=100, location=no, scrollbars=no, resizable=no');\n
			}\n
			</script>\n
			";
			while($row = mysql_fetch_array($result))
			{
				ShowReklama();
				$size=round(filesize('video/'.$row["file"])/1024,2);		
				
				echo "<div id=\"melodia_div\">";
				echo "<table width=\"100%\" border=\"0\" cellspacing=\"2\"><tr><td valign=\"top\" width=\"73\">";
				echo "<img src=\"images/video/".$row['image']."\" alt=\"\"/>";
				echo "</td><td valign=\"top\" style=\"padding-left: 5px; padding-top: 0px;\">";
				echo"<b>".$row['nazov']."</b> - <span id=\"red_b\">ID: ".$row["ID"]."</span> (".$size." kB)<br />";
				echo "http://4mobile.sk/video/".$row["ID"]."/<br />";
				if($row["poznamka"]<>'') echo $row["poznamka"]."<br />";
				$priemer = round($row["priemer"],2);
				fnShowStars($priemer);
				echo '&nbsp;'.$row["hlasov"]." hlasov, priemer: ".$priemer.", ".$row["dload"]." stiahnutí <br /> <span id=\"red_b\">Hlasuj!</span> <img src=\"images/smile/17.gif\" alt=\"\" /> ";
				for($k=1;$k<=5;$k++) {echo"<a href='hlasuj.php?action=video&amp;id=".$row['ID']."&amp;hlas=".$k."' id=\"hlasuj\">".$k."</a> ";}
				echo "<img src=\"images/smile/5.gif\" alt=\"\" />";
				if(isset($_SESSION['mobile_logged_in']))
				{
					echo " | <a href='javascript:play(".$row['ID'].");' class='tahaj'>PREHRAŤ</a>";
				}
				if(!$blocked_dloads[3] && session_is_registered('mobile_logged_in'))
				{
					echo " | <a href='http://4mobile.sk/video/".$row["ID"]."/' class='tahaj'>STIAHNI</a>";
				}
				echo "<br />\n</td></tr></table>";
				echo "</div>";
			}
		}
	}
	
?>

	<div id="register_form01">
	  <div id="menu01_head">:: <?php if(key_exists($action, $nadpisy)) echo $nadpisy[$action]; else echo 'videá';?></div>
	  <div id="melodie_01">
	    <?php 
	    
	    	if(!session_is_registered('mobile_logged_in')) echo "<br />Zaregistrovaní používatelia získajú prístup ku všetkým hrám! <br />";
//	    	echo $final_query;
    		if(($action=='') && session_is_registered('mobile_logged_in')) fnNavi($i, $stranok, "module=videa&amp;action=$action");
	    	$result = $dba->GetResult($final_query);
	    	fnVypisVidea($result);
	    	if(($action=='') && session_is_registered('mobile_logged_in')) fnNavi($i, $stranok, "module=videa&amp;action=$action");
    	?>
	  </div>
	</div>