<?php
/* Droconut SLIDERS v1.3; Droconut - Dropping Coconut KG
http://www.droconut.com 
Support: office@droconut.com

Copyright 2012, Attila Santo (Dropping Coconut KG) */

class ControllerModuleSliders extends Controller {
	protected function index($setting) {
		static $module = 0;

		$this->load->model('design/banner');
		$this->load->model('tool/image');

		if($setting['type'] == 'NIVO') {
		$this->document->addScript('catalog/view/javascript/jquery/nivo-slider/jquery.nivo.slider.pack.js');
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/stylesheet/nivo_styles.css')) {
			$this->document->addStyle('catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/nivo_styles.css');} else {
			$this->document->addStyle('catalog/view/theme/default/stylesheet/nivo_styles.css');}
		}

		if($setting['type'] == 'BX') {
		$this->document->addScript('catalog/view/javascript/jquery/jquery.easing.1.3.js');
		$this->document->addScript('catalog/view/javascript/jquery/bx-slider/jquery.bxSlider.min.js');
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/stylesheet/bx_styles.css')) {
			$this->document->addStyle('catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/bx_styles.css');} else {
			$this->document->addStyle('catalog/view/theme/default/stylesheet/bx_styles.css');}
		}

		if($setting['type'] == 'DIAPO') {
		$this->document->addScript('catalog/view/javascript/jquery/jquery.easing.1.3.js');
		$this->document->addScript('catalog/view/javascript/jquery/jquery.hoverIntent.minified.js');
		$this->document->addScript('catalog/view/javascript/jquery/diapo-slider/jquery.diapo.slider.min.js');
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/stylesheet/diapo_styles.css')) {
			$this->document->addStyle('catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/diapo_styles.css');} else {
			$this->document->addStyle('catalog/view/theme/default/stylesheet/diapo_styles.css');}
		}

		$this->data['width'] = $setting['width'];
		$this->data['height'] = $setting['height'];
		//$this->data['thumb_width'] = $setting['thumb_width'];
		//$this->data['thumb_height'] = $setting['thumb_height'];
		//$this->data['resize'] = $setting['resize'];

		$this->data['preferences'] = array();
		$this->data['preferences'] = $setting['preferences'];

		$this->data['banners'] = array();

		$results = $this->model_design_banner->getBanner($setting['banner_id']);

		foreach ($results as $result) {

			list($width, $height) = getimagesize(HTTP_SERVER . 'image/' . $result['image']);

			if (file_exists(DIR_IMAGE . $result['image'])) {

				switch ($setting['resize']) {
				case "crop":
					$this->data['banners'][] = array(
						'title'			=> $result['title'],
						'link'			=> $result['link'],
						'caption'		=> html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'),
						'thumb'			=> $this->model_tool_image->resizeThumb($result['image'], 50, 50),
						'image'			=> $this->model_tool_image->resizeThumb($result['image'], $setting['width'], $setting['height']),
						'width_orig'	=> $width,
						'height_orig'	=> $height
					);
					break;
				case "box":
					$this->data['banners'][] = array(
						'title'			=> $result['title'],
						'link'			=> $result['link'],
						'caption'		=> html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'),
						'thumb'			=> $this->model_tool_image->resizeThumb($result['image'], 50, 50),
						'image'			=> $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height']),
						'width_orig'	=> $width,
						'height_orig'	=> $height
					);
					break;
				default:
					$this->data['banners'][] = array(
						'title'			=> $result['title'],
						'link'			=> $result['link'],
						'caption'		=> html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'),
						'thumb'			=> $this->model_tool_image->resizeThumb($result['image'], 50, 50),
						'image'			=> "/image/".$result['image'],
						'width_orig'	=> $width,
						'height_orig'	=> $height
					);
					break;
				};

			}
		}


		$this->data['module'] = $module++;

		if($setting['type'] == 'NIVO') {
			if(isset($setting['preferences']['controlNavThumbsFromRel']) && ($setting['preferences']['controlNavThumbsFromRel'] == 'true')) {$this->data['thumb'] = true;} 
			else {$this->data['thumb'] = false;};
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/nivo_sliders.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/module/nivo_sliders.tpl';
			} else {
				$this->template = 'default/template/module/nivo_sliders.tpl';
			}
		}

		if($setting['type'] == 'BX') {
			if(isset($setting['slideWidth'])) {$this->data['slideWidth'] = $setting['slideWidth'];};
			if(isset($setting['slideCSSImg'])) {$this->data['slideCSSImg'] = $setting['slideCSSImg'];};
			if(isset($setting['slideCSSTxt'])) {$this->data['slideCSSTxt'] = $setting['slideCSSTxt'];};
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/bx_sliders.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/module/bx_sliders.tpl';
			} else {
				$this->template = 'default/template/module/bx_sliders.tpl';
			}
		}

		if($setting['type'] == 'DIAPO') {
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/diapo_sliders.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/module/diapo_sliders.tpl';
			} else {
				$this->template = 'default/template/module/diapo_sliders.tpl';
			}
		}

		$this->render();
	}
}
?>