<?php  
class ControllerModuleElegantAccordion extends Controller {
	protected function index($setting) {
		static $module = 0;
	
		$this->language->load('module/elegant_accordion');
		$this->load->model('tool/image');
		
		$this->document->addScript('catalog/view/javascript/jquery/jquery.kwicks-1.5.1.js');
		$this->document->addStyle('catalog/view/theme/' .  $this->config->get('config_template') . '/stylesheet/elegant_accordion.css');
		
		$this->data['text_more']        = $this->language->get('text_more');
		$this->data['accordion_width']  = $setting['accordion_width'];
		$this->data['accordion_height'] = $setting['accordion_height'];
		$this->data['image_width']      = $setting['image_width'];
		$this->data['image_height']     = $setting['image_height'];
		$number_sections = count($setting['sections']);
		
		$this->data['partial_view'] = (int)(($setting['accordion_width'] / $number_sections ) - 2);
		
		$description_height = (int)($setting['image_height'] / 3);
		
		if ($description_height < 130){
			$description_height = 130;
		}
		
		if ($description_height > 175){
			$description_height = 175;
		}
		
		$h2_font_size = 30;
		
		if ($setting['image_width'] < 300){
			$h2_font_size = (int) ($setting['image_width'] / 10);
		}
		
		$this->data['description_height'] = $description_height;	
		$this->data['description_bg_height'] = (int) ($description_height * 2);	
		$this->data['h2_font_size'] = $h2_font_size;	
		
		$this->data['sections'] = array();
		
		$section_row = 0;
		
		foreach($setting['sections'] as $section){
			if (isset($section['title'][$this->config->get('config_language_id')])){
				$title = html_entity_decode($section['title'][$this->config->get('config_language_id')], ENT_QUOTES, 'UTF-8');
			} else {
				$title = false;
			}
			
			if (isset($section['description'][$this->config->get('config_language_id')])){
				$description = mb_substr(strip_tags(html_entity_decode($section['description'][$this->config->get('config_language_id')], ENT_QUOTES, 'UTF-8')), 0, 100) . '...';
			} else {
				$description = false;
			}

			$this->data['sections'][] = array(
				'id'          => 'slide-' . $module . '-' . $section_row,
				'link'        => $section['link'],
				'title'       => $title,
				'description' => $description,
				'image'       => $this->model_tool_image->resize($section['image'], $setting['image_width'], $setting['image_height'])
			);
			
		}

		$this->data['module'] = $module++;
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/elegant_accordion.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/module/elegant_accordion.tpl';
		} else {
			$this->template = 'default/template/module/elegant_accordion.tpl';
		}
		
		$this->render();
	}
}
?>