$(document).ready(function() {
	
	Shadowbox.init();	

// offers
$(function() {
/*	if($('body').attr('id') == 'site-windows'){
		var bodyClass = $('body').attr('class');
		if( bodyClass.indexOf( "home" ) !== -1 ) {
			window.setTimeout(function(){
				Shadowbox.open({
				        content:    'wp-content/themes/twc/offers/winter-2011-12.html',
				        player:     "iframe",
				        title:      "",
				        height:     234,
				        width:      690,
						overlayOpacity: 0.8
				});
				$('#sb-wrapper-inner').addClass('offer');
			}, 1500);
			clearTimeout();
		}
	} */
})	

	
	$('.quote-open, #site-windows .menu-item-45 a, #site-conservatories .menu-item-21 a').click(function(){
		var url = $(this).attr('href');
		Shadowbox.open({
		        content:    url+'?lightbox=true',
		        player:     "iframe",
		        title:      "Free Quotation Request",
		        height:     350,
		        width:      470,
				overlayOpacity: 0.8 
	    });
		$('#sb-wrapper-inner').removeClass('offer');
		return false;
	});
	$('.button').css('cursor','pointer');
    $('#gform_1 .validation_error').html("Please check that you've completed the highlighted fields");
	// comments field
	var fieldComment = $('#input_1_6');
	$('#input_1_6').val('Please enter any requirements you have').css('color','#aaa');
	$('#input_1_6').focus(function(){
		fieldComment.val('').css('color','#000');
	})
	$('#input_1_6').blur(function(){
		if(fieldComment.val() == ''){
			fieldComment.val('Please enter any requirements you have').css('color','#aaa');	
		}
	})
	

	// search form
	var fieldS	=	$('#s');
	$('#s').css({'color':'#777'}).val('Search our blog');
	$('#s').focus(function(){
		fieldS.val('');
	})
	$('#s').blur(function(){
		if(fieldS.val() == ''){
			fieldS.val('Search our blog');	
		}
	})
	
	// cufon text replacement
	$('#quotationRequest').css('font-size','1.3em');
	Cufon.replace('.home h2, h1:not("#logo"), .right h3,.home .segment:not(".double") h3');

	// quickbar hover state
	$('#site-windows #quickBar .conservatories a').mouseover(function(){
		$('#quickBar p.conservatories').fadeIn(500);
	});
	$('#site-windows #quickBar .conservatories a').mouseout(function(){
		$('#quickBar p.conservatories').fadeOut(100);
	});
	$('#site-conservatories #quickBar .windows a').mouseover(function(){
		$('#quickBar p.windows').fadeIn(500);
	});
	$('#site-conservatories #quickBar .windows a').mouseout(function(){
		$('#quickBar p.windows').fadeOut(100);
	});
	
	// friend form toggle
	if ($('#friendForm').is('.submitted')) {
		$('#friendFormToggle').text('Hide the form');
	} else {
		$('#friendForm').css('display','none');		
	}
	$('#friendFormToggle').click(function(){
		$('#friendForm').slideToggle(300, function(){
			if ($('#friendForm').css('display') == 'block') {
				$('#friendFormToggle').text('Hide the form');
			} else {
				$('#friendFormToggle').text('Show the form');
			}
		});
		return false;
	});
	
	// twitter
	$('.tweet').html('');
	if($('#twitterFeed h4').hasClass('conservatories')){
		$(function(){
	      $(".tweet").tweet({
	        join_text: "auto",
	        username: "TradConservCo",
	        count: 1,
	        loading_text: "loading tweets...",
			template: "{text}<br>{time}"
	      });
	    });		
	} else {
		$(function(){
	      $(".tweet").tweet({
	        join_text: "auto",
	        username: "TradWindowCo",
	        count: 1,
	        loading_text: "loading tweets...",
			template: "{text}<br>{time}"
	      });
	    });		
	}

	// homepage
	if($('.examples')) {
		$('.testimonials .next a').click(function(){
			showTestimonials('cleared');
			return false;			
		});
		$('.testimonials .prev a').click(function(){
			showTestimonials('cleared', 'prev');
			return false;			
		});
	}
	


});

function loadQuotationForm(data) {
	
}


testInterval = window.setInterval('showTestimonials()', 10000);

// testimonials
// fade background image
var currentTestimonial = 0;
var activeTestimonial = currentTestimonial;
var currentZtestimonial = 10;

function showTestimonials(state,direction) {
	var countTestimonials = $('.testimonial').size();
	
	if(state == 'cleared'){
		window.clearInterval(testInterval);
		testInterval = window.setInterval('showTestimonials()', 10000);
	}
    // Make sure the new container is always on the background
    currentZtestimonial--;

    // Set the background image of the new active container
if (direction == 'prev') {
	activeTestimonial--;
	if (activeTestimonial < 0) { activeTestimonial = countTestimonials-1;currentZtestimonial = 10 }

    $(".testimonial:eq("+ (activeTestimonial) + ")").css({
        "display" : "block",
        "z-index" : currentZtestimonial
    });

    // Fade out the current container
    // and display the header text when animation is complete
    $(".testimonial:eq("+ (currentTestimonial) + ")").fadeOut(function(){
		currentTestimonial = activeTestimonial;
	});	
} else {
	activeTestimonial++;
	if (activeTestimonial > countTestimonials-1) { activeTestimonial = 0;currentZtestimonial = 10 }
	
    $(".testimonial:eq("+ (activeTestimonial) + ")").css({
        "display" : "block",
        "z-index" : currentZtestimonial
    });

    // Fade out the current container
    // and display the header text when animation is complete
    $(".testimonial:eq("+ (currentTestimonial) + ")").fadeOut(function(){
		currentTestimonial = activeTestimonial;
	});
}
}




