<?php
$lang = Yii::app()->getLanguage();
$style_script = "";

?>
<div class="container">
	<div class="row nav-row">
		<?php if ($lang == 'ar') { ?>
			<div class="hidden-xs col-sm-3">
			<?php } else { ?>
				<div class="hidden-xs col-sm-3">
				<?php } ?>

				<a href="<?php echo (Yii::app()->baseUrl == "" ? "/" : Yii::app()->baseUrl); ?>">
					<?php if ($lang == 'ar') { ?>
						<img class="img-logo center-block logo-image" src="<?php echo Yii::app()->request->baseUrl; ?>/images/logo.png" alt="al baraka logo">
					<?php } else { ?>

						<img class="img-logo center-block logo-image-english" src="<?php echo Yii::app()->request->baseUrl; ?>/images/logo-en.png" alt="al baraka logo english">
					<?php } ?>
				</a>

				</div>

				<?php if ($lang == 'ar') { ?>
					<div class="hidden-xs col-sm-9" id="hidde">
					<?php } else { ?>
						<div class="hidden-xs col-sm-9">
						<?php } ?>
						<div class="row">
							<nav class="navbar nav1">
								<div id="myNavbar">
									<ul class="nav navbar-nav" id="nav-header">
										<?php
										$header_menu = Menu::model()->findByAttributes(array('title' => 'header'));
										if ($header_menu != null) {
											foreach ($header_menu->menuItems as $item)
												echo '<li class="active"><a class="link" href="' . ((substr($item->link, 0, 4) === "http") ? $item->link : (Yii::app()->request->baseUrl . $item->link)) . '" ' . ((substr($item->link, 0, 4) === "http") ? 'target="_blank"' : '') . '>' . ($lang == "en" ? $item->en_title : $item->title) . '</a></li> ';
										}
										?>
										<li class="active">
											<a class="link" id="show-modal" href=""> <?php echo $lang == 'ar' ? ' فحص &nbsp; الوثائق' : 'Check Documents' ?></a>
										</li>
									</ul>
									<div class="nav navbar-nav navbar-left minus-10per-<?= $lang == 'ar' ? 'left' : 'right' ?>-margin">

										<form class="navbar-form navbar-right" action="<?php echo Yii::app()->request->baseUrl; ?>/site/siteSearch" method="post">
											<input type="hidden" name="_csrf" value="<?= Yii::app()->request->getCsrfToken() ?>">
											<div class="form-group">
												<input class="form-control search-box-nav" name="search" placeholder="<?php echo ($lang == 'en' ? 'Search' : 'أدخل كلمة البحث  ...') ?>">
												<button type="submit" class="btn btn-default search-btn-nav">
													<img class="img-responsive img-search-icon" src="<?php echo Yii::app()->request->baseUrl; ?>/images/searchicon.png" alt="search-icon">
												</button>
											</div>
										</form>
										<div class="dropdown lang-menu">
											<a href="<?php
														$currpage = strpos(Yii::app()->request->url, '?lang') ? (substr(Yii::app()->request->url, 0, strpos(Yii::app()->request->url, '?lang'))) : (Yii::app()->request->url);
														echo Yii::app()->request->baseUrl . '/site/setLanguage?lang=' . ($lang == 'en' ? 'ar' : 'en') . '&currpage=' . $currpage; ?>">
												<span class="lang-name uppercase"><?php echo $lang == 'ar' ? 'en' : 'ar' ?></span>
											</a>
										</div>

									</div>
								</div>
							</nav>
						</div>
						<div class="row">
							<nav class="navbar nav2">
								<div>
									<ul class="nav navbar-nav nav-pills">
										<?php
										$main_menu = Menu::model()->findByAttributes(array('title' => 'main'));
										if ($main_menu != null) {
											$sub_menu = "";

											$i = 0;
											$current_location = str_replace(Yii::app()->getBaseUrl(), '', Yii::app()->request->url);
											foreach ($main_menu->menuItemsFirstLevel as $item) {
												$bgStyle = ' <link rel="stylesheet" href="' . Yii::app()->request->baseUrl . '/site/styleMenu?id=' . $item->id . '';
												$headStyle = ' <link rel="stylesheet" href="' . Yii::app()->request->baseUrl . '/site/styleMenu?id=' . $item->id . '';

												$col2 = '<div class="col-sm-3-menu col-sm-3">';
												$col3 = ' </div><div class="col-sm-4-menu col-sm-3">
													<button onclick="finance()"  class="btn btn-calculate-1" type="button" name="calculate1">' . ($lang == "ar" ? "احتساب التمويل" : "Financial calculator") . '</button><br/>
													<button onclick="earnings()" class="btn btn-calculate-1" type="button" name="calculate1">' . ($lang == "ar" ? "احتساب الأرباح" : "Profits calculator") . '</button> 
														
													</div>';
												$i++;
												$style_script .= '
													#header .nav2 .nav-pills > li.menu' . $i . ' > a.style{
														/*background-color: #f7f7f7 !important;*/
														background-color: transparent !important;
													}
												';
												echo '<li class="menu' . $i . '" ><a data-toggle="pill" id="main-item-' . $item->id . '" class="newhover" href="' . ((substr($item->link, 0, 4) === "http") ? $item->link : ('#menu' . $item->id)) . '" > ' . ($lang == 'en' ? $item->en_title : $item->title) . '  </a></li><li><span class="line-menu">|</span></li> ';

												$sub = $item->menuItems;
												if (sizeof($sub) > 0) {
													$sub_menu .= ' <div id="menu' . $item->id . '" class="tab-pane fade expanded-menu">';
													//background section

													if ($item->image != NULL) {
														$sub_menu .= ' <div class="col-sm-1-menu col-sm-3" style="background-image: url(' . Yii::app()->request->baseUrl . '/uploads/MenuItem/' . $item->image . ');">';
													} else {
														$sub_menu .= ' <div class="col-sm-1-menu col-sm-3 back-menu-1-image">';
													}
													$sub_menu .= ' <div class="col-sm-1-layer" style="' . $headStyle . '"> </div></div>';

													//first level menu
													$sub_menu .= '  <div class="col-sm-2-menu col-sm-3" style="' . $headStyle . '">';
													$sub_menu .= ' <ul class="list-menu-style">';
													foreach ($sub as $sub_item) {
														$third_item = $sub_item->menuItems;
														$plus = (sizeof($third_item)) ? '<div class="col-sm-1 expanded-menu-link"> + </div>' : '';
														$sub_class = sizeof($third_item) > 0 ? 'class="list-style"  data-toggle="collapse" data-target="#sub-menu' . $item->id . '-menu' . $sub_item->id . '"' : 'class="list-style"';
														$link = ($sub_item->link == "#" || $sub_item->link == "") ? "#" : ((substr($sub_item->link, 0, 4) === "http") ? $sub_item->link : Yii::app()->request->baseUrl . $sub_item->link);
														$sub_menu .= ' <li ' . $sub_class . '><a href="' . $link . '" data-parent="main-item-' . $item->id . '" data-url="' . $sub_item->link . '" class="expanded-menu-link">
					   										<div class="col-sm-1 pb5"><div class="row"><span class="menu-icon center-block"></span></div></div><div class="col-sm-9"><div class="row expanded-menu-link">' . ($lang == 'en' ? $sub_item->en_title : $sub_item->title) . '</div></div>' . $plus . '</a></li>';
														if ($current_location == $sub_item->link)
															echo '<script  type="application/javascript" src="' . Yii::app()->request->baseUrl . '/site/scriptMenu?id=' . $item->id . '"></script>';
														//second level

														if (sizeof($third_item) > 0) {
															$col2 .= ' <ul id="sub-menu' . $item->id . '-menu' . $sub_item->id . '" class="collapse">';
															foreach ($third_item as $third_menu_item) {
																$class = sizeof($third_menu_item->menuItems) > 0 ? ' class="dropdown-toggle" data-toggle="dropdown"' : '';
																if ($current_location == $third_menu_item->link)
																	echo '<script  type="application/javascript" src="' . Yii::app()->request->baseUrl . '/site/scriptMenu?id=' . $item->id . '"></script>';
																$col2 .= '<li class="list-style"><a data-parent="main-item-' . $item->id . '" data-url="' . $third_menu_item->link . '" href="' . ((substr($third_menu_item->link, 0, 4) === "http") ? $third_menu_item->link : (Yii::app()->request->baseUrl . $third_menu_item->link)) . '"' . $class . '><div class="col-sm-1"><div class="row"><span class="black-color glyphicon glyphicon-triangle-' . (Yii::app()->getLanguage() == 'ar' ? 'left' : 'right') . '"></span></div></div><div class="col-sm-9"><div class="row expanded-menu-link"> ' . ($lang == 'en' ? $third_menu_item->en_title : $third_menu_item->title) . ' </div></div></a>';
																if (sizeof($third_menu_item->menuItems)) {
																	$col2 .= '<div class="dropdown-menu">';
																	foreach ($third_menu_item->menuItems as $last_level_menu)
																		$col2 .= '  <a  data-parent="main-item-' . $item->id . '" data-url="' . $last_level_menu->link . '"  href="' . ((substr($last_level_menu->link, 0, 4) === "http") ? $last_level_menu->link : (Yii::app()->request->baseUrl . $last_level_menu->link)) . '" class="dropdown-item0 expanded-menu-link">' . ($lang == 'en' ? $last_level_menu->en_title : $last_level_menu->title) . '</a> ';
																	$col2 .= '</div>';
																	if ($current_location == $last_level_menu->link)
																		echo '<script  type="application/javascript" src="' . Yii::app()->request->baseUrl . '/site/scriptMenu?id=' . $item->id . '"></script>';
																}
																$col2 .= '</li>';
															}
															$col2 .= '</ul>';
														}
													}
													$sub_menu .= '</ul></div>';
													$sub_menu .= $col2;
													$sub_menu .= $col3;
													$sub_menu .= '</div>';
												}
											}
										}
										?>

									</ul>
								</div>
							</nav>
						</div>
						</div>
					</div>
			</div>
			<!-- sub menus-->
			<!-- End Of Menus-->

			<div class="container-fluid hidden-xs">
				<div class="row">
					<div class="container-fluid">
						<div class="row">
							<div class="col-xs-12">
								<div class="row">
									<div class="tab-content">
										<?= $sub_menu; ?>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="container">
				<div class="row ">
					<div class="col-xs-12 hidden-xs ">
						<div class="line">
							<img class="img-responsive center-block" src="<?php echo Yii::app()->request->baseUrl ?>/images/line.png" alt="nav-under-line">
						</div>
					</div>
				</div>
			</div>
			<!--End Of Header-->

			<?php
			Yii::app()->clientScript->registerCss('mycss', $style_script);
			if(Yii::app()->controller->id == 'site' && Yii::app()->controller->action->id == 'index'){
				Yii::app()->clientScript->registerScript('menu-scroll', '
					$(window).scroll(function(){
						if($(document).scrollTop() == 0){
							$("#header").removeClass("white-header").addClass("transparent-header");
							$("#header").find("a").css("color", "white");
							$("#header").find(".line-menu").css("color", "white");
						}
						else{
							$("#header").removeClass("transparent-header").addClass("white-header");
							$("#header").find("a").css("color", "black");
							$("#header").find(".line-menu").css("color", "black");
							$(".mobile_menu li a").css("color", "black");
						}
					});

					$(window).trigger("scroll");

					$("ul.list-menu-style li[data-toggle=\'collapse\']").click(function(e){
						e.preventDefault();
					});

					// $(".nav-pills li").click(function(){
						
					// });
				');
			}
			?>