<?php 
$querydomaincategories = "SELECT * FROM  domaincategories WHERE parent_id='$domain_id' AND active='yes' ORDER BY order_seq ASC";
$resultdomaincategories = mysql_query ($querydomaincategories);
if (mysql_num_rows($resultdomaincategories) <> 0){
	?>
	<table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin-top:4px">
		<tr> 
			<td background="<?php echo $path;?>images/navigation/city_bg2.gif">
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
					<tr> 
						<?php
						$tv_days = array(
							"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
						);
                        $tv_keys = array();
                        foreach($tv_days as $tv_k=>$tv_day) {
                            $tv_keys[$tv_day] = $tv_k;
                        }
						$tv_categs = array() ;
						while($linedomaincategories = mysql_fetch_assoc($resultdomaincategories)){
                            $day_ = explode("|", $linedomaincategories['title_el']);
							$daynum = intval($tv_keys[trim($day_[0])]);
							$tv_categs [$daynum] = array(
								"friendly_url"	=> trim($linedomaincategories['friendly_url']),
								"catdom_id"		=> intval($linedomaincategories['catdom_id']),
								"title"			=> $tv_days[$daynum],
								"daynum"		=> $daynum
							);
						}
						$dow = intval(date("N")) - 1;
						
						$tv_categs_order = array();
						$cur_day = $dow;
						for ($i=0; $i<7; $i++) {
							if($i == 0) {
								$tv_categs_order[$tv_categs[$cur_day]['catdom_id']] = $tv_categs[$cur_day];
								$cur_day += 1;
							}
							else {
								$tv_categs_order[$tv_categs[$cur_day]['catdom_id']] = $tv_categs[$cur_day];
								$cur_day += 1;
							}
							if($cur_day == 7) $cur_day = 0;
						}
						
						$tv_categs_catdoms = array_keys($tv_categs_order);
						
						$tvcnt = 0;
						$tv_style = "";
						
						if(isset($_REQUEST['debugtv'])) {
							echo '<pre>', var_export($tv_categs_order, true), '</pre>';
						}
						foreach ($tv_categs_order as $tv_catdom_id=>$linedomaincategories) {
							$style="";
							if(isset($catdom_id) && intval($catdom_id) > 0 ) {
								if(in_array($catdom_id, $tv_categs_catdoms) && $catdom_id == intval($linedomaincategories['catdom_id'])) {
									$style = "on";
									$daynum = intval($linedomaincategories['daynum']);
									if($daynum >= $dow) $dd = $daynum - $dow;
									else $dd = 7 + intval($linedomaincategories['daynum']) - $dow;
									
								}
							}
							else {
								if($tvcnt == 0)  {
									$style = "on";
									$dd = 0;
								}
							}

							
							
							?>
							<td class="cityTdSeparator<?php echo $style;?>"><img src="<?php echo $path;?>images/navigation/city_left<?php echo $style;?>.gif" width="7" height="22"></td>
							<td class="cityTd<?php echo $style;?>">
								<?php
								$subcat_href = "";
								$subcat_furl = trim($linedomaincategories['friendly_url']);
								if($subcat_furl != ""){
									$subcat_href = $subcat_furl . '.html';
								}
								else {
									$subcat_href = 'index.php?catdom_id=' . $linedomaincategories["catdom_id"]; 
								}
								?>
								<a href="<?php echo $subcat_href;?>" class="city<?php if($linedomaincategories["catdom_id"]==$catdom_id || ($daynum=='0' && !isset($catdom_id))){echo "red";}?>"><?php echo $linedomaincategories['title']; ?></a>
							</td>
							<td align="right" class="cityTdSeparator<?php echo $style;?>"><img src="<?php echo $path;?>images/navigation/city_right<?php echo $style;?>.gif" width="7" height="22"></td>
							<?php 
							$tvcnt ++;
						}?>               
					</tr>
				</table> 
			</td>
		</tr>
	</table>
	<?php 
}?>