/* <![CDATA[ */  
// slideshow on homepage

	jQuery('#slides').cycle({
		fx:    'fade', 
		speed:  900,
		timeout: 6000, 
		pager: '#slidernav',
		pagerAnchorBuilder: function(index, slide) {
			var slider_img = jQuery(".fullImgLink", slide).attr('href');

			return '<a href="#"><img src="http://wabi-sabi.ca/wp-content/themes/wabisabi/includes/timthumb.php?src=' + slider_img +'&w=60&h=45"/></a>';
		}
 	});
	



jQuery(document).ready(function() {
	/*COURSE AND PRODUCT PAGES*/
	/*MAKE ODD NUMBERED BUTTONS RIGHT JUSTIFIED AND PADDED*/
	//jQuery('.course-banner:odd').find('a').css('text-align','right').css('padding-right','40px').css('padding-left','0px');

	/*RECENT BLOG POSTS HOVER ANIMATIONS*/
	jQuery('#recent-blog-posts').find('.single-post').each(function(){
		/*USE STYLESHEET-SET CSS VALUES FOR HOVER VALUES*/
		var hoverBackground = jQuery(this).css('background-color');
		var hoverTextColor = jQuery(this).css('color');
		/*DEFINE NON-HOVERED CSS VALUES AS VARIABLES*/
		var background = '#ffffff';
		var textColor ="#999999";
		var borderColor ="#999999";
		/*CREATE A BORDER*/
		jQuery(this).css('width', parseInt(jQuery(this).css('width'))-2);
		jQuery(this).css('border-style', 'solid');
		jQuery(this).css('border-width', '1px');
		/*SET NON-HOVERED CSS VALUES*/
		jQuery(this).css('border-color', borderColor);
		jQuery(this).css('color', textColor);
		jQuery(this).css('background-color', background);
		/*MOUSEOVER FUNCTIONS*/
		jQuery(this).mouseenter(function() {
			jQuery(this).css('background-color', hoverBackground);
			jQuery(this).css('color', hoverTextColor);
			jQuery(this).css('border-color', hoverBackground);
			var offTimeout = jQuery(this).data("offTimeout");
			if(offTimeout){clearTimeout(offTimeout);}
		});
		jQuery(this).mouseleave(function() {
			jQuery(this).data("offTimeout", setTimeout(jQuery.proxy(function() {
				jQuery(this).css('background-color', background);
				jQuery(this).css('color', textColor);
				jQuery(this).css('border-color', borderColor);
			}, this), 100));
		});
	});
	
	/*MAIN MENU HOVER ANIMATIONS*/
	var mainMenuCount = jQuery('#menu-main>li').size();
	var zmax = 1010;
	
	jQuery('#menu-main>li').mouseenter(function() { // enter animation
		var offTimeout = jQuery(this).data("offTimeout");
		if(offTimeout){clearTimeout(offTimeout);}
		jQuery(this).data("onTimeout", setTimeout(jQuery.proxy(function() {
		jQuery(this).find('ul').each(function(){
			
				var cur = parseInt(jQuery( this ).css( 'zIndex'));
				if(cur > parseInt(zmax)){zmax=cur;}
				jQuery(this).css( 'zIndex', parseInt(zmax)+1 );
				jQuery(this).slideDown();
				zmax=parseInt(zmax)+1;
			
		});
		}, this), 300));
	});
	
	jQuery('#menu-main>li').mouseleave(function() { // exit animation
		var onTimeout = jQuery(this).data("onTimeout");
		if(onTimeout){clearTimeout(onTimeout);}
	
		jQuery(this).data("offTimeout", setTimeout(jQuery.proxy(function() {
			jQuery(this).find('ul').slideUp();
		}, this), 600));
	});
	
	var readMoreText = "[read more]";
	var readLessText = "[read less]";
	
	/*jQuery('.course-event h2:eq(0)').after('<a class="course-read-more" href="#">'+readLessText+'</a>');*/
	jQuery('.course-event h2:gt(0)').after('<a class="course-read-more" href="#">'+readMoreText+'</a>');
	jQuery('.course-event .inner:gt(0)').css('display','none');

	jQuery('.course-read-more').click(
		function(){
			var currentThing = jQuery(this);
			
			jQuery(this).parent().find('.inner').slideToggle(600, function(){
				if(jQuery(currentThing).html()==readLessText){
					jQuery(currentThing).html(readMoreText);
				}else{
					jQuery(currentThing).html(readLessText);
				}
			});
			
			return false;
		}
	);
	
	//clear course list divs
	
	var divs_per_row = 3;
	
	//jQuery(".category-single-div:nth-child("+divs_per_row+"n + 1)").css('clear','both');
	
	
	//all courses in row same height
	
	function heightEvener(selector){
		var selected = jQuery( selector );
		selected.each(function(index, value){
			if(index%divs_per_row==0){
	
				var heights = new Array();
				
				//get height of h3s until divs_per_row
				for(i=0;i<=divs_per_row-1;i++){
					if(jQuery(selector + ":eq("+(index+i)+")").length >0){ 
						heights.push(parseInt(jQuery(selector + ":eq("+(index+i)+")").css('height')));
					}
				}
				//console.log(heights);
				var largest = Math.max.apply(Math, heights);
				//console.log(largest);
				for(i=0;i<=divs_per_row-1;i++){
					if(jQuery(selector + ":eq("+(index+i)+")").length >0){ 
						jQuery(selector + ":eq("+(index+i)+")").css('height', largest);
					}
				}
				
			}
		});
		
	}
	
	
	heightEvener(".category-single-div");
	heightEvener(".homepage-div .inner");	
	//heightEvener("#recent-blog-posts .single-post");	
	
});

	


/* ]]> */
