<?php
	#
	# 	DECLARE PAGE VARIABLES
	#

 	$my_pagetitle = " - Huvudsida";
	$my_PageTitle = " - Huvudsida";
	$my_frontpage = FALSE;
	$my_topp = "grillspett.jpg";
	$my_header = "tom.gif";

	# 	BUILD HEADER

	include("../kontiki-header.php");

	# 	CONNECT TO DB

	require("../connect-sql.php");

	# 	SET MAIL PREFS

	define("ADRESS", "info@kontiki.nu");
	define("SUBJECT", "ny epostadress fran hemsidan");

	function showPictureInFrame($imgname)
	{
		$path = "../" . $imgname;
		$properties = getimagesize($path);

		if(!is_file($path."_framed.jpg"))
		{
			// check if a framed version of the picture is available, if not, create one
			$newImage = imagecreatetruecolor(230, 250);
			$frameImage = imagecreatefromgif("../img/picture_frame5.gif");
			$newsImage = imagecreatefromjpeg($path);

			// first, resize and copy the information from the news image
			imagecopyresized($newImage, $newsImage, 25, 25, 0, 0, 205, 225, $properties[0], $properties[1]);

			// now we add the frame
			imagecopy($newImage, $frameImage, 0, 0, 0, 0, 230, 250);

			// and finally we save the results
			imagejpeg($newImage, "../" . $imgname . "_framed.jpg", 90);
			imagedestroy($newImage);
			imagedestroy($newsImage);
			imagedestroy($frameImage);
		}
		echo "<img src=\"/" . $imgname . "_framed.jpg\">";
	}

// select all the news events from the database along with their pictures. Print these one by one.

	echo "<table border=0 cellpadding=0 cellspacing=0 width=500 style=\"position:relative; top:-60px;\">\n";
	$query = "select * from news";
	$result = mysql_query($query);
	$left = true;
	while($line = mysql_fetch_array($result))
	{
		if($line[text] != "")
		{
			if($left)
			{
				echo "<tr>\n<td>$line[text]</td><td>";
				showPictureInFrame($line[img]);
				echo "</td>\n</tr>\n";
			}
			else
			{
				echo "<tr>\n<td>";
				showPictureInFrame($line[img]);
				echo "</td><td>$line[text]</td>\n</tr>\n";
			}
			$left = !$left;
		}
	}
	echo "</table>\n";

	include ("../kontiki-footer.php");
	# 	--------- 	rensa upp bättre?
	mysql_close($ODBC); 

php?>