$j(document).ready(function(){
	testimonials = new testimonialsInstance();
	testimonials.init();
});

function testimonialsInstance(){};
testimonialsInstance.prototype = {
	init : function() {
		var o = this;
		o.loadTestimonials();
		o.component = $j('#Testimonials');
		o.blockQuote = $j('blockquote',o.component);
		o.blockQuoteContent = $j('blockquote div',o.component);
		o.citeContent = $j('cite',o.component);
		o.tickerStarted = false;
		window.clearInterval(o.ticker);
	},
	loadTestimonials : function(){
		var o = this;
		$j.ajax({
		  type: "GET",
		  url: "/themes/funktional/_includes/Data/Testimonials.xml",
		  dataType: "xml",
			complete: function(data){
				o.JSON = $j.xmlToJSON(data.responseXML);
				o.JSONLength = o.JSON.Testimonial.length;
				o.JSONCurrent = 0;
				//Render
				o.render();
			}
		});
	},
	render : function(){
		var o = this;
		//Render first testimonial into blockquote
		o.pocket = o.JSON.Testimonial[o.JSONCurrent];
		o.blockQuote.attr('cite',o.pocket.Name[0].Text);
		o.blockQuote.attr('cite',o.pocket.Name[0].Text);
		o.blockQuoteContent.html(o.pocket.Content[0].Text);
		o.citeContent.html(o.pocket.Name[0].Text + '&nbsp;-&nbsp<a href="' + o.pocket.ALink[0].Text + '">' + o.pocket.Company[0].Text + '</a>');
		
	if(o.tickerStarted == false){
  		o.JSONCurrent = 1;
   		o.ticker =  window.setInterval						("testimonials.nextTestimonial()",20000);
   		o.tickerStarted = true;
  	}
		
	},
	nextTestimonial : function() {
		var o = this;

		
		if(o.JSONCurrent < o.JSONLength) {
			//Hide..
			o.blockQuote.fadeOut('slow');
			o.citeContent.fadeOut('slow',o.render());

			//Render Content..
			//o.render();

			//Show..
			o.blockQuote.fadeIn('slow');
			o.citeContent.fadeIn('slow');
			o.JSONCurrent++;
		}
		else { 
			//Reset counter
			o.JSONCurrent = 0;
			//Hide..
			o.blockQuote.fadeOut('slow');
			o.citeContent.fadeOut('slow',o.render());

			//Render Content..
			//o.render();

			//Show..
			o.blockQuote.fadeIn('slow');
			o.citeContent.fadeIn('slow');
			o.JSONCurrent++;
		}
	}
}


