// JavaScript Document
jQuery(document).ready(function($) {
	$('#Slides').cycle({delay:2000,timeout:6000})
	//Search Box
	$('#s').focusin(function(){
		var sv = $('#s').attr('value'); 
		if( sv == 'Search' ){ 
			$(this).attr('value', '');
		}
	});
	$('#s').focusout(function(){
		var sv = $('#s').attr('value'); 
		if( !sv ){ 
			$(this).attr('value', 'Search');
		}
	});
	AddFAQlinks('.faq h3');
	$('#Content h3').prepend('<span class="left"></span><span class="right"></span>');
	  
	  
	$('.minu li:eq(0), .menu li:eq(0)').addClass('first');
	
	AddQuote("#Testimonials p", 'half');
	AddQuote("blockquote.testimonial", 'name');
	AddQuote("blockquote:not(.testimonial)", 'normal');
	
	$("#GreenLight, #MeetTheTeam, #Testimonials").css('cursor', 'pointer').hover(function(){
			var title = $(this).find('a').attr('title');
			$(this).attr('title', title);
			$(this).find('h4').addClass('hover');
	},function(){
			$(this).find('h4').removeClass('hover');														 
	}).click(function(){
		window.location = $(this).find('a').attr('href');
	});
	$('.tabcontent').not('#content1').hide();
	$("ul.tabs a").click(function () {
			// switch all tabs off
			$(".active").removeClass("active");		
			// switch this tab on
			$(this).addClass("active");		
			// slide all content up
			$(".tabcontent").slideUp();		
			// slide this content up
			var content_show = $(this).attr("href");
			$(content_show).slideDown();
		  	return false;
		});
	
	
	function AddFAQlinks(element){
		if( $(element).length ){
			var titles = new Array();
			$(element).each(function (i) {
				titles[i] = '<li><a href="#Q'+i+'">'+$(this).html()+'</a></li>';
				$(this).attr('id', 'Q'+i).prepend('<a class="faq" href="#Content">Back to Top</a>');	
			});
			$(element+':eq(0)').before('<ol id="FAQlist">'+titles.join(' ')+'</ol>');
		}
	}
	
	function AddQuote(element, loc){
		if( $(element).length ){
			$(element).each(function (i) {
				
				if( loc == 'half' ){
					var quote = $(this).html();
					var words = quote.split(' ');
					var half = Math.round(words.length/2);
					words[half] = words[half]+'<span class="rq"></span>';
					var newquote = '<span class="lq"></span>'+words.join(' ');
					$(this).html(newquote);
				}else if( loc == 'name' ){
					var quote = $(this).html();
					var words = quote.split('<span class="name">');
					words[0] = words[0]+'<span class="rq"></span>';
					var newquote = '<span class="lq"></span>'+words.join('<span class="name">');
					$(this).html(newquote);
				}else if( loc == 'normal' ){
					var quote = $(this).html();
					var words = quote.split(' ');
					var half = Math.round(words.length/2);
					words[half] = words[half]+'<span class="rq"></span>';
					var newquote = '<span class="lq"></span>'+words.join(' ');
					$(this).html(newquote);
				}
				
			});
		}
	}
	
});
