// this is the main startup script
$(function () {

	// wire rotator (home page)
	$("#rotator").rotator({
		itemFade: 500,
		pagerFade: 0,
		itemShow: 5000,
		autoPlay : true,
		showPager : true
	});

	// wire superfish navigation (all pages)
	$('#nav').supersubs({ 
		minWidth:    18,   // minimum width of sub-menus in em units
		maxWidth:    30,   // maximum width of sub-menus in em units 
		extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
						   // due to slight rounding differences and font-family 
		}).superfish({
			animation: {opacity:'show',height:'show',width:'show'},
			dropShadows: true,
			speed:100
		});

	// IE6 bgiframe fix - do it only if bgIframe is loaded (all pages)
	if($.fn.bgIframe)
		$('#nav').find('ul').bgIframe({opacity:false});

	// replace heading fonts (all pages)
	Cufon.replace('#nav li a, #content h1, #content h2, #content h3, #content h4, #content ul.imglist h3, #footer h6, #meteo h4, #meteo h5, #rotator p.title, #temoignages', {
		fontFamily: 'Aller',
		hover: true,
		forceHitArea: true
	});

	if($.fn.tooltip)
		$("#captchaTooltip").tooltip({
			track: true,
			delay: 0,
			showBody: " - ",
			fade: 250,
			top: -15,
			left: 15
		});

	// fancybox for pictures
	$("a.box").fancybox({
		'centerOnScroll'     : true,
		'hideOnContentClick' : true,
		'opacity'            : true
	});

	// fancybox for iframe
	$("a.boxiframe").fancybox({
		'centerOnScroll' : true,
		'opacity'        : true,
		'type'           : 'iframe',
		'height'         : 350
	});

	// fancybox for iframe (ozalee)
	$("a.boxiframeozalee").fancybox({
		'centerOnScroll' : true,
		'opacity'        : true,
		'type'           : 'iframe',
		'height'         : 510
	});

// fancybox for google maps
	$("a.boxmap").fancybox({
		'centerOnScroll' : true,
		'opacity'        : true,
		'type'           : 'iframe',
		'height'         : 600,
		'width'          : 600
	});

	// fancybox for message box
	$("a.boxmessage").fancybox({
		'centerOnScroll': true,
		'opacity' : true,
		'type'    : 'iframe',
		'width'   : 300,
		'height'  : 150
	});

	// fancybox for message box
	$("a.boxmeteo").fancybox({
		'centerOnScroll': true,
		'type'          : 'iframe',
		'titleShow'     : false,
		'width'         : 390,
		'height'        : 265
	});

	$("a.boxvideo").click(function() {
		$.fancybox({
			'autoScale'     : false,
			'centerOnScroll': true,
			'transitionIn'  : 'none',
			'transitionOut' : 'none',
			'title'         : this.title,
			'width'         : 412, // 680,
			'height'        : 300, // 495,
			'href'          : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'          : 'swf',
			'swf'           : {
				'wmode'           : 'transparent',
				'allowfullscreen' : 'true'
			}
		});

		return false;
	});

	// contact form hide success/error messages (contact page)
	$('#contactform div.success, #contactform div.error').hide();
	// define ajax submit handler
	var AjaxSubmit = function(){
		var btnText=$('#contactform .submit').val();
		// inform client that data is been sent:
		$('#contactform .submit').val('Envoi en cours...');
		$.ajax({
			rules: {
				captcha: {
					required: true,
					remote: "_process.php"
				}
			},
			type: 'POST',
			url: $('#contactform').attr('action'),
			data: $('#contactform').serialize(),
			// successful POST - display result in success div:
			success: function(msg){
				$('#contactform .form').slideUp(500,function(){
					$('#contactform div.success').fadeIn(500);
					$('#contactform div.error').fadeOut(500);
				});
			},
			// error on server, or wrong url - display status text in error div:
			error: function(response) {
				$('#contactform .submit').val(btnText);
				$('#contactform div.error').html(response.statusText).slideDown(500);
			}
		});
		// prevent default submit button behaviour:
		return false;
	}

	if (document.getElementById('cross-slide_equitation_ethologique'))
	{
		$('#cross-slide_equitation_ethologique').crossSlide(
		{
		fade: 3
		}, [
		{
			src:  'cross-slide/equitation_ethologique/1.jpg',
			from: '100% 50% 1x',
			to:   '70% 20% 1.3x',
			time: 5
		},
		{
			src:  'cross-slide/equitation_ethologique/2.jpg',
			from: 'bottom left',
			to:   'top right 1.5x',
			time: 5
		},
		{
			src:  'cross-slide/equitation_ethologique/3.jpg',
			from: '100% 50% 1.3x',
			to:   '0% 50% 1x',
			time: 5
		},
		{
			src:  'cross-slide/equitation_ethologique/4.jpg',
			from: '100% 50%',
			to:   '50% 50% 1.5x',
			time: 5
		},
		{
			src:  'cross-slide/equitation_ethologique/5.jpg',
			from: '70% 50% 1.5x',
			to:   '30% 50% 1x',
			time: 5
		}
		]);
	}

	if (document.getElementById('cross-slide_randonnee_equestre_voyage'))
	{
		$('#cross-slide_randonnee_equestre_voyage').crossSlide(
		{
		fade: 3
		}, [
		{
			src:  'cross-slide/randonnee_equestre_voyage/1.jpg',
			from: '100% 50% 1x',
			to:   '50% 30% 1x',
			time: 5
		},
		{
			src:  'cross-slide/randonnee_equestre_voyage/2.jpg',
			from: '50% 50% 1.2x',
			to:   '50% 100%',
			time: 5
		},
		{
			src:  'cross-slide/randonnee_equestre_voyage/3.jpg',
			from: '0% 50% 1.5x',
			to:   '50% 50% 1x',
			time: 5
		},
		{
			src:  'cross-slide/randonnee_equestre_voyage/4.jpg',
			from: '100% 50%',
			to:   '30% 50% 1.5x',
			time: 5
		},
		{
			src:  'cross-slide/randonnee_equestre_voyage/5.jpg',
			from: '80% 30% 1.5x',
			to:   '20% 30% 1x',
			time: 5
		}
		]);
	}

	if (document.getElementById('cross-slide_stages_enfants'))
	{
		$('#cross-slide_stages_enfants').crossSlide(
		{
		fade: 3
		}, [
		{
			src:  'cross-slide/stages_enfants/1.jpg',
			from: '70% 70% 1x',
			to:   '30% 70% 1.3x',
			time: 5
		},
		{
			src:  'cross-slide/stages_enfants/2.jpg',
			from: 'bottom left 1.3x',
			to:   'top center 1x',
			time: 5
		},
		{
			src:  'cross-slide/stages_enfants/3.jpg',
			from: '100% 80% 1.5x',
			to:   '80% 0% 1x',
			time: 5
		},
		{
			src:  'cross-slide/stages_enfants/4.jpg',
			from: '100% 50%',
			to:   '30% 50% 1.5x',
			time: 5
		},
		{
			src:  'cross-slide/stages_enfants/5.jpg',
			from: 'top right 1.3x',
			to:   'top left 1x',
			time: 5
		}
		]);
	}

	if (document.getElementById('cross-slide_stages_adultes'))
	{
		$('#cross-slide_stages_adultes').crossSlide(
		{
		fade: 3
		}, [
		{
			src:  'cross-slide/stages_adultes/1.jpg',
			from: '80% 40% 1x',
			to:   '30% 40% 1.3x',
			time: 5
		},
		{
			src:  'cross-slide/stages_adultes/2.jpg',
			from: 'bottom left',
			to:   'top center 1.5x',
			time: 5
		},
		{
			src:  'cross-slide/stages_adultes/3.jpg',
			from: '50% 50% 1x',
			to:   '100% 20% 1x',
			time: 5
		},
		{
			src:  'cross-slide/stages_adultes/4.jpg',
			from: '100% 30%',
			to:   '30% 30% 1.5x',
			time: 5
		},
		{
			src:  'cross-slide/stages_adultes/5.jpg',
			from: '70% 30% 1.5x',
			to:   '30% 0% 1x',
			time: 5
		}
		]);
	}

	if (document.getElementById('cross-slide_education_reeducation'))
	{
		$('#cross-slide_education_reeducation').crossSlide(
		{
		fade: 3
		}, [
		{
			src:  'cross-slide/education_reeducation/1.jpg',
			from: '20% 0% 1x',
			to:   '10% 0% 1.3x',
			time: 5
		},
		{
			src:  'cross-slide/education_reeducation/2.jpg',
			from: '70% 0% 1.5x',
			to:   '70% 0% 1x',
			time: 5
		},
		{
			src:  'cross-slide/education_reeducation/3.jpg',
			from: '100% 100% 1x',
			to:   '40% 0% 1x',
			time: 5
		},
		{
			src:  'cross-slide/education_reeducation/4.jpg',
			from: '100% 100% 1x',
			to:   '40% 0% 1x',
			time: 5
		},
		{
			src:  'cross-slide/education_reeducation/5.jpg',
			from: '60% 50% 1.5x',
			to:   '40% 0% 1x',
			time: 5
		}
		]);
	}

	if (document.getElementById('cross-slide_structure'))
	{
		$('#cross-slide_structure').crossSlide(
		{
		fade: 3
		}, [
		{
			src:  'cross-slide/structure/1.jpg',
			from: '50% 100% 1x',
			to:   '20% 50% 1.3x',
			time: 5
		},
		{
			src:  'cross-slide/structure/2.jpg',
			from: 'bottom left',
			to:   '100% 30% 1.5x',
			time: 5
		},
		{
			src:  'cross-slide/structure/3.jpg',
			from: '50% 80% 1.5x',
			to:   '50% 0% 1x',
			time: 5
		},
		{
			src:  'cross-slide/structure/4.jpg',
			from: '70% 50% 1.5x',
			to:   '0% 50% 1x',
			time: 5
		},
		{
			src:  'cross-slide/structure/5.jpg',
			from: '100% 40% 1.5x',
			to:   '30% 40% 1x',
			time: 5
		}
		]);
	}

	if (document.getElementById('cross-slide_acteurs'))
	{
		$('#cross-slide_acteurs').crossSlide(
		{
		fade: 3
		}, [
		{
			src:  'cross-slide/structure/1.jpg',
			from: '50% 100% 1x',
			to:   '20% 50% 1.3x',
			time: 5
		},
		{
			src:  'cross-slide/structure/2.jpg',
			from: 'bottom left',
			to:   '100% 30% 1.5x',
			time: 5
		},
		{
			src:  'cross-slide/structure/3.jpg',
			from: '50% 80% 1.5x',
			to:   '50% 0% 1x',
			time: 5
		},
		{
			src:  'cross-slide/structure/4.jpg',
			from: '70% 50% 1.5x',
			to:   '0% 50% 1x',
			time: 5
		},
		{
			src:  'cross-slide/structure/5.jpg',
			from: '100% 40% 1.5x',
			to:   '30% 40% 1x',
			time: 5
		}
		]);
	}

	// wire client validation
	$("#contactform").validate({
		submitHandler: AjaxSubmit
	});

	// fill the search box with default value
	set_field('searchText','Rechercher');

});