<?php
    $i = 0;
    if(isset($_SERVER['REDIRECT_URL']))
		$tablica = explode('/', $_SERVER['REDIRECT_URL']);
    foreach($menu_items as $menu_item){
        $current='';
        if($menu_item['active']){
            if(isset($tablica[3])){
                //echo $menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html<br/>';
                if($tablica[3] == $menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html' || $tablica[3] == $menu_item['friendlyurl'].'.html'){
                    $current=array( 'idparent'=>$menu_item['idparent'],
                                    'idmenu_items'=>$menu_item['idmenu_items']
                                  );
                }elseif(isset($subarticle)){
                    if($tablica[3] == $article['friendlyurl'].'-'.$article['idarticles'].'.html' && $subarticle['friendlyurl'].'-'.$subarticle['idarticles'].'.html' == $menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html'){
                        $current=array( 'idparent'=>$menu_item['idparent'],
                                        'idmenu_items'=>$menu_item['idmenu_items']
                                      );
                    }elseif(isset($parent)){
                        if($parent['friendlyurl'].'-'.$parent['idarticles'].'.html' == $menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html'){
                            $current=array( 'idparent'=>$menu_item['idparent'],
                                            'idmenu_items'=>$menu_item['idmenu_items']
                                          );
                        }
                    }
                }
            }elseif(isset($tablica[2])){
                if($tablica[2] == $menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html' || $tablica[2] == $menu_item['friendlyurl']){
                    $current=array( 'idparent'=>$menu_item['idparent'],
                                    'idmenu_items'=>$menu_item['idmenu_items']
                                  );
                }
            }else{
                if('' == $menu_item['friendlyurl']){
                    $current=array( 'idparent'=>$menu_item['idparent'],
                                    'idmenu_items'=>$menu_item['idmenu_items']
                                  );
                }
            }
            if($current!=''){
                $all[$i] = $current;
                break;
            }
        }
    }
    //przygotowanie drzewka menu
    if(isset($all)){
        $i++;
         do{
            $child = false;
            foreach($menu_items as $menu_item){
                if($all[$i-1]['idparent']==$menu_item['idmenu_items']){
                    $all[$i] = array( 'idparent'=>$menu_item['idparent'],
                                    'idmenu_items'=>$menu_item['idmenu_items']
                                  );
                    if($all[$i]['idparent']!=''){
                       $child = true;
                       $i++;
                       break;
                    }
                }
            }
         }while($child);
         
         foreach($menu_items as $menu_item){
			if($menu_item['active']){
			//$menu_item['friendlyurl']!='panel-klienta.html' jest warunkiem dodanym tylko na potrzeby networds.pl
                if($menu_item['idparent']==null && $menu_item['friendlyurl']!='panel-klienta.html'){
                 /* w przypadku robienia kresek pomiędzy pozycjami
				if($i>=1){
					echo '<div class="dots"></div>';
				}else{
					$i++;
				}
                */
                    if($all[sizeof($all)-1]['idmenu_items']==$menu_item['idmenu_items']){
                        echo '<div class="menu-poziom-item-left"></div>';
                        echo '<div class="menu-poziom-item-active">';
                    }else{
                        echo '<div class="menu-poziom-item">';
                    }



                    switch($menu_item['type']){
                        case 'article':
                            echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['artykul'].'/'.$menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html">'.$menu_item['elementname'].'</a>';
                            break;
                        case 'gallery':
                            echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['galeria'].'/'.$menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html">'.$menu_item['elementname'].'</a>';
                            break;
                        case 'news':
                            echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['news'].'/'.$menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html">'.$menu_item['elementname'].'</a>';
                            break;
                        case 'none':
                            if($menu_item['friendlyurl']!=''){
                                echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$menu_item['friendlyurl'].'">'.$menu_item['elementname'].'</a>';
                            }else{
                                echo '<a href="/">'.$menu_item['elementname'].'</a>';
                            }
                            break;
                        case 'product_category':
                            echo 'a href="/'.strtolower($this->site['lang']['skrot']).'/'.$menu_item['friendlyurl'].'.html">'.$menu_item['elementname'].'</a>';
                            break;
                        case 'product':
                            echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['produkt'].'/'.$menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html">'.$menu_item['elementname'].'</a>';
                            break;
                    }
                    echo '</div>';
                    if($all[sizeof($all)-1]['idmenu_items']==$menu_item['idmenu_items']){
                            echo '<div class="menu-poziom-item-right"></div>';
                    }
                }
            }
         }
    }else{
        foreach($menu_items as $menu_item){
			if($menu_item['active']){
			//$menu_item['friendlyurl']!='panel-klienta.html' jest warunkiem dodanym tylko na potrzeby networds.pl
                if($menu_item['idparent']==null && $menu_item['friendlyurl']!='panel-klienta.html'){
                    echo '<div class="menu-poziom-item">';
                    switch($menu_item['type']){
                        case 'article':
                            echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['artykul'].'/'.$menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html">'.$menu_item['elementname'].'</a>';
                            break;
                        case 'gallery':
                            echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['galeria'].'/'.$menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html">'.$menu_item['elementname'].'</a>';
                            break;
                        case 'news':
                            echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['news'].'/'.$menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html">'.$menu_item['elementname'].'</a>';
                            break;
                        case 'none':
                            if($menu_item['friendlyurl']!=''){
                                echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$menu_item['friendlyurl'].'">'.$menu_item['elementname'].'</a>';
                            }else{
                                echo '<a href="/">'.$menu_item['elementname'].'</a>';
                            }
                            break;
                        case 'product_category':
                            echo 'a href="/'.strtolower($this->site['lang']['skrot']).'/'.$menu_item['friendlyurl'].'.html">'.$menu_item['elementname'].'</a>';
                            break;
                        case 'product':
                            echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['produkt'].'/'.$menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html">'.$menu_item['elementname'].'</a>';
                            break;
                    }
                    echo '</div>';
                }
            }
         }
    }
 ?>
<?php
/*
	$i=0;
	if(isset($subarticles[0])){
		$subarticle = $subarticles[0];
	}
	if(isset($_SERVER['REDIRECT_URL']))
		$tablica = explode('/', $_SERVER['REDIRECT_URL']);
		
        foreach($menu_items as $menu_item){
			if($menu_item['active']){	
			//$menu_item['friendlyurl']!='panel-klienta.html' jest warunkiem dodanym tylko na potrzeby networds.pl
             if($menu_item['idparent']==null && $menu_item['friendlyurl']!='panel-klienta.html'){
             */ /*
         * w przypadku robienia kresek pomiędzy pozycjami 
				if($i>=1){
					echo '<div class="dots"></div>';
				}else{ 
					$i++;
				}
                *//*
				if(isset($tablica[3])){
						if($tablica[3] == $menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html' || $tablica[3] == $menu_item['friendlyurl'].'.html'){
							$active=true; 
						}elseif(isset($subarticle)){
							if($tablica[3] == $article['friendlyurl'].'-'.$article['idarticles'].'.html' && $subarticle['friendlyurl'].'-'.$subarticle['idarticles'].'.html' == $menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html'){
								$active=true; 
							}elseif(isset($parent)){
								if($parent['friendlyurl'].'-'.$parent['idarticles'].'.html' == $menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html'){
									$active=true; 
								}else{
									$active=false; 
								}
							}else{
								$active=false; 
							}
						}else{
							$active=false; 
						}
					}elseif(isset($tablica[2])){
						if($tablica[2] == $menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html' || $tablica[2] == $menu_item['friendlyurl']){
							$active=true; 
						}else{
							$active=false; 
						}
					}else{
						if('' == $menu_item['friendlyurl']){
							$active=true; 
						}else{
							$active=false; 
						}
					}
                    
                    if(!$active){
                       foreach($menu_items as $submenu_item){
                            if($submenu_item['idparent'] == $menu_item['idmenu_items'] && !$active){
                                if(isset($tablica[3])){
                                    if($tablica[3] == $submenu_item['friendlyurl'].'-'.$submenu_item['idelement'].'.html' || $tablica[3] == $submenu_item['friendlyurl'].'.html'){
                                        $active=true;
                                    }elseif(isset($subarticle)){
                                        if($tablica[3] == $article['friendlyurl'].'-'.$article['idarticles'].'.html' && $subarticle['friendlyurl'].'-'.$subarticle['idarticles'].'.html' == $submenu_item['friendlyurl'].'-'.$submenu_item['idelement'].'.html'){
                                            $active=true;
                                        }elseif(isset($parent)){
                                            if($parent['friendlyurl'].'-'.$parent['idarticles'].'.html' == $submenu_item['friendlyurl'].'-'.$submenu_item['idelement'].'.html'){
                                                $active=true;
                                            }else{
                                                $active=false;
                                            }
                                        }else{
                                            $active=false;
                                        }
                                    }else{
                                        $active=false;
                                    }
                                }elseif(isset($tablica[2])){
                                    if($tablica[2] == $submenu_item['friendlyurl'].'-'.$submenu_item['idelement'].'.html' || $tablica[2] == $submenu_item['friendlyurl']){
                                        $active=true;
                                    }else{
                                        $active=false;
                                    }
                                }else{
                                    if('' == $submenu_item['friendlyurl']){
                                        $active=true;
                                    }else{
                                        $active=false;
                                    }
                                }
                            }
                        }
                    }
                    
					if($active){
						echo '<div class="menu-poziom-item-left"></div>';
                        echo '<div class="menu-poziom-item-active">';
					}else{
                        echo '<div class="menu-poziom-item">';
                    }
					
				
					
				switch($menu_item['type']){
					case 'article':
						echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['artykul'].'/'.$menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html">'.$menu_item['elementname'].'</a>';
						break;
					case 'gallery':
						echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['galeria'].'/'.$menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html">'.$menu_item['elementname'].'</a>';
						break;
					case 'news':
						echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['news'].'/'.$menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html">'.$menu_item['elementname'].'</a>';
						break;
					case 'none':
                        if($menu_item['friendlyurl']!=''){
                            echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$menu_item['friendlyurl'].'">'.$menu_item['elementname'].'</a>';
                        }else{
                            echo '<a href="/">'.$menu_item['elementname'].'</a>';
                        }
						break;
					case 'product_category':
						echo 'a href="/'.strtolower($this->site['lang']['skrot']).'/'.$menu_item['friendlyurl'].'.html">'.$menu_item['elementname'].'</a>';
						break;
					case 'product':
						echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['produkt'].'/'.$menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html">'.$menu_item['elementname'].'</a>';
						break;
				}
				echo '</div>';
                if($active){
                        echo '<div class="menu-poziom-item-right"></div>';
					}
                  */ /*
				if($active){
					foreach($menu_items as $submenu_item){
						if($submenu_item['idparent']==$menu_item['idmenu_items']){
							$friendlyurl = $submenu_item['friendlyurl'].'-'.$submenu_item['idelement'].'.html';
							$color = 'class="submenu"';
							if(isset($tablica[3])){
								if($tablica[3]==$friendlyurl){
									$color = 'class="submenu_active"';
								}
							}
							echo '<div '.$color.'>';
							switch($submenu_item['type']){
								case 'article':
									echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['artykul'].'/'.$friendlyurl.'">'.$submenu_item['elementname'].'</a>';
									break;
								case 'gallery':
									echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['galeria'].'/'.$friendlyurl.'">'.$submenu_item['elementname'].'</a>';
									break;
								case 'news':
									echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['news'].'/'.$friendlyurl.'">'.$submenu_item['elementname'].'</a>';
									break;
								case 'none':
									echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$submenu_item['friendlyurl'].'">'.$submenu_item['elementname'].'</a>';
									break;
								case 'product_category':
									echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$submenu_item['friendlyurl'].'.html">'.$submenu_item['elementname'].'</a>';
									break;
								case 'product':
									echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$menu_item['friendlyurl'].'/'.$friendlyurl.'">'.$submenu_item['elementname'].'</a>';
									break;
							}
							echo '</div>';
						}
					}
				}
                *//*
			}
		}
	}*/
?>