// Wedding Window JavaScript Stuff


document.documentElement.className = 'js-enabled';
//document.getElementsByClassName('html')[0].className = 'js';


// test for include
//alert ('included!');

jQuery(document).ready(function() {
	
	// test for jQuery working
	//alert("Hello world!");
	
	
	// Make Category Columns
	
	// set target group
	var target_group = '#pop-menu #tab-categories .cat-item';
	
	// get total number of categories
	var total_cats = jQuery(target_group).length;
	// define the number of groups you'd like
	var cat_groups = 2;
	// get number of categories to go in each group
	var cats_in_group = Math.ceil( total_cats / cat_groups);
	
	//alert ('groups: ' + total_cats + ' / ' + cat_groups + ' = ' + cats_in_group);
	
	// create array to hold results
   var cat_list = [];
   
   // for each item...
   jQuery(target_group).each(function (i, value) {
	
	// add current item to array
	cat_list.push(value);
	
	// if it's a break point or the last item...
	if (((i + 1) % cats_in_group === 0) || (i === total_cats -1))
	{
		// store array in new variable
		var current_set = jQuery(cat_list);
		
		// reset array to empty
		cat_list = [];
		
		// wrap div around the current group
		current_set.wrapAll(jQuery('<div class="cat-wrap"></div>'));
	 }
   });
   
	
	
	
	
	jQuery('body').addClass('js-enabled');
	
	
	// add class to header widgets for styling
	jQuery('#header-aside ul:eq(0)').addClass('dynamic');
	
	
	
	/*
	jQuery('.widget_openxwpwidget a')
		.not('.widget_openxwpwidget a:eq(0)')
		.css({
			'width': '125px',
			'float': 'left',
			'display': 'block',
			'clear': 'none',
			'padding': '17px 0 0 17px',
			'margin': '0'
		});
		*/
	
	
	
	// add mouse enter / out menu reveal
	/*
	jQuery('#header-aside ul.xoxo li').mouseenter(function(){
		jQuery(this).children('ul').slideDown(0);
		jQuery(this).children('h3').addClass('hover');
	}).mouseleave(function(){
		jQuery(this).children('ul').slideUp(0);
		jQuery(this).children('h3').removeClass('hover');
	});
	
	jQuery('#header-aside ul.xoxo li ul a').mouseenter(function(e){
		e.stopPropigation();
		jQuery(this).parent('ul').slideDown(0);
	}).mouseleave(function(e){
		e.stopPropigation();
		jQuery(this).parent('ul').slideUp(0);
	});
	*/
	
	/*
	var config = {    
     sensitivity: 4, // number = sensitivity threshold (must be 1 or higher)    
     interval: 0, // number = milliseconds for onMouseOver polling interval    
     over: menuOpen, // function = onMouseOver callback (REQUIRED)    
     timeout: 0, // number = milliseconds delay before onMouseOut    
     out: menuClose // function = onMouseOut callback (REQUIRED)    
	};
	
	//$("#demo3 li").hoverIntent( config );
	
	jQuery('#header-aside ul.xoxo li').hoverIntent( config );
	
	function menuOpen(){
		jQuery(this).children('ul').slideDown(0);
		jQuery(this).children('h3').addClass('hover');
	}
	
	function menuClose(){
		jQuery(this).children('ul').slideUp(0);
		jQuery(this).children('h3').removeClass('hover');
	}
	*/

	
	
	/*
	jQuery('#header-aside ul.xoxo li').hover(
      function () {
        jQuery(this).children('h3').addClass('hover');
		jQuery(this).children('ul').fadeIn();
      }, 
      function () {
		jQuery(this).children('h3').removeClass('hover');
        jQuery(this).children('ul').fadeOut();
      }
    );
*/
	
	
	// used for testing to make menu open
	/*
	jQuery('#header-aside ul.xoxo li ul:eq(0)').slideDown();
	jQuery('#header-aside ul.xoxo li h3:eq(0)').addClass('hover');
	*/
	
	
	
	jQuery('.sociable').not('.category-authors .sociable', '.category-mini-bio-only .sociable').each(function(i){
		var mama = '.the_post_comments:eq(' + i + ')';
		jQuery(this).appendTo(jQuery(mama)).not('.category-authors ' + mama, '.category-mini-bio-only ' + mama);
	});
	
	
	
	
	jQuery('.multiwidget_author_avatars .no_users').parent('.multiwidget_author_avatars').css('display', 'none');
	
	
	
	// move category info
	jQuery('.cat-links').each(function(i){
			var mama = '.post:eq(' + i + ')';
			var sister = '.the_post_comments:eq(' + i + ')';
			
			jQuery(mama).children('.entry-utility').addClass('cat-reveal-button').prepend('<span class="cat-links"><a>Filed under</a> |&nbsp;</span>');
				
			jQuery(this).insertBefore(jQuery(sister)).wrap('<div class="cat-reveal"></div>');
			
			jQuery(this).parent('.cat-reveal').slideUp(0);
	});
	
	
		
	//jQuery('.sociable').appendTo( jQuery(this).parent('body') );
	
	
	
	
	// add reveal
	
	jQuery('.cat-reveal-button .cat-links').click(function(){
		jQuery(this).parent('.cat-reveal-button').siblings('.cat-reveal').slideToggle('fast');
	});
	
	
	
	
	
	
	
	jQuery('.widget_openxwpwidget a').not('.widget_openxwpwidget a:eq(0)').addClass('small_ad');
	
	
	jQuery('#header #pop-menu .nav li').fadeIn(3000);
	
	// make clicked pop menu nav show appropriate tab and hide others
	jQuery('#pop-menu .nav li a').removeAttr('href').click(function(event) {
	  
	  // find target
	  var requested = '#pop-menu .tabs li#' + jQuery(this).parent('li').attr('id').replace('pop-', 'tab-');
	  
	  // if it's not the active one
	  if (!jQuery(this).hasClass('active'))
	  {		  
		  // if it's the category link
		  if (jQuery(this).parent('li').is('#pop-categories'))
		  {
			  // add a wide class (because it needs to be wider
			  jQuery('#pop-menu').addClass('wide');
		  }
		  // if it's not the category link
		  else
		  {
			  // make sure it doesn't have a wide class because it should be thinner
			  jQuery('#pop-menu').removeClass('wide');
		  }
		  
		  // hide active
		  jQuery('#pop-menu .tabs li.active').removeClass('active');
		  jQuery('#pop-menu .nav li a.active').removeClass('active'); 
		  
		  // make requested tab active
		  jQuery(requested).toggleClass('active');
		  jQuery(this).toggleClass('active');
	  }
	  // if it is the already active one
	  else
	  {
		  // if it's not the search link
		  if (jQuery(this).parent('li').attr('id') != 'pop-search')
		  {
			  // make sure it doesn't have a wide class because it should be thinner
			  jQuery('#pop-menu').removeClass('wide');
			  
			  // remove active class from items
			  jQuery(this).removeClass('active');
			  jQuery(requested).removeClass('active');
			  
			  // apply active class to search items
			  jQuery('#pop-menu .nav li#pop-search a').addClass('active');
			  jQuery('#pop-menu .tabs li#tab-search').addClass('active');
		  }
	  }
	});
 });

