<?php defined('_JEXEC') or die;
/*
 * @package     mod_uk_skills
 * @copyright   Copyright (C) Joomlaplates. All rights reserved.
 * @license     GNU General Public License version 3 or later; see http://www.gnu.org/licenses/gpl-3.0.txt
 */
#$document = JFactory::getDocument();
#$modulePath = JURI::base() . 'modules/mod_uk_counter/';
#$document->addStyleSheet($modulePath.'css/mod_uk_counter.css');
#$document->addScript($modulePath.'js/jquery.waypoints.js');
#$document->addScript($modulePath.'js/jquery.counterup.js');

$content_before_class       = $params->get('content_before_class');
$content_before    = $params->get('content_before');
$count_icon     		= $params->get('count_icon');
$count_icon_size     		= $params->get('count_icon_size');
$count_icon_color     		= $params->get('count_icon_color');
$count_number     		= $params->get('count_number');
$count_number_color     		= $params->get('count_number_color');
$count_number_size     		= $params->get('count_number_size');
$content_bg     		= $params->get('content_bg');





?>
</style>
<?php if ($content_before) { ?>
<div class="<?php echo $content_before_class; ?>">
<?php echo $content_before; ?>
</div>
<?php } ?>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/waypoints/4.0.1/jquery.waypoints.min.js"></script>
<script type="text/javascript">
(function( $ ){
  "use strict";

  $.fn.counterUp = function( options ) {

    // Defaults
    var settings = $.extend({
        'time': 400,
        'delay': 10
    }, options);

    return this.each(function(){

        // Store the object
        var $this = $(this);
        var $settings = settings;

        var counterUpper = function() {
            var nums = [];
            var divisions = $settings.time / $settings.delay;
            var num = $this.text();
            var isComma = /[0-9]+,[0-9]+/.test(num);
            num = num.replace(/,/g, '');
            var isInt = /^[0-9]+$/.test(num);
            var isFloat = /^[0-9]+\.[0-9]+$/.test(num);
            var decimalPlaces = isFloat ? (num.split('.')[1] || []).length : 0;

            // Generate list of incremental numbers to display
            for (var i = divisions; i >= 1; i--) {

                // Preserve as int if input was int
                var newNum = parseInt(num / divisions * i);

                // Preserve float if input was float
                if (isFloat) {
                    newNum = parseFloat(num / divisions * i).toFixed(decimalPlaces);
                }

                // Preserve commas if input had commas
                if (isComma) {
                    while (/(\d+)(\d{3})/.test(newNum.toString())) {
                        newNum = newNum.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2');
                    }
                }

                nums.unshift(newNum);
            }

            $this.data('counterup-nums', nums);
            $this.text('0');

            // Updates the number until we're done
            var f = function() {
                $this.text($this.data('counterup-nums').shift());
                if ($this.data('counterup-nums').length) {
                    setTimeout($this.data('counterup-func'), $settings.delay);
                } else {
                    delete $this.data('counterup-nums');
                    $this.data('counterup-nums', null);
                    $this.data('counterup-func', null);
                }
            };
            $this.data('counterup-func', f);

            // Start the count up
            setTimeout($this.data('counterup-func'), $settings.delay);
        };

        // Perform counts when the element gets into view
        $this.waypoint(counterUpper, { offset: '100%', triggerOnce: true });
    });

  };

})( jQuery );
</script>

<?php if ($content_before) { ?>
<div class="<?php echo $content_before_class; ?>">
<?php echo $content_before; ?>
</div>
<?php } ?>
<div uk-slider<?php echo $sw_params; ?>>
    <div class="uk-position-relative uk-visible-toggle">
        <ul class="uk-grid-match uk-slider-items <?php echo $classes; ?>" uk-grid >
            <?php
            foreach ($items as $item) {?>
            <li>
				<div style="background:<?php echo $item->content_bg; ?>" class="p-3 <?php echo $item_style; ?> <?php echo $center; ?>">
					<?php if ($item->count_icon) { ?><p style="font-size:<?php echo $item->count_icon_size; ?>;color:<?php echo $item->count_icon_color; ?>" class="pb-2 <?php echo $item->count_icon; ?>"></p><?php } ?>
					<p style="font-size:<?php echo $item->count_number_size; ?>;color:<?php echo $item->count_number_color; ?>"class="pb-2 statistic-counter"><?php echo $item->count_number; ?></p>
					<?php if ($item->content) { ?><div class=""><?php echo $item->content; ?></div><?php } ?>
				</div>
            </li>
            <?php } ?>
        </ul>
		<?php if ($slidenav) { ?>
		<a class="uk-position-center-left uk-position-small uk-hidden-hover" href="#" uk-slidenav-previous uk-slider-item="previous"></a>
        <a class="uk-position-center-right uk-position-small uk-hidden-hover" href="#" uk-slidenav-next uk-slider-item="next"></a>    <?php } ?>

    </div>
    
    
    <?php if ($dotnav) { ?>
    <div class="uk-flex uk-flex-center uk-margin-small-top">
        <ul class="uk-slider-nav uk-dotnav"></ul>
    </div>
    <?php } ?>
    
</div>
<script type="text/javascript">
  // Counter 
            jQuery('.statistic-counter').counterUp({
                delay: 10,
                time: 1000
            });	
</script>

