<?php
/**
 * @package Sj Latest Jobs For Js Jobs
 * @version 1.0.0
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @copyright (c) 2015 YouTech Company. All Rights Reserved.
 * @author YouTech Company http://www.smartaddons.com
 *
 */

defined('_JEXEC') or die;

echo '<div class="sj_newest_jobs_show_future_jobs_info">';
	echo '<div class="sj_newest_jobs_show_future_jobs_info_title">'.$params->get('sj_newest_jobs_label_newest').'</div>';
	echo '<div class="sj_newest_jobs_show_future_jobs_info_descreption">'.$params->get('sj_newest_jobs_des_newest').'</div>';
echo '</div>';

echo '<div class="sj_newest_jobs_show_future_jobs_content">';
	
		
			echo '<div class="sj_newest_jobs_show_future_jobs_slide_logo">';
				echo '<div class="owl-demo owl-carousel owl-theme">';
					foreach($nItems as $item){	
						if($item->logo == ''){
							$logo = '<img src="'.JURI::root().'components/com_jsjobs/images/blank_logo.png" alt/>';
						}else{
							$logo = '<img src="'.JURI::root().'jsjobsdata/data/employer/comp_'.$item->companyid.'/logo/'.$item->logo.'" alt/>';
						}
						echo '<div class="item">'.$logo.'</div>';
					}
				echo '</div>';
			echo '</div>';
		
		echo '<div class="sj_newest_jobs_future_wrap_content">';
		foreach($nItems as $item){
			echo '<div class="sj_newest_jobs_future_item">';
				if($params->get('sj_newest_jobs_newest_show_department') == 1){
					echo '<div class="sj_newest_jobs_future_item_title">';
						$url = JURI::root();
						$array_url = explode('/index.php',$url);
						echo '<p><a href="'.$array_url[0].'index.php/component/jsjobs/job/viewjob/job-'.$item->alias.'-'.$item->id.'">'.$item->title.'</a></p>';
					echo '</div>';
				}
				if($params->get('sj_newest_jobs_newest_show_city') != 0 || $params->get('sj_newest_jobs_newest_show_type') != 0){
					echo '<div class="sj_newest_jobs_newest_wrap">';
						if($params->get('sj_newest_jobs_newest_show_city') == 1){
							echo '<div class="sj_newest_jobs_future_item_city sj_left">';
							echo '<p><i class="fa fa-map-marker"></i>';
							foreach($Cityname as $city) {
								if($city->city_id == $item->city){
									echo $city->cityN . " ";
								}
							}
							echo '</p>';
							echo '</div>';
						}
						if($params->get('sj_newest_jobs_newest_show_type') == 1){
							echo '<div class="sj_newest_jobs_future_item_type sj_left">';
								echo '<p><i class="fa fa-adjust"></i>'.$item->jobtypetitle.'</p>';
							echo '</div>';
						}
						
						if($params->get('sj_newest_jobs_newest_show_category') == 1){
							echo '<div class="sj_newest_jobs_item sj_left">';
								echo '<div class="sj_newest_jobs_show_newest_jobs_content_item_show_category sj_newest_jobs_show_category">';
									$url = JURI::getInstance();
									$array_url = explode('/index.php',$url);
									echo '<p>'.$item->cat_title.'</p>';
								echo '</div>';
							echo '</div>';
						}
						
						
						if($params->get('sj_newest_jobs_newest_show_created') == 1){
							echo '<div class="sj_newest_jobs_item sj_newest_jobs_newest_show_created sj_left">';
								echo '<div class="sj_newest_jobs_show_newest_jobs_content_item_show_created">';
									$pub = $item->startpublishing;
									$array_pub = explode(' ',$pub);
									echo '<p><i class="fa fa-calendar"></i>'.$array_pub[0].'</p>';
								echo '</div>';
							echo '</div>';
						}
						
					echo '</div>';
				}
				if($params->get('sj_newest_jobs_newest_show_content') == 1){
					echo '<div class="sj_newest_jobs_future_item_description ">';
						$description = str_replace('</p>','',$item->description);
						$description = str_replace('<p>','',$description);
						if(strlen($description) <= $params->get('sj_newest_jobs_newest_limit_content')){
							echo '<p>'.$description.'</p>';
						}else{
							echo '<p>'.JHtmlString::truncate($description,$params->get('sj_newest_jobs_newest_limit_content'),true,false).'</p>';
						}
						
					echo '</div>';
				}
				if($params->get('sj_newest_jobs_newest_show_view_job') == 1){
					echo '<div class="sj_newest_jobs_future_item_read_more">';
						$url = JURI::root();
						$array_url = explode('/index.php',$url);
						echo '<p><a href="'.$array_url[0].'index.php/component/jsjobs/job/viewjob/job-'.$item->alias.'-'.$item->id.'">'.$params->get('sj_newest_jobs_newest_readmore_text').'</a></p>';
					echo '</div>';
				}
			echo '</div>';
		}
		echo '</div>';
echo '</div>';

?>

<script>
    jQuery(document).ready(function ($) {
      var time = 5;
      var $progressBar,
          $bar, 
          $elem, 
          isPause, 
          tick,
          percentTime;

        $("#sj_wrap_newest_jobs_<?php echo $module->id;?> .owl-carousel").owlCarousel({
          slideSpeed : 1000,
          paginationSpeed : 500,
          singleItem : true,
          afterInit : progressBar,
          afterMove : moved,
          startDragging : pauseOnDragging
        });


        function progressBar(elem){
          $elem = elem;
          buildProgressBar();
		  i = -1;
          start();
        }


        function buildProgressBar(){
          $progressBar = $("<div>",{
            class:"progressBar"
          });
          $bar = $("<div>",{
            class:"bar"
          });
          $progressBar.append($bar).prependTo($elem);
        }
		var i;
        function start() {
			if(i == (parseInt($('#sj_wrap_newest_jobs_<?php echo $module->id;?> .sj_newest_jobs_show_future_jobs .sj_newest_jobs_future_item').length)-1)){i=0;}else{i = i + 1;}
			$('#sj_wrap_newest_jobs_<?php echo $module->id;?> .sj_newest_jobs_show_future_jobs .sj_newest_jobs_future_item').css('display','none');
			$('#sj_wrap_newest_jobs_<?php echo $module->id;?> .sj_newest_jobs_show_future_jobs .sj_newest_jobs_future_item').css('opacity','0');
			$('#sj_wrap_newest_jobs_<?php echo $module->id;?> .sj_newest_jobs_show_future_jobs .sj_newest_jobs_future_item').eq(i).css('display','block');
			$('#sj_wrap_newest_jobs_<?php echo $module->id;?> .sj_newest_jobs_show_future_jobs .sj_newest_jobs_future_item').eq(i).animate({opacity: "1"});
			percentTime = 0;
			isPause = true;
		  
			tick = setInterval(interval, 10);
        };

        function interval() {
          if(isPause === false){
            percentTime += 1 / time;
            $bar.css({
               width: percentTime+"%"
             });
            if(percentTime >= 100){ 
              $elem.trigger('owl.next')
            }
          }
        }
		

        function pauseOnDragging(){
          isPause = true;
        }
		
        function moved(){
          clearTimeout(tick);
          start();
        };
		<?php if($params->get('pause_hover',1) == 1){?>
		$elem.on('mouseover',function(){
           isPause = true;
         });
         $elem.on('mouseout',function(){
           isPause = false;
         });
		
		<?php }?>
		
    });
    </script>
	
