jQuery(document).ready(function(){ // make sure the jquery is loaded
	
	
	// fix logo height
	var menuH = jQuery('#masthead .contactpoints').height();
	jQuery('.logo h3').height(menuH);
	jQuery('.logo a').height(menuH);
	jQuery('.logo a').hover(function() {
			jQuery(this).parent().parent().parent().addClass('logo-hover');
		},
		function() {
			jQuery(this).parent().parent().parent().removeClass('logo-hover');
		}
	);



	// accordion
	jQuery(".accordion").accordion({autoHeight: false, header: "h3.handle" });
	jQuery(".nested-accordion").accordion({autoHeight: false, header: "h3.handle", collapsible: true, active: false });

	
	// ----------------------------- external links
	jQuery('a[href^=http]').each(function(){
		if(this.href.indexOf(location.hostname) == -1) {
			jQuery(this).attr('target', '_blank');
		} else {
			if (this.href.indexOf('/tag/') > 1) {
				$link_ttl = 'Learn more about ' + jQuery(this).html();
				jQuery(this).attr('title', $link_ttl);
				jQuery(this).addClass('tag');
			};
		};
	});



	// tabs
	jQuery("#tabs").tabs();
	
	
	// show download icons
	jQuery("a[href$='.pdf']").each(function(){
		if(jQuery(this).parent().get(0).tagName == 'LI') {
			jQuery(this).parent('li').addClass("pdf");
		} else {
			jQuery(this).addClass("pdf");
		}
	});	
	jQuery("a[href$='.zip']").each(function(){
		if(jQuery(this).parent('li')) {
			jQuery(this).parent('li').addClass("zip");
		} else {
			jQuery(this).addClass("zip");
		}
	});	
	
	
	// entry images in colorbox
	jQuery("a[rel=photogallery]").colorbox();
	
	
	// Split columns
     jQuery('.splitcol').each(function() {
		 var ordered = false;
          if(jQuery(this).is("ol")) { var ordered = true; };
          var colsize = Math.round(jQuery(this).find("li").size() / 2);
          jQuery(this).find("li").each(function(i) {
               if (i>=colsize) {
                    jQuery(this).addClass('right_col');
               };
          });
          if(ordered == true) {
               jQuery(this).find('.right_col').insertAfter(this).wrapAll("<ol class='splitcol' start='" + (colsize+1) + "'></ol>").removeClass("right_col");
          } else {
               jQuery(this).find('.right_col').insertAfter(this).wrapAll("<ul class='splitcol'></ul>").removeClass("right_col");
          };
          jQuery(this).next('.splitcol').after('<br class="spacer" />');
     });
     
     
     // Line break after every third list item
     jQuery("ul.thirds-group li:nth-child(3n)").after('<br class="spacer" />');
     // .half alignments
     jQuery(".entry .half.fl-right").css('float','right').after('<br class="spacer" />');
	// Industry-list items clickable
     jQuery(".industry-list li").click(function(event){ 
     	window.location=jQuery(this).find("a").attr("href");
     	return false;
     });
	
     
     
     // CAF boxes clickable
     jQuery("#caf .box").each(function() {
     	// not on industry products
     	if(!jQuery(this).find(".widget_industry_products").is('li')) {
			jQuery(this).click(function(event){ 
				window.location=jQuery(this).find("a").attr("href");
				return false;
			});
			// cursor
			jQuery(this).hover(function() {
				jQuery(this).css('cursor','pointer');
			});
		};
     });
     
     // Add shadow to recent blog post image
     jQuery("#caf .widget_recent_post").append('<img src="/wp-content/themes/VersaPay/library/images/caf-postshadow.png" class="shadow" />');
	
	
	
	// enterprise platforms demos	
	jQuery('.how').each(function() {
		var colsize = jQuery(this).find("li").size();
		jQuery(this).find("li").each(function(i) {
			if (i == 0) {
				jQuery(this).addClass('first');
			}
			if (i != (colsize - 1)) {
				jQuery(this).append('<span class="next"></span>');
			}
			jQuery(this).addClass('step-'+i);
          });
		jQuery(this).after("<br class='spacer' />");
	});
	
	
	
	// text replacement
	Cufon.replace('.ttl-font');
	Cufon.replace('.entry h1');
	
	
	
});