// CUSTOM SCRIPTS


///////////////REMOOVE THUMB DIMENSIONS/////////////

jQuery(document).ready(function ($) {
    jQuery('img, svg, table').removeAttr('width').removeAttr('height');
	jQuery('table').css('width', '');
	jQuery('table').css('height', '')
});

/*************TABLES***********/
jQuery(document).ready(function($) {
	jQuery('.entry table').wrap( "<div class='table-wrap'></div>" );
	
	});
	
//////////////smooth scroll top /////////

jQuery(document).ready(function($) {
  var eventtype = 'click';
  $('.gotop').on(eventtype, function (e) {
    e.preventDefault();
    $("html, body").animate({
      scrollTop: 0
      }, 1500);
  });
 });
 


 ///////////////goback//////////////
 jQuery(document).ready(function(){
	jQuery('a.back').click(function(){
		parent.history.back();
		return false;
	});
});

////////////////////////SMOOTH SCROLL TO ANCHOR///////////////
jQuery(document).ready(function($){
	jQuery('a.smooth').on('click',function (e) {
	    e.preventDefault();

	    var target = this.hash;
	    var $target = $(target);

	    jQuery('html, body').stop().animate({
	        'scrollTop': $target.offset().top
	    }, 900, 'swing', function () {
	        window.location.hash = target;
	    });
		
		////////////////Stop Anchor Being Included In URL//////////////
		jQuery('html, body').stop().animate({
     'scrollTop': $target.offset().top
}, 900, 'swing');
});
});

 

/*****************match height*********************/ 
 jQuery(function() {
    jQuery('.mht').matchHeight(
	{
    byRow: true,
    property: 'height',
    target: null,
    remove: false
}
	);
	
		
	
});


/**********************CALCULATIONS**************/
/*
 jQuery(document).ready(function($) {
	var videoh = jQuery('.vimg').height();
	
	jQuery('.video-img').css('height', videoh - 100  + 'px');
	
	jQuery('.c-row:nth-child(even)').addClass('chet');
	jQuery('.c-row:nth-child(odd)').addClass('nechet')
	
	//////////landing////////////
	if(jQuery(window).width() > 1041) {
	var land_2 = jQuery('.landing-2 .row').height();
	jQuery('#landing-form').css('height', land_2  + 'px');
	}
	
	});//End Ready	

*/


///////////////split by separator | /////////////////////
 jQuery(document).ready(function($) {

$.fn.chunkify = function( options ) {

		$.fn.chunkify.settings = {
        	//separator: /\s/,
			separator: /\|/,
        	wrapper: 'span',
        	klass: 'chunk'
        };
        
        options = $.extend( $.fn.chunkify.settings, options );

		return this.each(function() {
			
			var $element = $( this );
		    var num = 0;
		    var text = $element.text();
		    
		    
		    var parts = text.split( options.separator );
		    var html = "";
		    
		    for( var i = 0; i < parts.length; ++i ) {
		    
		        num++;
		        
		        var part = parts[i];
		        
		        html += "<" + options.wrapper + " class='" + options.klass + num + "'>" + part + "</" + options.wrapper + "> ";
				
		    
		    
		    }
		    
		    $element.html( html );
		
		}); 
	
	
   };
	
});

jQuery(function() {
  jQuery( ".split" ).chunkify();
  
});

		
/********************TABS*****************/
 jQuery(document).ready(function ($) {
          $('.tabs').responsiveTabs({
    	startCollapsed: 'false',
		event: 'click',
		animation: 'slide',
		navigationContainer: '#cat-tabs',
		setHash: false 
});

 });

/////////////////STICKY SIDEBAR///////////////////////////
 /*jQuery(document).ready(function() {
    jQuery('.sticky-sidebar').theiaStickySidebar({
      // Settings
      additionalMarginTop: 60
    });
  });
  */
  
  /************MAKE ME CENTER *************/
  /*
 jQuery(document).ready(function ($) {
   
  jQuery(".mkcenter").makemecenter({

// CSS position
position : "absolute",
horizontal : true,
vertical : true,
parentRelative : '.video-img' ,	

   });
      });

 
/////////////////TOOLTIP///////////////////
jQuery(document).ready(function () {

  jQuery('.mtooltip').tooltip({
  	// container: 'body'
});

});

*/
/////////////ACCORDION/////////
   
 jQuery(document).ready(function ($) {
	jQuery('.beefup').beefup({
   // openSingle: false,
   // stayOpen: 0,
	trigger: '.readmore, .beefup__head, .morebtn, .morebtn.less', 
		
});
	jQuery('.beefup-2').beefup({
   // openSingle: false,
   // stayOpen: 0,
	trigger: '.readmore, .beefup_title',
		
});

}); 
 

	
 
//////////////////filter open///////////
jQuery(document).ready(function($) {
	$(".filter-open").on('click', function(event) {
		event.preventDefault();
		$("#filter-panel").slideDown();
		$(".filter-open").addClass('hide');
		//$("#searchclose").show();
	});

	$(".filter-close").on('click', function(event) {
		event.preventDefault();
		$("#filter-panel").slideUp();
		$(".filter-open").removeClass('hide');
		//$("#searchclose").hide();
	});
		});
		
		
/**********current url************/
jQuery(document).ready(function($) { 
 var cur = window.location.href
		   //console.log(cur)
       jQuery(".enav a").each(function(){
		  
               if (jQuery(this).attr("href") == cur){
                       jQuery(this).addClass("current");
               }
       });
});

 /////////////////enable superfish/////////////////
 jQuery(document).ready(function() {
		jQuery('.smenu ul.children').superfish();
	});
	

 /////////////////menu active class/////////////////
  jQuery(document).ready(function() {	

    var url = window.location.href;
	var pathname = window.location.pathname; 
	
	console.log(url);
	  	
    jQuery(".menu-primary li a").each(function () {
		
		//jQuery(this).addClass('test')
        var href = jQuery(this).attr('href');
		//console.log(href);
       	 if (href == url) {			
			//console.log('YEEES');
            jQuery(this).closest('li').addClass('current-menu-item');
      	 }
    });

});
/////////////////////SPLIT TO COLS//////////////////////
jQuery(function($) {
	if($(window).width() > 1200) {
    var num_cols = 2
	  } else {
	var num_cols = 1
	  }
    container = $('.mega__ .sub-level-1'),
    listItem = 'li',
    listClass = 'sub-list';
    container.each(function() {
        var items_per_col = new Array(),
        items = $(this).find(listItem),
        min_items_per_col = Math.floor(items.length / num_cols),
        difference = items.length - (min_items_per_col * num_cols);
        for (var i = 0; i < num_cols; i++) {
            if (i < difference) {
                items_per_col[i] = min_items_per_col + 1;
            } else {
                items_per_col[i] = min_items_per_col;
            }
        }
        for (var i = 0; i < num_cols; i++) {
            $(this).append($('<ul ></ul>').addClass(listClass));
            for (var j = 0; j < items_per_col[i]; j++) {
                var pointer = 0;
                for (var k = 0; k < i; k++) {
                    pointer += items_per_col[k];
                }
                $(this).find('.' + listClass).last().append(items[j + pointer]);
            }
        }
    });
});

		
		

//////////menu to select ////////////////
jQuery(document).ready(function($) {  
 if ($(window).width() < 820) {
// Create a <select> and append to #menu

var $select = $('<select></select>');
$('.mobileselect').append($select);
// Cycle over menu links
$('.mobileselect a').each(function(){
	var $anchor = $(this);
	
	// Create an option
	var $option = $('<option></option>');

	// Deal with selected options depending on current page
	if($anchor.parent().hasClass('selected')) {
		$option.prop('selected', true);
	}

	// Option's value is the href
	$option.val($anchor.attr('href'));

	// Option's text is the text of link
	$option.text($anchor.text());

	// Append option to <select>
	$select.append($option);

});

$select.change(function(){
	window.location = $select.val();
});
 }
});



/*****************scrollbars*******************/
/*
jQuery(document).ready(function($) {   
jQuery(function() { 
// if (jQuery(window).width() > 420) { 
    jQuery(".nice, .table-wrap").niceScroll({
		cursorcolor: "#dadada",
		// cursorborder: "1px solid #dadada",
		// cursorwidth: "10px",
		 	});
			
// }
});
})
*/

////////////////menu image///////////////////
jQuery(document).ready(function($) {
	jQuery( '.mega' ).each(function( index ) {
	  var imgdiv = jQuery(this).find('.m-img');
	  jQuery(this).find('ul.sub-level-1').append(imgdiv);
	  
	});
	
	/*var parentli = jQuery('.m-img').parent('li').attr(id);
	console.log (parentli);
	//$('#menu-item-1191 ul.sub-level-1').append(imgdiv)
	$('#' +parentli + 'ul.sub-level-1').append(imgdiv)*/



});

/////////////////////MENU ACC///////////////////////

jQuery(document).ready(function($) { 
	if (jQuery(window).width() > 1024) {
		
		jQuery('ul.sub-level-1 li').each(function(){
			var $this = $(this);
			if ($this.index() == $this.siblings().length)  {         
		 	jQuery(this).addClass('last-li');			
			jQuery('ul.sub-level-1 ul li').removeClass('last-li');  
			
        }
	});
			
			
			jQuery('.menu-primary ul li').last().addClass('menu-end');
			
	
			
		//jQuery('.menu-primary li:last-child').addClass('menu-end');  	
		
		jQuery(".menu-primary li a").on('keydown', function(event) { 		
			jQuery(this).next('ul.sub-level-1').addClass('dropdown');
			});

		jQuery(".menu-primary .last-li a").on('keydown', function(event) { 		
			jQuery(this).parents('ul.sub-level-1').removeClass('dropdown');
		
		});
		
			jQuery(".menu-primary .menu-end a").on('keydown', function(event) { 		
			jQuery('ul.sub-level-1').removeClass('dropdown');
		
		});
		
				
		 
	}
	
});
//////////////////SLICK BUTTONS and other alts///////////////

jQuery(document).ready(function($) {
	
	jQuery("button.slick-next").attr("aria-label", "קדימה");
	jQuery("button.slick-prev").attr("aria-label", "אחורה");
	
	jQuery("a.em-calnav-prev").attr("aria-label", "אחורה");
	jQuery("a.em-calnav-next").attr("aria-label", "קדימה");
	
	});

///////////////scroll animate///////////////
jQuery(document).ready(function($) {
	jQuery('.animate').scrolla({
	  animateCssVersion: 3
});
});

////////////////INSERT WEEKDAY CONTAINER//////////////

jQuery(document).ready(function($) {
	/*jQuery('<div class="my-event-container">').insertBefore('dt.simcal-day-label');
	jQuery('</div>').insertAfter('dd.simcal-day');
	*/
	/*jQuery("dt.simcal-day-label + dd.simcal-day").wrapAll('<div id="newDiv" />');*/


 
});
	
