<?php

class NavTabView extends Slot {

	var $ModuleID = 1;
	var $SectionID = 2;
	var $module = 1;
	var $item = 1;
	var $menu = array();

	function __construct($pquery) {
		parent::__construct($pquery);
	}

	function init() {
		//print '<li> NavTabView<br>';
		$this->getModule();
		$this->Action->processEvent($this->SectionID,'open',array('id' => $this->module),$this);
		if(!empty($this->PreparedTemplates['_error'])) header('Location: '.$this->Home.$this->SID);
		if(!$this->PreparedTemplates['is_describe']) header('Location: '.$this->Home.$this->SID);
		$this->city_default = 0;
		if($this->PreparedTemplates['type']['id']==9) {
			if(!empty($this->LocalTarget[1])) {
				$this->Action->processEvent($this->SectionID,'city',array('name' => $this->LocalTarget[1]),$this);
				if(empty($this->PreparedTemplates)) $this->city_default = 1;
			}
			else $this->city_default = 1;
		}
		if($this->city_default) {
			$this->Action->processEvent($this->SectionID,'get_menu',array('id' => 39),$this);
		}
		else {
			$this->Action->processEvent($this->SectionID,'open_menu',array('module' => $this->module,'type' => 7),$this);
		}
		$this->setSchemeTemplate($this->Scheme);
	}

	function fillElements() {
		if(!$this->city_default) $this->PreparedTemplates = $this->Action->getTemplate($this->SectionID,'open_menu');
		else $this->PreparedTemplates = $this->Action->getTemplate($this->SectionID,'get_menu');
		$array = $this->LocalTarget;
		$this->last_target = array_pop($array);
		$this->setTargetArray($this->PreparedTemplates,0.1);
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID,'open_menu');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID,'get_menu');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID,'open');
	}

	function getModule($id = 0) {
		global $REGISTRY;
		$value = '';
		$path = '';
		if(!empty($this->LocalTarget[$id])) $path = implode('/',$this->LocalTarget);
		if(!empty($REGISTRY['Request']['Search'])) {
			foreach($REGISTRY['Request']['Search'] as $k => $v) {
				if(isset($REGISTRY['VirtualSlotTarget']['main']['/'.$path.'?'.$k.'='.$v])) {
					$value = $REGISTRY['VirtualSlotTarget']['main']['/'.$path.'?'.$k.'='.$v];
				}
			}
		}
		if(empty($value)) {
			foreach($REGISTRY['VirtualSlotTarget']['main'] as $k => $v) {
				if(equals($k,'/'.$path)) $value = $v;
			}
		}
		$query = explode('?',$value);
		$target = explode(':',array_shift($query));
		$properties = array_shift($query);
		$pair = explode('=',$properties);
		$name = array_shift($target);
		$this->module = $pair[1];
	}

	function setTargetArray($array = array(),$level = 1,$subitems = array()) {
		$i = 0;
		foreach($array as $key => $value) {
			$this->TempFillEls['items'][$key] = array(
				'id' => $key,
				'url' => $value['path']=='./'.$this->last_target || $value['path']=='/'.implode('/',$this->LocalTarget) || ($this->city_default && $value['label']=='Availability')? trim($value['label']) : makeLink($value['path'],trim($value['label']),array(),$value['anchor'],($value['target']? 'target="_blank"' : 'target="_top"')),
				'select' => $value['path']=='./'.$this->last_target || $value['path']=='/'.implode('/',$this->LocalTarget) || ($this->city_default && $value['label']=='Availability')? '2' : '',
				'left' => $value['path']=='./'.$this->last_target || $value['path']=='/'.implode('/',$this->LocalTarget) || ($this->city_default && $value['label']=='Availability')? 'navtab/lbg' : '1',
				'right' => $value['path']=='./'.$this->last_target || $value['path']=='/'.implode('/',$this->LocalTarget) || ($this->city_default && $value['label']=='Availability')? 'navtab/rbg' : '1',
				'roll' => $value['path']=='./'.$this->last_target || $value['path']=='/'.implode('/',$this->LocalTarget) || ($this->city_default && $value['label']=='Availability')? array() : array(array('id' => $key)),
				'roll_left' => $value['path']=='./'.$this->last_target || $value['path']=='/'.implode('/',$this->LocalTarget) || ($this->city_default && $value['label']=='Availability')? array() : array(array('id' => $key)),
				'roll_right' => $value['path']=='./'.$this->last_target || $value['path']=='/'.implode('/',$this->LocalTarget) || ($this->city_default && $value['label']=='Availability')? array() : array(array('id' => $key)),
			);
			if(!empty($value['subcat'])) $this->setTargetArray($value['subcat'],$level+1);
			$i++;
		}
	}

}
?>