<?php @session_start(); ?>
<script type="text/javascript">
	var yasurl = "<?php echo $setting['siteurl'].'includes/ratingbar/rpc.php';?>";
</script>
<?php
require('./includes/ratingbar/_drawrating.php'); // processes game votes and displays stars
if (isset($_POST['Favourites_x'])) {
	yasDB_insert("INSERT INTO favourite (userid, gameid) VALUES({$_SESSION['userid']}, {$_POST['gamesave']})") or die("Error updating favourites");
}
$query = yasDB_select("SELECT * FROM `games` WHERE id = '$id'");
$row = $query->fetch_array(MYSQLI_ASSOC);
if ($row['thumbnail_200'] != '') $row['thumbnail'] = $row['thumbnail_200'];
if (file_exists($row['thumbnail'])) {
	$thumbnail = $row['thumbnail'];						
} else {
	$thumbnail = 'templates/' . $setting['theme'] . '/skins/' . $setting['skin'] . '/images/nopic.jpg';
}
if ($row['type'] == 'SWF' || $row['type'] == 'Remote') {
	if ($row['height']<350 || $row['width']<350) { // games are not likely less than 350px so lets double check the actual game size
		if ($row['type'] == 'SWF') {
			list($width, $height, $type, $attributes) = getimagesize($setting['sitepath'].'/'.$row['file']);
		} elseif ($row['type'] == 'Remote') {
			list($width, $height, $type, $attributes) = getimagesize($row['file']);
		}
		$row['height'] = $height;
		$row['width'] = $width;
	}
	$ratio = $row['height']/$row['width'];
	$new_width = 756;
	$new_height = ceil($new_width*$ratio);
}
if ($row['type'] == 'Remote' && @getimagesize($row['thumbnail'])) {
	$thumbnail = $row['thumbnail'];
} elseif (file_exists($setting['sitepath'].$row['thumbnail'])) {
	$thumbnail = $setting['siteurl'].$row['thumbnail'];
	$thumbnail = urldecode($thumbnail);
} else {
	$thumbnail = $setting['siteurl'].'templates/' . $setting['theme'] . 'skins/' . $setting['skin'] . 'image/nopic150.jpg';
}
$displayed = 'no';
$lightbox = $setting['lightbox'];
/////////////////////////////////////////////////
//											   //
//				if light box is on			   //	
/////////////////////////////////////////////////
if ($lightbox == 'yes') {
	if ($row['type'] == 'SWF' || $row['type'] == 'MPG' || $row['type'] == 'IMAGE' || $row['type'] == 'YOUTUBE' || $row['type'] == 'Remote'){ 
		$displayed = 'yes';
		?>
		<div id="left">  
			<div id="game_title_header"><?php echo $row['title'];?></div>
			<div id="game_box">
				<div id="game_box_ad">				
				<?php
				// set light box according to type
				switch ($row['type']) {
					case 'SWF':
						$class = 'game';
						$file = $setting['siteurl'].$row['file'];
						?>
						<script type="text/javascript">
							$(document).ready(function() {
								$("a.game").fancybox({
									'type'              : 'swf',
		 							'padding'			: 0,
									'autoScale'			: false,
									'transitionIn'		: 'elastic',
									'transitionOut'		: 'fade',
									'width'             : 800,
									'height'            : <?php echo ceil(800*$ratio);?>,
									'hideOnContentClick': false,
									'hideOnOverlayClick': false

								});
							});
						</script>
						<?php
						break;
					case 'Remote':
						$class = 'game';
						$file = $row['file'];
						?>
						<script type="text/javascript">
							$(document).ready(function() {
								$("a.game").fancybox({
									'type'              : 'swf',
		 							'padding'			: 0,
									'autoScale'			: false,
									'transitionIn'		: 'elastic',
									'transitionOut'		: 'fade',
									'width'             : 800,
									'height'            : <?php echo ceil(800*$ratio);?>,
									'hideOnContentClick': false,
									'hideOnOverlayClick': false

								});
							});
						</script>
						<?php
						break;
					case 'YOUTUBE':
						$class = 'youtube';
						$file = str_replace("watch?v=", "v/", $row['file']). '&fs=1';
						?>
						<script type="text/javascript">
							$(document).ready(function() {
								$("a.youtube").fancybox({
									'type'              : 'swf',
									'padding'			: 0,
									'transitionIn'		: 'elastic',
									'transitionOut'		: 'fade',
									'width'             : 680,
									'height'            : 495,
									'hideOnContentClick': false,
									'hideOnOverlayClick': false
								});
							});
						</script>
						<?php
						break;
					default:
						break;
				}
				if (ad("3") == 'Put AD code here') {
					?><img src="<?php echo $setting['siteurl'].'templates/'.$setting['theme'].'/skins/'.$setting['skin'].'/images/300x250.png';?>" width="300" height="250" /><?php //temp ad pic
				} else {
					echo ad("3");
				}				
				$pic_settings = array('w'=>150,'h'=>150);
				?>
				</div>				
				<div id="gameplay_pic">
				<a class="<?php echo $class;?>" href="<?php echo $file;?>" title="<?php echo $row['title'];?>"> 
				  <img src="<?php echo resize($setting['siteurl'].$thumbnail, $pic_settings);?>" alt="<?php echo $row['title'];?>" width="150" height="150"/></a>
				  <div id="gameplay_btn"><a class="<?php echo $class;?>" href="<?php echo $file;?>" title="<?php echo $row['title'];?>"> 
				  <img src=" <?php echo $setting['siteurl'];?>templates/<?php echo $setting['theme'];?>/skins/<?php echo $setting['skin'];?>/images/buttons/play.png" width="100" height="30" alt="Playing: <?php echo $row['title'];?>" /></a></div>
				  </div>
				 
				
				<?php
				// The following code is for a box of random games
				echo '<div id="random">';
				$query = yasDB_select("select * from games order by rand() limit 9");
				$pic_settings = array('w'=>60,'h'=>60);
				while($games = $query->fetch_array(MYSQLI_ASSOC)) {
					$gameurl = prepGame($games['title']);
					if (file_exists($games['thumbnail'])) {
						$thumbnail = $games['thumbnail'];						
					} else {
						$thumbnail = 'templates/' . $setting['theme'] . '/skins/' . $setting['skin'] . '/images/nopic.jpg';
					}
					if ($setting['seo']=="yes") {
						echo $setting['siteurl'] . $thumbnail;
						exit;
						echo'<a href="' . $setting['siteurl'] . 'game/' . $games['id'] . '/' . $gameurl . '.html' . '">
							<img src="' . resize($setting['siteurl'] . $thumbnail, $pic_settings) . '" width="60" height="60" alt="'.$games['title'].'" title="'.$games['title'].'"/></a>';                         
					}else {
						echo '<a href="' . $setting['siteurl'] . 'index.php?act=game&id=' . $games['id'] . '">
							<img src="' . resize($setting['siteurl'] . $thumbnail, $pic_settings) . '" width="60" height="60" alt="'.$games['title'].'" title="'.$games['title'].'"/></a>';
					}
					
				}
				echo '</div>';?>
				          	
		<?php	if(isset($_SESSION["user"])) { 
					$user=$_SESSION["user"];
					$userid = $_SESSION['userid'];
					echo '<div id="favorites"><form method="post" action="">
						<input type="hidden" name="usersave" value="' . $userid . '"  />
						<input type="hidden" name="gamesave" value="' . $row['id'] .'" />
						<input type="image" name="Favourites" value="Favourites" alt="Save to Favorites" src="' . $setting['siteurl'] . 'templates/' . $setting['theme'] . '/skins/'.$setting['skin'].'/images/buttons/favorite.png" width="100" height="30" onclick="addFavorite(\''.$row['title'].'\',\''.$id.'\');return false">
						</form></div>';
				}
	}
	else {
		$lightbox = "no";
	}	
}
/////////////////////////////////////////////////////////////////////
//											                       //
//				if light box is off	or unsupported format		   //	
/////////////////////////////////////////////////////////////////////
else if ($lightbox=='no'){
    ?>
<div id="left">  

 	<br /><div id="game_title_header"><?php echo $row['title'].'<'.$lightbox.'>';?></div><div id="game_box" style="height:auto;">
    <br/>
    <div align="center">
      <?php
	if ($row['type']=='SWF' || $row['type']=='Remote' && $displayed == 'no') {
        echo '<div id="gameDiv" style="height: '.$new_height.'px; width: '.$new_width.'px; position:relative; top: 0; left: 0">';
        include "media/swf.php";
        echo '</div>';
    }else if($row['type']=='DCR') {              
		include "media/dcr.php"; 
	}else if($row['type']=='WMV') {
		include "media/wmv.php";
	}else if($row['type']=='MPG' && $displayed == 'no') {
		include "media/mpg.php";
	}else if($row['type']=='AVI') {
		include "media/avi.php";
	}else if($row['type']=='MOV') {
		include "media/mov.php";
	}else if($row['type']=='IMAGE' && $displayed == 'no') {
		include "media/image.php";
	}else if($row['type']=='FLV') {
		include "media/flv.php";
	}else if($row['type']=='YOUTUBE') {
		include "media/youtube.php";
	}else if($row['type']=='CustomCode') {
		echo $row['code'];
	}		          
    ?> 
    <br/> 
<?php	if(isset($_SESSION["user"])) { 
			$user=$_SESSION["user"]; 
			$userid = $_SESSION["userid"];
			echo '<div style="width:101px; height:31px;"><form method="post" action="">
				<input type="hidden" name="usersave" value="' . $userid . '"  />
				<input type="hidden" name="gamesave" value="' . $row['id'] .'" />
				<input type="image" name="Favourites" value="Favourites" alt="Save to Favorites" src="' . $setting['siteurl'] . 'templates/' . $setting['theme'] . '/skins/'.$setting['skin'].'/images/buttons/favorite.png" width="100" height="30" onclick="addFavorite(\''.$row['title'].'\',\''.$id.'\');return false">
				</form></div>'; 
		}
?>
	  <br/></div>     
    
<?php    
}
/////////////////////////////////////////////////
//											   //
//				end light box check			   //	
/////////////////////////////////////////////////
// Begin Facebook Like button		
if ($setting['seo']=="yes") {
	$url = $setting['siteurl'] . 'game/' . $row['id'] . '/' . $row['title'] . '.html';
} 
else {			
	$url = $setting['siteurl'] . 'index.php?act=game&id=' . $row['id'];
}
	echo '<div id="facebook"><iframe src="http://www.facebook.com/plugins/like.php?href='.urlencode($url).'&amp;layout=standard&amp;';
	echo 'show_faces=true&amp;width=400&amp;action=like&amp;font=lucida+grande&amp;colorscheme=light&amp;height=28" scrolling="no" frameborder="0"'; 
	echo 'style="border:none; overflow:hidden; width:400px; height:28px;" allowTransparency="true"></iframe></div>';
// End Facebook code ?>
<div class="clear"></div>

<div class="gamebar">
	<a href="http://get.adobe.com/shockwave/"  title="Get Shockwave Player" target="_blank">			
	<img src="<?php echo $setting['siteurl'];?>templates/<?php echo $setting['theme'];?>/skins/<?php echo $setting['skin'];?>/images/buttons/shockwave.png" width="100" height="30" border="0" alt="Get Shockwave Player"/></a>&nbsp;&nbsp;
	<a href="<?php echo $setting['siteurl'].$row['file'];?>"><img src="<?php echo $setting['siteurl'];?>templates/<?php echo $setting['theme'];?>/skins/<?php echo $setting['skin'];?>/images/buttons/fullscreen.png" width="100" height="30" border="0" alt="Go Fullscreen"/></a>&nbsp;&nbsp;
   	<a href="http://get.adobe.com/flashplayer/"  title="Get Flash Player"><img src="<?php echo $setting['siteurl'];?>templates/<?php echo $setting['theme'];?>/skins/<?php echo $setting['skin'];?>/images/buttons/flash.png" width="100" height="30" border="0" alt="Get Flash Player" /></a> &nbsp;&nbsp; 
</div></div><br/><br/>
<div id="description_top">info </div>
<div id="description_box">
<div id="game_description">
    <strong>Name: </strong><?php echo $row['title'];?>
    <br/><br/><strong>Description: </strong> <?php echo $row['description'];?></p>
    <br/><br/><strong>Instuctions: </strong> <?php echo $row['instructions'];?></p>
    <br/><br/><strong>Keywords: </strong> 
	<?php
    $row['keywords'] = explode(',', $row['keywords']);
    foreach ($row['keywords'] as $keyword) {
        echo "<a href='".$setting['siteurl'] ."/index.php?act=search&q=".$keyword."'>".$keyword."</a>";
	}
	?>
    <br/><br/><strong>Views: </strong><?php echo $row['plays'];?>
</div>
<div id="game_description">
    <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rating:</strong><br />
    <div id="ratingbox"><?php echo rating_bar($row['id'],''); ?> </div>
    <br />
    <div id="gamecode">
		<strong>Game Code:</strong>    
        <?php
		$query = yasDB_select("SELECT * FROM `games` WHERE id = '$id'");
		$row = $query->fetch_array(MYSQLI_ASSOC);
		$query->close();
		?>
        <textarea style="width: 300px; height: 100px; border:solid 3px #999; font: normal 12px arial;" id="txtarea" onClick="SelectAll('txtarea');">
        <?php 
        if($row['type']=='SWF') {
			include "media/swf.php";  
        }else if($row['type']=='DCR') { 
	        include "media/dcr.php";  
	    }else if($row['type']=='WMV') {
		    include "media/wmv.php";
	    }else if($row['type']=='MPG') {
		    include "media/mpg.php";
	    }else if($row['type']=='AVI') {
		    include "media/avi.php";
	    }else if($row['type']=='MOV') {
		    include "media/mov.php";
	    }else if($row['type']=='IMAGE') {
		    include "media/image.php";
	    }else if($row['type']=='FLV') {
		    include "media/flv.php";
	    }else if($row['type']=='YOUTUBE') {
		    include "media/youtube.php";
	    }else if($row['type']=='CustomCode') {
		    echo $row['code'];
	    }          
		?>
		<br/><a href="<?php echo $setting['siteurl'];?>"><?php echo $setting['slogan'];?></a>
		</textarea>
	</div>
</div><br style="clear: both"/></div><div id="description_bottom"></div><div class="gamebar"></div><br/><br/><br/>
				
				<div id="comment_header"><strong>Comments:</strong></div>
                <div id="comment_box">
                <div align="center"><div id="preview"></div><div id="messages"><br/><br/>
				
				<?php
	$query = yasDB_select("SELECT count(id) AS count FROM comments WHERE gameid = '$id'");
	$result = $query->fetch_array(MYSQLI_ASSOC);
	$total = $result['count'];
	$prefix = $setting['siteurl'] . 'templates/' . $setting['theme'] . '/skins/' . $setting['skin'] . '/images/smileys/';
	if($total == 0) {
		echo '<div id="comment_text">This game has no comments, be the first to add one!</div>';
	} else {
		$query = yasDB_select("SELECT * FROM comments WHERE gameid = '$id'");
		while($row = $query->fetch_array(MYSQLI_ASSOC)) {
			$text = $row['comment'];
			$text = str_replace(':D','<img src="' . $prefix . 'biggrin.gif" title="biggrin" alt="biggrin" />',$text);
			$text = str_replace(':?','<img src="' . $prefix . 'confused.gif" title="confused" alt="confused" />',$text);
			$text = str_replace('8)','<img src="' . $prefix . 'cool.gif" title="cool" alt="cool" />',$text);
			$text = str_replace(':cry:','<img src="' . $prefix . 'cry.gif" title="cry" alt="cry" />',$text);
			$text = str_replace(':shock:','<img src="' . $prefix . 'eek.gif" title="eek" alt="eek" />',$text);
			$text = str_replace(':evil:','<img src="' . $prefix . 'evil.gif" title="evil" alt="evil" />',$text);
			$text = str_replace(':lol:','<img src="' . $prefix . 'lol.gif" title="lol" alt="lol" />',$text);
			$text = str_replace(':x','<img src="' . $prefix . 'mad.gif" title="mad" alt="mad" />',$text);
			$text = str_replace(':P','<img src="' . $prefix . 'razz.gif" title="razz" alt="razz" />',$text);
			$text = str_replace(':oops:','<img src="' . $prefix . 'redface.gif" title="redface" alt="redface" />',$text);
			$text = str_replace(':roll:','<img src="' . $prefix . 'rolleyes.gif" title="rolleyes" alt="rolleyes" />',$text);
			$text = str_replace(':(','<img src="' . $prefix . 'sad.gif" title="sad" alt="sad" />',$text);					
			$text = str_replace(':)','<img src="' . $prefix . 'smile.gif" title="smile" alt="smile" />',$text);
			$text = str_replace(':o','<img src="' . $prefix . 'surprised.gif" title="surprised" alt="surprised" />',$text);
			$text = str_replace(':twisted:','<img src="' . $prefix . 'twisted.gif" title="twisted" alt="twisted" />',$text);
			$text = str_replace(':wink:','<img src="' . $prefix . 'wink.gif" title="wink" alt="wink" />',$text);
			echo '<p class="comments"><strong>' . $row['name'] . ' </strong>- ' . $text . '<br/><br/>';
		}
	}
	$query->close();
	if (isset($_POST['comment'])) {
		$comment = $_POST['comment'];
	} else {
		$comment = '';
	}
	?>
</div></div>
<div class="clear"></div>
<div class="game_box">
	<div class="comment_box">
	<div id="commentBox"><div class="comment_box3"><center>
		<form name="addcomment" id="addcomment" method="post" action="<?php echo $setting['siteurl'];?>includes/comment.php">
			<br/><strong>Message:</strong><br />
			<textarea name="comment" rows="3" cols="26" id="comment_message"><?php echo $comment; ?></textarea><br />
			<input name="gameid" id="gameid" type="hidden" value="<?php echo $id;?>" />
			<input name="title" type="hidden" value="<?php echo $row['title'];?>" />
			<input type="hidden" name="timestamp" id="timestamp" value="<?php echo time(); ?>" />
			</center>
	</div>
		<div id="smiles"><center>
		    <a href="javascript:addsmilie(' :D ')"><img src="<?php echo $prefix.'biggrin.gif';?>" border="0"  /></a>
		    <a href="javascript:addsmilie(' :? ')"><img src="<?php echo $prefix.'confused.gif';?>" border="0"  /></a>
		    <a href="javascript:addsmilie(' 8) ')"><img src="<?php echo $prefix.'cool.gif';?>" border="0"  /></a>
		    <a href="javascript:addsmilie(' :cry: ')"><img src="<?php echo $prefix.'cry.gif';?>" border="0"  /></a>
		    <a href="javascript:addsmilie(' :shock: ')"><img src="<?php echo $prefix.'eek.gif';?>" border="0"  /></a>
		    <a href="javascript:addsmilie(' :evil: ')"><img src="<?php echo $prefix.'evil.gif';?>" border="0"  /></a>
		    <a href="javascript:addsmilie(' :lol: ')"><img src="<?php echo $prefix.'lol.gif';?>" border="0"  /></a>
		    <a href="javascript:addsmilie(' :x ')"><img src="<?php echo $prefix.'mad.gif';?>" border="0"  /></a><br />
		    <a href="javascript:addsmilie(' :P ')"><img src="<?php echo $prefix.'razz.gif';?>" border="0"  /></a>
		    <a href="javascript:addsmilie(' :oops: ')"><img src="<?php $prefix.'redface.gif';?>" border="0"  /></a>
		    <a href="javascript:addsmilie(' :roll: ')"><img src="<?php echo $prefix.'rolleyes.gif';?>" border="0"  /></a>
		    <a href="javascript:addsmilie(' :( ')"><img src="<?php echo $prefix.'sad.gif';?>" border="0"  /></a>
		    <a href="javascript:addsmilie(' :) ')"><img src="<?php echo $prefix.'smile.gif';?>" border="0"  /></a>
		    <a href="javascript:addsmilie(' :o ')"><img src="<?php echo $prefix.'surprised.gif';?>" border="0"  /></a>
		    <a href="javascript:addsmilie(' :twisted: ')"><img src="<?php echo $prefix.'twisted.gif';?>" border="0"  /></a>
		    <a href="javascript:addsmilie(' :wink: ')"><img src="<?php echo $prefix.'wink.gif';?>" border="0"  /></a>
		</center>
		</div>
	<div class="comment_box4"><center>
		<strong>Name:</strong><br />
		<?php
		if (isset($_POST['name'])) {
			$commentname = $_POST['name'];
		} else if (isset($_SESSION['user'])) {
			$commentname = $_SESSION['user'];
		} else {
			$commentname = '';
		}
		?>
		<input name="name" type="text" style="border: 1px solid #000;" value="<?php echo $commentname;?>"/><br /><br />	
		<?php
		if ($setting['userecaptcha'] == "yes") {
			@session_start();
			// securimage captcha
			?>
			<div style="width: 760px; float:left;height: 90px">
			<img id="siimage" align="center" style="padding-right: 5px; border: 0" src="<?php echo $setting['siteurl']; ?>includes/securimage/securimage_show.php?sid=<?php echo md5(time()) ?>" />
			<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="19" height="19" id="SecurImage_as3" align="middle">
			    <param name="allowScriptAccess" value="sameDomain" />
			    <param name="allowFullScreen" value="false" />
			    <param name="movie" value="<?php echo $setting['siteurl']; ?>includes/securimage/securimage_play.swf?audio=securimage_play.php&bgColor1=#fff&bgColor2=#00132f&iconColor=#000&roundedCorner=5" />
			    <param name="quality" value="high" />			
			    <param name="bgcolor" value="#00132f" />
			    <embed src="<?php echo $setting['siteurl']; ?>includes/securimage/securimage_play.swf?audio=securimage_play.php&bgColor1=#fff&bgColor2=#00132f&iconColor=#000&roundedCorner=5" quality="high" bgcolor="#00132f" width="19" height="19" name="SecurImage_as3" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
			 </object>
			        
			<!-- pass a session id to the query string of the script to prevent ie caching -->			
			<a tabindex="-1" style="border-style: none" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = '<?php echo $setting['siteurl']; ?>includes/securimage/securimage_show.php?sid=' + Math.random(); return false"><img src="<?php echo $setting['siteurl']; ?>includes/securimage/images/refresh.gif" alt="Reload Image" border="0" onclick="this.blur()" align="middle" /></a>
			<div style="clear: both"></div>
			</div>			
			Security Code:<br />
			<input type="text" name="code" size="12" /><br /><br />
			<input name="recaptcha" type="hidden" value="yes" /><?php
			// end securimage captcha
		}
		else {
			?>Security Question: five + five = <br />
            <input name="security" type="text" style="border: 1px solid #000;" /><br/>
			<input name="recaptcha" type="hidden" value="no" />
			<?php
		} ?>
        <input name="addcomment" type="submit" value="Add Comment" style="border: 1px solid #000; margin-top: 2px;" />
	</form></div><div id="comment_footer"></div></div>
				<div class="clear"></div>    
</div></div></div><div id="comment_bar"></div>		