(function($) {
	$(document).ready(function() {	
		
		/* preventing title widows */
		$("h2, h3 a, h4, h5, h6").each(function() {
			var wordArray = $(this).text().split(" ");
			if(wordArray.length > 1) {
				wordArray[wordArray.length-2] += "&nbsp;" + wordArray[wordArray.length-1];
				wordArray.pop();
				$(this).html(wordArray.join(" "));
			}	
		});
		
		
		$("#home-poll").attr('rel',"#poll_overlay");
		
		$("#wordmark").click(function() {
			window.location = $('a',this).attr('href');
		});
		
		$("#home-slider").addClass("home-slider-js");
		
		$(".home-slider-js").css({ "padding-top" : "15px" });
		
		/* search functionality */
		var searchVal = $('#searchform input:text').val();
		if(searchVal == "") {
			$('#searchform input:text').val("Search for...")
		} 
		
		$('#searchform input:text').focus(function() {
			$(this).val('');
		});
		
		
		$('#searchform input:text').blur(function() {
			$(this).val('Search for...');
		});
		
		/* external links */
		$('.external').attr('target', '_blank');
		
		/* homepage modal buttons */
			$("#home-testimonials").click(function() {
				window.location="http://rodrigoflores.ca/home/testimonials/";
			});
			$("#home-about").click(function() {
				window.location="http://rodrigoflores.ca/home/about-me/";
			});
				
		/* jquerytools expose */
		
		$("div[rel]").overlay({  expose:'#CCC' });
		
		/* jquerytools tip */
		
		$("a[rel=tip], li[rel=tip]").tooltip({
			tip : "#jq-tip",
			offset : [-58, 0],
			position : "top center",
			effect : "fade",
			delay : 50
		});
		 
		/* code box */
		
		/* enjoyed this post? */
		
		$("#share-p p").css({ opacity: 0 });
		
		$("#share-this a").each(function(){
			var title = $(this).attr("title");
			$(this).attr("title", "");
			$("img", this).css({ opacity : 0.8 }).hover(function(){
				$(this).stop().animate({ opacity : 1 },300);
				$("#share-p p").empty().stop().animate({ opacity: 1 }, 300).text(title);
			}, function() {
				$(this).stop().animate({ opacity : 0.8 },300);
				$("#share-p p").stop().animate({ opacity: 0 }, 300).empty();
			});
		});
		
		/* additional fixes */
		
		$("blockquote p:last").css({ "padding-bottom": 0, "margin-bottom" : 0 });
		
		
			
	}); // end $
	
})(jQuery); // end function($)