// setuptestimonials.js
// Setup the scrolling testimonials on pages using AJAX and jquery.serialscroll 
//
// created Aug 31st, 2011, 
// Zinovi Tauber
//
/////////////////////////////////////////////

;(function() 
{		  
	$.extend($.fn, {
		
		getTestimonialUrl: function ()
		{
			if(tProperties.tgroup == 'pitestimonial')
				return "js/Testimonials/PrivateIDiplomaTestimonials.js";
			if(tProperties.tgroup == 'sptestimonial')
				return "js/Testimonials/SecurityProDiplomaTestimonials.js";
			if(tProperties.tgroup == 'pieptestimonial')
				return "js/Testimonials/PrivateIExamPrepTestimonials.js";
			if(tProperties.tgroup == 'sgeptestimonial')
				return "js/Testimonials/SecurityGuardExamPrepTestimonials.js";
			if(tProperties.tgroup == 'pisgeptestimonial')
				return "js/Testimonials/PISGExamPrepTestimonials.js";
				
			return "";
		},
		
		populateLi: function (tlist)
		{
			var ul = $(this);
			$(tlist).each(function () {
					$("<li />", {
					  	text: this.highlight,
						mouseover: (function (t) {return (
							function () {tooltip.show("<div class='tooltip'>"+t.full+"<span class='testimonialSig'>"+t.attrib+"</span></div>");})})(this),
						mouseout: function () {tooltip.hide();}
					}).append($("<span />", {
						'class': "testimonialSig",
						text: this.attrib
					 }))
					.appendTo(ul);
				});
			
			return ul;
		},
			 
		submitAjax: function()
		{ 
			var url = $(this).getTestimonialUrl();
			if(url.length > 0)
				$.ajax
				({
					type     : "GET",
					data     : '',
					url      : $(this).getTestimonialUrl(),
					dataType : "json",
		
					success:
						function(success_msg)
						{
							$(".testimonials").populateLi(success_msg).loadGeneral();
						},
						
					error:
						function(error_msg)
						{
							$(".testimonials").loadGeneral();
						}
				 });
			else
				$(".testimonials").loadGeneral();
			
			
			return true;
		},
		
		loadGeneral: function () {
			$.ajax
			({
				type     : "GET",
				data     : '',
				url      : 'js/Testimonials/GeneralTestimonials.js',
				dataType : "json",
	
				success:
					function(success_msg)
					{
						$(".testimonials").populateLi(success_msg);
					},
					
				error:
					function(error_msg)
					{
						$(".testimonials").populateLi([{"full":"I would personally like to take this opportunity to thank you and all the members of the faculty of CSPIS Ltd. while I attended both the Private Investigations and the Security course from September 2010 to March 2011. While being apprehensive prior to starting the courses by giving up a successful business to embark on a considerably different career, I am now confident that I have made the right choice in choosing your particular school to prepare me for the exciting challenges in both fields that I have studied for.  \n\nThe quality of knowledge and professionalism from all the instructors exceeded my high expectations throughout the duration of both courses. [The instructors] are all exceptionally qualified in each of their fields of expertise, and I was impressed by each of their effective and personable teaching methods. <br/> I encourage anyone who is seriously considering a career in Private Investigation and or Security Professional that CSPIS should be their first school of choice. <br/> I would like to extend a special thanks to [the receptionist] for all her hard work, and having a genuinely friendly presence each day that I attended.", "attrib":"Andrew B", "highlight":"... The quality of knowledge and professionalism from all the instructors exceeded my high expectations... [The instructors] are all exceptionally qualified in each of their fields of expertise, and I was impressed by each of their effective and personable teaching methods. \n\n I encourage anyone who is seriously considering a career in Private Investigation and/or Security Professional that CSPIS should be their first school of choice..."},{"full": "I would like to extend my appreciation to CSPI for allowing me to attend this school and for helping me with my job search, which has proven to be very successful. The school prepared me well for my new career in the Private Investigation field. I have already begun telling friends about CSPI. I hope they attend so they too will enjoy a better career. Thanks so much, CSPI!!! for a brighter and more challenging future.", "attrib": "Chris K.", "highlight": "... The school prepared me well for my new career in the Private Investigation field. I have already begun telling friends about CSPI. I hope they attend so they too will enjoy a better career. Thanks so much, CSPI!!!"}]);
					}
			});
			
			return true;
		},

		// process the account form data validation.
		TestimonialScroller: function (settings)
		{
			$.extend(tProperties, settings);
			tProperties.tgroup = $(this).attr("id");
			$(this).submitAjax();
			
			return $(this);
		}
	});
	
	var tProperties = $.fn.TestimonialScroller.properties = {
	};
})();

$(function($) 
{	
	$(".testimonials").TestimonialScroller().ajaxStop($(".testimonials").AutoScroller);
});

