jQuery(document).ready( function () {
	
	if(jQuery('.menu-deroulant').length) {
		
		jQuery('#menu a').click(function(e) {
			jQuery('.sous-menu').removeClass('open');
			jQuery('.sous-menu').css('display','none');
		});
		
		var timeout;
		var sous_menu;
		
		jQuery('.menu-item').bind('mouseenter', function(e) {
			clearTimeout(timeout);
		});
		
		jQuery('.menu-deroulant').bind('mouseenter', function(e) {
			
			if(!jQuery(this).children('.sous-menu').hasClass('open')) {
				sous_menu = jQuery(this).children('.sous-menu');
				timeout = setTimeout(function(el) {
					sous_menu.addClass('open');
					sous_menu.slideToggle(175,function(e) {
						
					});
				},125);
			}
		});
		
		jQuery('.menu-deroulant').bind('mouseleave', function(e) {
			clearTimeout(timeout);
			if(jQuery(this).children('.sous-menu').hasClass('open')) {
				jQuery(this).children('.sous-menu').removeClass('open');
				jQuery(this).children('.sous-menu').slideToggle(175,function(e) {
					
				});
			}
		});
	}
	
	if(jQuery('.accordion').length) {
		jQuery('.accordion').accordion({ autoHeight: false, animated: 'bounceslide' });
	}
	
	if(jQuery('#slideshowHolder').length) {
		
		var partenaires_affiche = 1;
		var nb_partenaires = jQuery('.slide-partenaires').length;
		var partenaires_timeout;
		
		jQuery('.slide-partenaires').hide();
		jQuery('#slide-partenaires-'+partenaires_affiche).show();
		
		var change_partenaires = function() {
			partenaires_affiche++;
			if(partenaires_affiche > nb_partenaires) {
				partenaires_affiche = 1;
			}
			
			jQuery('.slide-partenaires').hide();
			jQuery('#slide-partenaires-'+partenaires_affiche).fadeIn('slow');
		}
		
		var diff_left = 0;
		if(jQuery('#slideshow-type').val() == 1) {
			diff_left = 130;
			jQuery('#slideshowHolder').jqFancyTransitions({ width: 990, height: 270, delay:3000, strips: 30,	stripDelay: 5, navigation: true});
		}else {
			jQuery('#slideshowHolder').jqFancyTransitions({ width: 780, height: 270, delay:3000, strips: 30,	stripDelay: 5, navigation: true});
		}
	
		var texte_selectionne = 1;
		jQuery('.legende-slideshow').hide();
		jQuery('#legende-slideshow-'+texte_selectionne).fadeIn();
		
		var change_texte = function(e) {
			if(texte_selectionne > 5) {
				texte_selectionne = 1;
			}
			/*
			jQuery('.texte-home').removeClass('active');
			jQuery('.texte-'+texte_selectionne).addClass('active');*/
			
			var couleur = 'noir';
			var top = 20;
			var left = 430;
			
			switch(texte_selectionne) {
				case 1: couleur = 'blanc'; top = 20; left = 300+diff_left; break;
				case 2: couleur = 'blanc'; top = 10; left = 280+diff_left; break;
				case 3: couleur = 'noir'; top = 240; left = 370+diff_left; break;
				case 4: couleur = 'blanc'; top = 60; left = 320+diff_left; break;
				case 5: couleur = 'noir'; top = 10; left = 520+diff_left; break;
			}
			
			jQuery('.legende-slideshow').hide();
			jQuery('#legende-slideshow-'+texte_selectionne).fadeIn();
			jQuery('#legende-slideshow-'+texte_selectionne).addClass(couleur);
			jQuery('#legende-slideshow').css('left',left);
			jQuery('#legende-slideshow').css('top',top);
		}
		
		jQuery(document).bind('transition', function(e) {
			texte_selectionne++;
			change_texte();
			change_partenaires();
		});
		
		jQuery('.ft-button-slideshowHolder').click(function(e) {
			var id = jQuery(this).attr('id');
			id = id.split('-');
			id = id[1];
			texte_selectionne = id;
			change_texte();
		});
	}
	
	if(jQuery('.news-top').length) {
		var news_position = 0;
		var news_slide_height = jQuery('.news-slide').height();
		jQuery('#news-next').children('a').click(function(e) {
			e.preventDefault();
			news_position = news_position-290;
			if(news_slide_height < (-news_position)) {
				news_position = 0;
			}
			if(news_position == 0) {
				jQuery('#news-prev').hide();
			}else {
				if(jQuery('#news-prev').css('display') == 'none') {
					jQuery('#news-prev').fadeIn();
				}
			}
			jQuery('.news-slide').animate({
			    top: news_position
			  }, 400, function() {
				 
			  });
		});
		
		jQuery('#news-prev').children('a').click(function(e) {
			e.preventDefault();
			news_position = news_position+290;
			if(news_slide_height < (-news_position)) {
				news_position = 0;
			}
			if(news_position == 0) {
				jQuery('#news-prev').hide();
			}else {
				if(jQuery('#news-prev').css('display') == 'none') {
					jQuery('#news-prev').fadeIn();
				}
			}
			jQuery('.news-slide').animate({
			    top: news_position
			  }, 400, function() {
				 
			  });
		});
	}
	
	if(jQuery('#google-maps').length) {
	    var latlng = new google.maps.LatLng(43.593, 3.893366);
	    var options = {
	      zoom: 15,
	      center: latlng,
	      mapTypeId: google.maps.MapTypeId.ROADMAP
	    };
	    
	    var map = new google.maps.Map(document.getElementById("google-maps"),options);
	    
	    var contentString = 
	    	'<div><h4 class="bold">Royer Robin AssociÃ©s</h4>'
	    	+'<div class="margeur-5">461-501 Rue MÃ©tairie de Saysset<br />34070 MONTPELLIER<br /><br /></div>'
	    	+'</div>';

		var infowindow = new google.maps.InfoWindow({
		    content: contentString
		});
		
		var latlng2 = new google.maps.LatLng(43.590715, 3.894000);
	    var marker = new google.maps.Marker({
	        position: latlng2, 
	        map: map, 
	        title:"Royer Robin AssociÃ©s"
	    }); 
	    
	    infowindow.open(map,marker);
	}
	
	if(jQuery('.bandeau-partenaires').length && !jQuery('#slideshowHolder').length) {
		var partenaires_affiche = 1;
		var nb_partenaires = jQuery('.slide-partenaires').length;
		var partenaires_timeout;
		
		jQuery('.slide-partenaires').hide();
		jQuery('#slide-partenaires-'+partenaires_affiche).show();
		
		var change_partenaires = function() {
			partenaires_affiche++;
			if(partenaires_affiche > nb_partenaires) {
				partenaires_affiche = 1;
			}
			
			jQuery('.slide-partenaires').hide();
			jQuery('#slide-partenaires-'+partenaires_affiche).fadeIn('slow');
			
			partenaires_timeout = setTimeout(function(el) {
				change_partenaires();
			},3000);
		}
		
		partenaires_timeout = setTimeout(function(el) {
			change_partenaires();
		},3000);
	}
});
