// TOOLTIPS
this.tooltip = function(){	
	/* CONFIG */
		xOffset = 10;
		yOffset = 20;
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
	/* END CONFIG */
	$("a.tooltip").hover(function(e){
		this.t = this.title;
		this.title = "";
		$("body").append("<div id='tooltip'><p>"+ this.t +"</p></div>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};

$(function(){
	tooltip();
	// COMMON
	$('li:first-child').addClass('first-child');
	$('li:last-child').addClass('last-child');
	$('tbody tr:nth-child(odd),li:nth-child(odd)').addClass('odd');
	$('tbody tr:nth-child(even),li:nth-child(even)').addClass('even');
	// TRUNCATE CRAP
	if ($('.top_list.best_programs').is('*')){
		$('.top_list.best_programs > li > a').truncatable({limit: 35});
	};
	if ($('.strip-text-content').is('*')){
		$('.strip-text-content a').truncatable({limit: 20});
	};
	// TOGGLE TOP LIST CONTENT
	$('.toggle').click(function(){
		$(this).parents('li').toggleClass('closed open');
		$(this).parent().next('.toggle_content').slideToggle();
		$('.closed .toggle').html('&#9660;');
		$('.open .toggle').html('&#9650;');
	});
	
	// INSERT IMAGE IF THERE ISN'T ONE
	// creating a new version that doesn't use javascript
	/*if ($('#content.page').is('*')){
		if($('#content img').length){
			// Don't do anything
		}else{
			$('<img class="alignright" src="/wp-content/themes/MCCMinimalist/images/random-students/random.php" alt="Online Degrees" />').insertAfter('#content h1');
		}
	};*/

	// SLIDESHOWS
	if ($('#testimonials').is('*')){
		$('#testimonials ul.slides').cycle({
			fx: 'scrollUp',
		  cleartypeNoBg: true,
		  slideResize: 0,
		  height: '75px',
		  timeout: 5000,
		  pause: 1,
		  pauseOnPagerHover: 1,
		  pager: '#testimonials_nav', 
		  pagerAnchorBuilder: function(idx, slide) { 
		      // return selector string for existing anchor 
		      return '#testimonials_nav li:eq(' + idx + ')'; 
		  }			
		});
	};
	if ($('#slides_schools').is('*')){
		$('#slides_schools').cycle({
			fx: 'fade',
		  cleartypeNoBg: true,
		  slideResize: 0,
		  height: '180px',
		  width: '700px',
		  timeout: 5000,
		  pause: 1,
		  pauseOnPagerHover: 1,
		  pager: '#h-1_nav', 
		  pagerAnchorBuilder: function(idx, slide) { 
		      // return selector string for existing anchor 
		      return '#h-1_nav li:eq(' + idx + ')'; 
		  }			
		});
	};
	
	// ADD DYNAMIC BUTTON BEFORE SECOND PARAGRAPH
	if($('.page .in_content').is('*')){
		var button = $('.in_content').html();
		if($('#content h2:first').is('*')){
			$('.in_content').remove();
			$('<div class="in_content">'+button+'</div>').insertBefore('#content h2:first');
		};
		if($('.top_list li.first-child a.list_button').is('*') && $('.top_list li.first-child a.list_button').attr('href').length > 0){
			var linky = $('.top_list li.first-child a.list_button').attr('href');
			$('.in_content a').attr('href', linky);
			var top_bold = $('#top_list_title strong').text();
			$('.button_subtitle').text('with '+ top_bold +' Degrees');
		};
	};
	if($('.blog_post .in_content').is('*')){
		var button = $('.in_content').html();
		$('.in_content').remove();
		$('<div class="in_content">'+button+'</div>').insertBefore('.post_content > p:nth-child(3)');
	};
	
});

