<?php
$cache = RayCache::getInstance('home', null, array('prefix' => 'slim_', 'path' => 'cache/', 'expire' => $setting['cachelife']));
$data = $cache->read('home');
if ($data) {
	echo $data;
} else {
	$cache->start_caching();

$pic_settings = array('w'=>80,'h'=>80);
?>
<div id="left">
	<ul style="display:inline;width:761px;list-style: none; margin: 0 0 0 0; padding: 0 0 0;">
	<?php
	$select_cats = yasDB_select("SELECT * FROM categories WHERE active='yes'AND home='yes' ORDER BY `order` DESC");
	while($cats = $select_cats->fetch_array(MYSQLI_ASSOC)){
		$gamesort = $setting['gamesort'];   
		$numbgames = $setting['numbgames'];
		$numbgames = 4;
		$catid = $cats['id'];
		if ($gamesort=='popular') {
			$query = yasDB_select("SELECT * FROM games WHERE category=".$catid." ORDER BY plays DESC LIMIT ".$numbgames."");
		}
		elseif ($gamesort=='newest') {
			$query = yasDB_select("SELECT * FROM games WHERE category=".$catid." ORDER BY id DESC LIMIT ".$numbgames."");
		} 
		else {
		  $query = yasDB_select("SELECT * FROM games WHERE category=".$catid." ORDER BY md5(rand()) LIMIT ".$numbgames."");
		}
		if ($query->num_rows == 0) continue;
		$hsize = 92 * $numbgames + 52;
		echo '<li style="list-style:none;height:'. $hsize . 'px; float:left;"><div id="main_wrap"><div class="list_column"><div class="category_image">';
		echo '<h2>';
		if ($setting['seo'] == 'yes') {
			echo '<a href="' . $setting['siteurl'] . 'category/' . $cats['id'] .'/1.html">' . $cats['name'] . '</a></h2>';
		}
		else {
			echo '<a href="' . $setting['siteurl'] . 'index.php?act=cat&id=' . $cats['id'] .'">' . $cats['name'] . '</a></h2>';
		}	
		echo '</div>';
		while($games = $query->fetch_array(MYSQLI_ASSOC)){
			$gameurl = prepgame($games['title']);
			$games['description'] = stripslashes($games['description']);
			$description = str_replace(array("\r\n", "\r", "\n", "'", '"'), ' ', $games['description']);
			if (file_exists($games['thumbnail'])) {
				$thumbnail = urldecode($games['thumbnail']);
			} else {
				$thumbnail = $setting['siteurl'].'templates/'.$setting['theme'].'/skins/'.$setting['skin'].'/images/nopic.jpg';
			}
			if ($setting['seo']=='yes') {
				$gurl = $setting['siteurl'] . 'game/' . $games['id'] . '/' . $gameurl . '.html';
			} else {
				$gurl = $setting['siteurl'] . 'index.php?act=game&id=' . $games['id'];
			}	
			echo'<div class="main_game_holder"><a href="' . $gurl . '">';
			echo '<img align="absmiddle" src="' . resize($thumbnail, $pic_settings) . '" width="80" height="80" /></a>';
			echo '<div class="main_game_holder_text"><a href="' . $gurl . '" class="hintanchor" onMouseover="showhint(\''.$description.'\', this, event, \'200px\')"> ';
			echo $games['title'] . '</a></div><div class="play"><a href="' . $gurl;
			echo '"><img name="Play" src="' . $setting['siteurl'] . 'templates/' . $setting['theme'] . '/skins/'.$setting['skin'].'/images/buttons/play.png" ';
			echo 'title="' . $games['title'] . '" width="60" height="30" /></a></div></div>';
		}
		echo '</div></div></li></ul><div style="clear:right";></div>';
	}
$cache->write('home');
$cache->stop_caching();
echo $cache->read('home');
}
include ("templates/".$setting['theme']."/small_footer.php"); ?>