var jqf = jQuery.noConflict();


function searchSet(vehicle){
	jqf('#quick_search_type').attr('value', vehicle);

	if( vehicle == "caravan"){
		jqf('#form_caravan').attr('src', '/templates/main/images/search_btn_caravan_on.gif');
		jqf('#form_motorhome').attr('src', '/templates/main/images/search_btn_motorhome.gif');
	}
	else{
		jqf('#form_caravan').attr('src', '/templates/main/images/search_btn_caravan.gif');
		jqf('#form_motorhome').attr('src', '/templates/main/images/search_btn_motorhome_on.gif');
	}
}

function searchOn(){
	jqf('#form_search_button').attr('src',  '/templates/main/images/search_btn_on.gif');
}

function searchOut(){
	jqf('#form_search_button').attr('src', '/templates/main/images/search_btn.gif');
}

function validate_form(quick_form){
	if (jqf('#quick_search_type').attr('value') == "caravan_or_motorhome"){
		alert("Please choose caravan or motorhome");
		return false;
	}
	else {
		return true;
	}
}




jqf(document).ready(function(){
	// preload images//
	var cache = [];
	jqf('.smallImage img').each(function() {
		var cacheImage = document.createElement('img');
		cacheImage.src = this.src.replace(/w97/, 'w307');
		cache.push(cacheImage);
	});

	/**
	* Car detail images
	*/
	jqf('.smallImage img').animate({ opacity: 0.5}, 1);
	jqf('.smallImage .first img').animate({ opacity: 1}, 1);

	jqf('.thumb').mouseover(function(event) {
		jqf('.smallImage img').animate({ opacity: 0.5}, 1);
		jqf('img', this).animate({ opacity: 1}, 1);

		jqf('#mainImage img').attr('src', jqf('img', this).attr('src').replace(/w97/, 'w307'));
		jqf('#mainImage a').attr('href', this.href);
		return false;
	});

	jqf('#mainImageFlag').click(function() {
		jqf('#mainImage a').click();
	});

	if (jqf('a.lightbox').length > 0) {
		jqf('a.lightbox').lightBox();
	}

	jqf('.contactUs').click(function() {
		jqf('#contactForm').slideDown('slow');
		return false;
	});


	/**
	*  AJAX - submit the form function
	*/
	jqf('.detailForm').submit(function() {
		// Form validation //
		var errorString = false;
		var email=/^.+@.+\..{2,6}$/
		jqf('.JFormMandatory', this).each(function() {
			if (
				typeof this.value == 'undefined'
				|| this.value == ''
				|| (jqf(this).hasClass('JFormEmail') && email.test(this.value) == false)
			) {
				jqf('label[for=' + this.name + ']').addClass('error');
				if (errorString == false) {
					jqf(this).focus();
				}
				errorString = true;
			}
			else {
				jqf('label[for=' + this.name + ']').removeClass('error');
			}
		});

		// print out error //
		if (errorString == true) {
			jqf('.JFormStatus').hide();
			jqf('.JFormStatusError').show();

			var destination = jqf('label.error').offset().top;
			jqf('html').animate({scrollTop: destination});
			return false;
		}

		thisForm = this;
		jqf(this).ajaxSubmit({
			success: function(responseText, statusText) {
				if (responseText == 'success') {
					// print success message //
					jqf('.JFormStatus').hide();
					jqf('.JFormStatusSuccess').show();

					// clear form //
					jqf('.JFormClear', thisForm).each(function() {
						jqf(this).attr('value', '');
					});
				}
				else {
					// print error message //
					jqf('.JFormStatus').hide();
					jqf('.JFormStatusError').show();

					jqf('label[for=capcha]').addClass('error');
					jqf(this).focus();
				}
				var destination = jqf('.JFormStatus').offset().top;
				jqf('html').animate({scrollTop: destination});
			}
		});
		return false;

	});

	jqf('.moddate li.lca span:first').toggleClass("switch");

	jqf('.moddate li.lca span').click(function() {
		jqf(this).toggleClass("switch");
	});
	
	jqf('.regShow').click(function() {
		jqf('#logRegHide').hide();
		jqf('.regHide').fadeIn();
		jqf('.continueshift1').addClass('continueshift');
		return false;
	});
	


});
