
/**
 * sfTestimonial
 *
 * @version: 1.1
 * @author SimpleFlame http://www.simpleflame.com/
 *
 * Settings
 *  nextClass   - optional class for the next link
 *  item        - selector matching single testimonial
 *  nextLabel   - text of the next link
 *  duration    - autorotate interval
 *  autorotate  - autorotate on/off switch
 *  activeClass - which testimonial should be displayed as the first active one
 */
(function($){var sfTestimonial=function(el,options){var defaults={nextClass:null,prevClass:null,item:'div.item',nextLabel:'Next',prevLabel:'Prev',duration:5000,autorotate:true,activeClass:'active'};this.options=$.extend(defaults,options);this.wrapper=$(el);this.items=this.wrapper.find(this.options.item);this.current=this.items.index('.'+this.options.activeClass);if(this.current<0){this.current=0;} this.items.hide().eq(this.current).show();this.buildNavigation();if(this.options.autorotate){this.autorotate();}};sfTestimonial.prototype.buildNavigation=function(){var buildNavItem=$.proxy(function(label,offset,className){var el=$('<a>',{'class':label,'href':'#','text':label,click:$.proxy(function(e){e.preventDefault();this.cycle(offset);},this)});if(className){el.addClass(className);} return $('<li />').append(el);},this);var next=buildNavItem(this.options.nextLabel,1,this.options.nextClass),prev=buildNavItem(this.options.prevLabel,-1,this.options.prevClass);var ul=$('<ul class="nav" />').append(next,prev);this.wrapper.append(ul);};sfTestimonial.prototype.cycle=function(){var offset=arguments[0]||1;this.items.stop().eq(this.current).hide();this.current=this.current+offset;if(this.current===this.items.length){this.current=0;} else if(this.current===-1){this.current=this.items.length-1;} this.items.stop().eq(this.current).fadeIn();if(this.options.autorotate){this.autorotate();}};sfTestimonial.prototype.autorotate=function(){window.clearTimeout(this.timeout);this.timeout=window.setTimeout($.proxy(function(){this.cycle();},this),this.options.duration);};$.fn.sfTestimonial=function(){var options=arguments[0]||{};return this.each(function(){return new sfTestimonial(this,options);});};})(jQuery);



/*
 * hrefID jQuery extention
 */
$.fn.extend({ hrefId: function() { return $(this).attr('href').substr($(this).attr('href').indexOf('#')); } });

/*
 * Scripts
 *
 */
jQuery(function($) {
 
	var Engine = {
		utils : {
			links : function(){
				$('a[rel*=external]').click(function(e){
					e.preventDefault();
					window.open($(this).attr('href'));						  
				});
			}
		},
		forms : {
			labels : function(){
				var $elements = $('#header form.newsletter p input');
				$elements.each(function(){
					if($(this).val() !== '') $(this).prevAll('label:first').hide();
				}).focus(function(){
					$(this).prevAll('label:first').hide();
				}).blur(function(){
					if($(this).val() === '') $(this).prevAll('label:first').show();
				});
			}
		},
		ui : {
			rotator : function(){
				$('#header div.showcase ul.images').pqrotator();
			}
		},
		fixes : {
			comments : function(){
				// No Comments/Trackbacks + Alternative
				var $comments = $('div.comments-a');
				$comments.each(function(){
					if($(this).find('div.comment').length == 0){
						var fixed = $(this).html().replace('</h2>','</h2><p class="empty">') + '</p>';
						$(this).html(fixed);
					} else {
						$(this).find('div.comment:odd').addClass('alt');
					}
				});
				
				// Show/Hide Comments/Trackbacks
				var $links = $('div.post-a p.info a.comments, div.post-a p.info a.trackbacks');
				$links.click(function(){
					$($(this).hrefId()).toggle();
					if($(this).is('.comments')) $($(this).hrefId()).next('div.add-comment-a:first').toggle();
					return false;
				});
				
				// Single Post
				if($('div.post-a').length == 1){
					$('div.comments-a, div.add-comment-a').show();
				}
			}
		},
		
		tweaks : {
			
				testimonials : function(){
					// this controls the home page testimonials
					if(jQuery('.testimonials').size === 0){ return; }
					
					jQuery('.testimonials').sfTestimonial();	
					
				},// testimonials
				
				breadCrumbs : function(){
					// makes last <a> correct color.
					if(jQuery(".breadcrumbs-a").size() === 0){ return; }

					jQuery(".breadcrumbs-a a:last").css("color","#999999");
				}
				
		}// tweaks 
	};

	Engine.utils.links();
	Engine.forms.labels();
	Engine.ui.rotator();
	Engine.fixes.comments();
	
	Engine.tweaks.testimonials();
	Engine.tweaks.breadCrumbs();
	
});
