// Background Postion Fix
// NORMAL RULES

(function($){
	$.fn.truncate = function(options) {
	   
		var defaults = {
			length: 300,
			minTrail: 20,
			moreText: "more",
			lessText: "less",
			ellipsisText: "...",
			moreAni: "",
			lessAni: ""
		};
		
		var options = $.extend(defaults, options);
	   
		return this.each(function() {
			obj = $(this);
			var body = obj.html();
			
			if(body.length > options.length + options.minTrail) {
				var splitLocation = body.indexOf(' ', options.length);
				if(splitLocation != -1) {
					var splitLocation = body.indexOf(' ', options.length);
					var str1 = body.substring(0, splitLocation);
					var str2 = body.substring(splitLocation, body.length - 1);
					obj.html(str1 + '<span class="truncate_ellipsis">' + options.ellipsisText + 
						'</span>' + '<span class="truncate_more">' + str2 + '</span>');
					obj.find('.truncate_more').css("display", "none");
					obj.append(
						'<span class="more_less">' +
							'<a href="#" class="truncate_more_link">' + options.moreText + '</a>' +
						'</span>'
					);
					var moreLink = $('.truncate_more_link', obj);
					var moreContent = $('.truncate_more', obj);
					var ellipsis = $('.truncate_ellipsis', obj);
					moreLink.click(function() {
						if(moreLink.text() == options.moreText) {
							moreContent.show(options.moreAni);
							moreLink.text(options.lessText);
							ellipsis.css("display", "none");
						} else {
							moreContent.hide(options.lessAni);
							moreLink.text(options.moreText);
							ellipsis.css("display", "inline");
						}
						return false;
				  	});
				}
			}
			
		});
	};
})(jQuery);

$(document).ready(function() {
	
	// CYCLING RULES
	$(function () {
		$('#eye_candy').cycle({ 
			pause: true, 
			timeout: 3000,
			speed: 1000
		});
	})
	;
	$(function () {
		$('.testimonial_cycle').cycle({
			fx: 'scrollDown',
			pause: true, 
			timeout: 6000,
			speed: 1000
		});
	});
	
	$('.testimonial_container_large p').truncate({
		length: 200,
	});
	
});
