var name = "#social";
var menuYloc = null;


jQuery.noConflict();
jQuery(document).ready(function(){ 
	jQuery("#nav-footer .menu_niv_01 .page").each(function() {
		linext = jQuery(this).next('.sspage').children();
		jQuery(this).append(linext);
		jQuery(this).next('.sspage').remove();
	})
	
	menuYloc = parseInt(jQuery(name).css("top").substring(0,jQuery(name).css("top").indexOf("px")))
	jQuery(window).scroll(function () { 
		offset = menuYloc+jQuery(document).scrollTop()+"px";
		jQuery(name).animate({top:offset},{duration:500,queue:false});
	});
	jQuery('.produit_vignette li .post_produit, .produit_associes li .post_produit').equalHeights();
	jQuery('.produit_vignette li .post_produit, .produit_associes li .post_produit').hover(
		function() {
			jQuery(this).addClass("hovered").hover(
				function(){ 
					jQuery(this).addClass("hovered"); 
				},
				function(){ 
					jQuery(this).removeClass("hovered"); 
				}
			);
		});
	
	jQuery('.liste_images a img').mouseover(function() {
        var imageSrc = jQuery(this).attr('src');
        var imageHref = jQuery(this).parent().attr('href');
        //main image
        jQuery('.produit_detail .illustration img').attr('src', imageSrc.replace('/miniature/', '/vignette/'));
        //zoom image
        jQuery('.produit_detail .illustration').attr('href', imageHref);
        //jQuery('.produit_detail .illustration').attr('onClick', zoomPopupHref + ";return false;");
    });
	var anchor = jQuery.url.attr('anchor')
	jQuery('.commander a').click(function(){
		jQuery('#questionnaire').slideDown();
		
		//return false;
	})
	
	if (anchor == 'questionnaire' || jQuery('#questionnaire form').children().is('.erreur_questionnaire') || jQuery('#questionnaire form').children().is('.msg-success'))  {
		jQuery('#questionnaire').slideDown();
	}
	
	if (jQuery('#questionnaire form').children().is('.erreur_questionnaire') || jQuery('#questionnaire form').children().is('.msg-success')) {
		var speed     = 1000;

		goTo('#questionnaire');								
	}
	if (jQuery('#ajouter-temoignage form').children().is('.erreur_temoignages') || jQuery('#ajouter-temoignage').children().is('.msg-success')) {
		var speed     = 1000;

		goTo('#ajouter-temoignage');								
	}
	
	function goTo(ancre){jQuery('html,body').animate({scrollTop:jQuery(ancre).offset().top},speed,'swing',function(){
            if(ancre != 'body')
                window.location.hash = ancre;
            else
                window.location.hash = '#';
            jQuery(ancre).attr('tabindex','-1');
            jQuery(ancre).focus();
            jQuery(ancre).removeAttr('tabindex');
        });
    }
	
	//Newsticker
	//cache the ticker
		var ticker = jQuery("#sidebarRight .insolite-blog .billet");
		  
		//wrap dt:dd pairs in divs
		ticker.children().filter(".post_blog").each(function() {
		  
		  var element = jQuery(this),
		    container = jQuery("<div>");
		  
		  element.next().appendTo(container);
		  element.prependTo(container);
		  
		  container.appendTo(ticker);
		});
				
		//hide the scrollbar
		ticker.css("overflow", "hidden");
		
		//animator function
		function animator(currentItem) {
		    
		  //work out new anim duration
		  var distance = currentItem.height();
			duration = (distance + parseInt(currentItem.css("marginTop"))) / 0.025;
 
		  //animate the first child of the ticker
		  currentItem.animate({ marginTop: -distance }, duration, "linear", function() {
		    
			//move current item to the bottom
			currentItem.appendTo(currentItem.parent()).css("marginTop", 0);
 
			//recurse
			animator(currentItem.parent().children(":first"));
		  }); 
		};
		
		//start the ticker
		animator(ticker.children(":first"));
				
		//set mouseenter
		ticker.mouseenter(function() {
		  
		  //stop current animation
		  ticker.children().stop();
		  
		});
		
		//set mouseleave
		ticker.mouseleave(function() {
		          
          //resume animation
		  animator(ticker.children(":first"));
		  
		});
		
	//Défilement news accueil
	jQuery(".post_blog_wrapper").scrollable({size: 3,items: '.post_blog_wrap', circular:true}).autoscroll({autoplay:true, step:1});
	
	jQuery('.home_page .produit_top').innerfade({ 
		animationtype: 'fade'
		,speed: '5000'
		,timeout: '5000'
		,type: 'sequence'
		,containerheight: '330px'
		,runningclass: 'innerfade'
	}); 
	jQuery('.produit_top').innerfade({ 
		animationtype: 'fade'
		,speed: '5000'
		,timeout: '5000'
		,type: 'sequence'
		,containerheight: '330px'
		,runningclass: 'innerfade'
	}); 



	
});





