<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Description of ciext
 *
 * @author Igor Ratsun
 */
class Ciext {

    private $CI;

    function __construct() {
        $this->CI = & get_instance();
    }

    private $js_css_links = array();

    /**
     * Load jQuery
     * @return boolean
     */
    public function load_jquery() {
        $this->CI->js_css->add_js($this->js_link_jquery());

        return TRUE;
    }

    /**
     * Load jQuery UI
     * @return boolean
     */
    public function load_jquery_ui() {
        $this->load_jquery();
        $this->CI->js_css->add_css($this->css_link_jquery_ui());
        $this->CI->js_css->add_js($this->js_link_jquery_ui());

        return TRUE;
    }

    /**
     * Load Twitte bootstrap
     * @return boolean
     */
    public function load_bootstrap() {
        $this->load_jquery();
        $this->CI->js_css->add_css($this->css_link_twitter_bootstrap());
        $this->CI->js_css->add_js($this->js_link_twitter_bootstrap());

        return TRUE;
    }

    /**
     * Add slashes to string
     * @param string $str
     * @param string $type - left, right, both
     * @return string
     */
    public function add_slash($str, $type = 'left') {
        $new_str = '';
        switch ($type) {
            case 'right':
                $new_str = ($str[strlen($str) - 1] != '/') ? $str . '/' : $str;
                break;
            case 'both':
                $new_str = $this->add_slash($this->add_slash($str, 'right'));
                break;

            default:
                $new_str = ($str[0] != '/') ? '/' . $str : $str;
                break;
        }

        return $new_str;
    }

    /**
     * Get jquery link
     * @return string 
     */
    public function js_link_jquery() {
        if (!isset($this->js_css_links['js_link_jquery'])) {
            $this->js_css_links['js_link_jquery'] = $this->CI->config->item('js_jquery');
        }
        
        return $this->js_css_links['js_link_jquery'];
    }

    /**
     * Get jquery-ui javascript link
     * @return string 
     */
    public function js_link_jquery_ui() {
        if (!isset($this->js_css_links['js_link_jquery_ui'])) {
            $this->js_css_links['js_link_jquery_ui'] = $this->CI->config->item('js_jquery_ui');
        }
        
        return $this->js_css_links['js_link_jquery_ui'];
    }

    /**
     * Get jquery-ui css link
     * @return string 
     */
    public function css_link_jquery_ui() {
        if (!isset($this->js_css_links['css_link_jquery_ui'])) {
            $this->js_css_links['css_link_jquery_ui'] = $this->CI->config->item('css_jquery_ui');
        }
        
        return $this->js_css_links['css_link_jquery_ui'];
    }

    /**
     * Get twitter bootstrap javascript link
     * @return string 
     */
    public function js_link_twitter_bootstrap() {
        if (!isset($this->js_css_links['js_link_twitter_bootstrap'])) {
            $this->js_css_links['js_link_twitter_bootstrap'] = $this->CI->config->item('js_twitter_bootstrap');
        }

        return $this->js_css_links['js_link_twitter_bootstrap'];
    }

    /**
     * Get twitter bootstrap css link
     * @return string 
     */
    public function css_link_twitter_bootstrap() {
        if (!isset($this->js_css_links['css_link_twitter_bootstrap'])) {
            $this->js_css_links['css_link_twitter_bootstrap'] = $this->CI->config->item('css_twitter_bootstrap');
        }

        return $this->js_css_links['css_link_twitter_bootstrap'];
    }

}