<?php

	$count = 1;
	$j = 1;

	$sql = "SELECT * FROM Firma WHERE ID='1' ";
	$result = $db->query($sql);
	$nt = $result->fetch_assoc();

	$sql1 = "SELECT * FROM Firma WHERE ID='2' ";
	$result1 = $db->query($sql1);
	$nt1 = $result1->fetch_assoc();

	$sql2 = "SELECT * FROM objekte WHERE Aktiv = 1 AND FotoStart = 1 ORDER BY RAND(); ";
	$result2 = $db->query($sql2);
	
	$sql3 = "SELECT * FROM objekte WHERE Aktiv = '1' AND Neu = '1' ORDER BY RAND(); ";
	$result3 = $db->query($sql3);
	while ( $nt3 = $result3->fetch_assoc() )
		{
			if ( file_exists ( "img/objekte/" . $nt3['ID'] . "_1.jpg" ) )
				{
					$image_info	= getimagesize ( "img/objekte/" . $nt3['ID'] . "_1.jpg" );
					if ( $image_info[0] > $image_info[1] )
						{
							break;
						}
				}
		}
	
	$_OV_Typ3 = $nt3['O_TYP'] . ' - ' . $nt3['V_TYP'];
	if ("Wohnung - Miete" == $_OV_Typ3) {
		$neu = "index.php?section=immobilien&amp;topic=wohnung_miete&amp;obj=".$nt3['ID'];
	}
	elseif ("Wohnung - Kauf" == $_OV_Typ3) {
		$neu = "index.php?section=immobilien&amp;topic=wohnung_kauf&amp;obj=".$nt3['ID'];
	}
	elseif ("Haus - Miete" == $_OV_Typ3) {
		$neu = "index.php?section=immobilien&amp;topic=haus_miete&amp;obj=".$nt3['ID'];
	}
	elseif ("Haus - Kauf" == $_OV_Typ3) {
		$neu = "index.php?section=immobilien&amp;topic=haus_kauf&amp;obj=".$nt3['ID'];
	}
	elseif ("gewerbe" == $nt3['KAT'] AND "Kauf" == $nt3['V_TYP'] ) {
		$neu = "index.php?section=immobilien&amp;topic=gewerbe_kauf&amp;obj=".$nt3['ID'];
	}
	elseif ("gewerbe" == $nt3['KAT'] AND "Miete" == $nt3['V_TYP'] ) {
		$neu = "index.php?section=immobilien&amp;topic=gewerbe_miete&amp;obj=".$nt3['ID'];
	}
	elseif ("anlage" == $nt3['KAT'] ) {
		$neu = "index.php?section=immobilien&amp;topic=anlage&amp;obj=".$nt3['ID'];
	}

	echo "<div class=\"firma\">\n";
	echo "<h1>" . $nt ['Firma'] . "</h1>";
	echo $nt ['Vertreter1'];
	echo "<br />&nbsp;<br /><img src=\"img/unterschrift.png\" />";
	echo "</div>\n";

	echo "<div class=\"neu\"> \n";
	echo "    <h2>Neu bei Wachter!</h2> \n";
	echo "<a style=\"border:none; margin:0px; padding:0px;\" href=\"" . $neu . "\"><img src=\"img/objekte/" . $nt3['ID'] . "_1.jpg\" alt=\"" . $nt3['Kurz'] . "\" /></a>\n";
	echo "</div> \n";
	
	echo "<div class=\"kont\"> \n";
	echo "    <h2>Wachter Immobilien</h2> \n";
	echo "    <p>Kirchenöschle 28</p> \n";
	echo "    <p>88422 Betzenweiler</p> \n";
	echo "    <p>+49 7374 9205882</p> \n";
	echo "    <a href=\"mailto:info@wachter-immobilien.com\">info@wachter-immobilien.com</a> \n";
	echo "</div> \n";

	echo "<br class=\"fix\" />\n";
	echo "&nbsp;<br />\n";

	echo "<div class=\"grau\"> \n";
	echo "<table width=\"100%\">\n";
	echo "    <colgroup>\n";
	echo "        <col span=\"4\" width=\"25%\" />\n";
	echo "    </colgroup>\n";
	echo "    <tr>\n";
		while (($count <= 4) AND ($j < 2)) {
			while (($nt2 = $result2->fetch_assoc()) AND ($count<= 4)) {
				$file = "img/objekte/".$nt2['ID']."_1.jpg";
				$_OV_Typ2 = $nt2['O_TYP'] . ' - ' . $nt2['V_TYP'];
				if ("Wohnung - Miete" == $_OV_Typ2) {
					$link = "index.php?section=immobilien&amp;topic=wohnung_miete&amp;obj=".$nt2['ID'];
				}
				elseif ("Wohnung - Kauf" == $_OV_Typ2) {
					$link = "index.php?section=immobilien&amp;topic=wohnung_kauf&amp;obj=".$nt2['ID'];
				}
				elseif ("Haus - Miete" == $_OV_Typ2) {
					$link = "index.php?section=immobilien&amp;topic=haus_miete&amp;obj=".$nt2['ID'];
				}
				elseif ("Haus - Kauf" == $_OV_Typ2) {
					$link = "index.php?section=immobilien&amp;topic=haus_kauf&amp;obj=".$nt2['ID'];
				}
				elseif ("gewerbe" == $nt2['KAT'] AND "Kauf" == $nt2['V_TYP'] ) {
					$link = "index.php?section=immobilien&amp;topic=gewerbe_kauf&amp;obj=".$nt2['ID'];
				}
				elseif ("gewerbe" == $nt2['KAT'] AND "Miete" == $nt2['V_TYP'] ) {
					$link = "index.php?section=immobilien&amp;topic=gewerbe_miete&amp;obj=".$nt2['ID'];
				}
				elseif ("anlage" == $nt2['KAT'] ) {
					$link = "index.php?section=immobilien&amp;topic=anlage&amp;obj=".$nt2['ID'];
				}
				if (file_exists($file)) {
					echo "    <td align=\"center\"><a href=\"$link\"><img src=\"$file\" alt=\"" . $nt2['Kurz'] . "\" width=\"152px\" height=\"114px\" /></a></td>\n";
					$count++;
				}
			}
			$j = 2;
		}
	echo "    </tr>\n";
	echo "</table>\n";
	echo "</div> \n";



?>