$(document).ready(function(){

	$('ul li:last-child').addClass('last');

	// Renewal reminder validation
	if(document.URL.indexOf('renewal-reminder') != -1) {
		$('form#cformsform').submit(function(e){
			$('#usermessagea').removeClass('failure').text('').hide();
			var self = $(this);
			var selected_count = 0;
			self.find('select').each(function(){
				if($(this).find('option[value=January]').length != 0 && $(this).val() != '') selected_count++;
			});
			
			if(selected_count == 0) {
				e.preventDefault();
				$('#usermessagea').addClass('failure').text('Please fill out at least one renewal date.').show();
			}
		});
	}
	// Sliding content area
	if($('#slider').length){
	
		var height = $('#slider').height();
		$('#slider').css({height:180});
		$('#slider').after('<p id="slider-controls" class="group"><a class="more" href="#" title="Reveal full text">Read More</a></p>');
		
		$('#slider-controls a').click(function() {
			if($('#slider').height() == 180){
				$('#slider').animate({height: height}, 600, 'linear'/*, function(){location = '#slider';}*/);
				//$(this).parent().fadeOut('fast');
				$('#slider-controls a').html('Hide Info').removeClass('more').addClass('less').attr('title','Hide full text');
			}else{
				/*location = '#container';*/
				$('#slider').animate({height:180}, 600);
				$('#slider-controls a').html('Read More').removeClass('less').addClass('more').attr('title','Reveal full text');
			}
			return false;		
		});	
	
	}
	
	// Suckerfish
	if($('#marketing').length){

		$('#marketing li ul').hide();

		$("#marketing li").click(function(){
			$(this).children("ul").toggle();
		});
	}	
	
	// FAQ Revealer
	if($('.faq-reveal').length) {
		$('.faq-reveal dd').hide();
		$('.faq-reveal dt').css('cursor', 'pointer');
		$('.faq-reveal dt').click(function() {
			if($(this).next('dd').is(':hidden')) {
				$(this).next('dd').slideDown();
			} else {
				$(this).next('dd').slideUp();
			}
		});
	}
	
	// Benefits Revealer
	if($('.benefits').length) {
		$('.benefits dd').hide();
		$('.benefits').children().each(function(){
				if ($(this).next('dd').length){
					$(this).append('<div class="more">More Info</div>');
				}
			
		});
		$('.benefits dt').click(function() {
			if ($(this).next('dd').length){
				if ($(this).next('dd').is(':hidden')) {
					$(this).next('dd').slideDown();
					$(this).find('div.more').html('Less Info').removeClass('more').addClass('less');
				} else {
					$(this).next('dd').slideUp();
					$(this).find('div.less').html('More Info').removeClass('less').addClass('more');
				}
			}
		});
	}
		$.expr[':'].external = function(obj){
		    return !obj.href.match(/^mailto\:/i)
						&& !obj.href.match(/^http\:\/\/www.mycarolenash.com/i)
						&& !obj.href.match(/^http\:\/\/www.whoiscarolenash.co.uk/i)
                        && !obj.href.match(/^https\:\/\/carolenashclassiccar.insurance--quotations.com/i)
						&& !obj.href.match(/^http\:\/\/www.motorcyclelive.co.uk/i)
                        && !obj.href.match(/^http\:\/\/carolenashuk.epticahosting.com/i)
			            && (obj.hostname != location.hostname);
						};

	$('a:external').click(function(e) {
	  return confirm('By clicking on this link you will be entering into an external website. Please note we cannot be held responsible for the content of this external website and by using this link you will be subject to the terms of use to that site.');
	});
});

