jQuery.noConflict();

jQuery(document).ready(function(){

	// gestion menu principal
	jQuery(function(){
		jQuery('ul.nav_main').superfish();
	});	
	
	// bouton reste allum 
	jQuery('.nav_main A').next('ul').hover(function() { 
		jQuery(this).prev('A').css('background-position','100% 0');
	},function(){
		jQuery(this).prev('A').css('background-position','0 0');
	});
	
	jQuery('.nav_main A').hover(function() { 
		jQuery(this).css('background-position','100% 0');
	},function(){
		jQuery(this).css('background-position','0 0');
	});


	// gestion des hovers sur boutons
	jQuery('.hover').mouseover(function() {
		var source = jQuery(this).attr("src").length;
		var ext = jQuery(this).attr("src").substring(source - 4, source);
		var newsource = jQuery(this).attr("src").substring(0, source - 4) + "_ON" + ext;
		
		
		if ( jQuery(this).attr("src").substr(source-7,source) != "_ON"+ext ) {
			jQuery(this).attr("src", newsource);
		}
		});
		jQuery('.hover').mouseout(function() {
		var source = jQuery(this).attr("src").length;
		var ext = jQuery(this).attr("src").substring(source - 4, source);
		var newsource = jQuery(this).attr("src").substring(0, source - 7) + ext;
		if ( jQuery(this).attr("src").substr(source-7,source) == "_ON"+ext ) {
			jQuery(this).attr("src", newsource);
		}
	});


	// mise en place de classe pour les input pour faciliter le ciblage
	jQuery('input:text').addClass('inputText');
	jQuery('input:password').addClass('inputText');
	jQuery('input:checkbox').addClass('inputCheckbox');
	jQuery('input:radio').addClass('inputRadio');
	jQuery('input:submit').addClass('inputSubmit');
	jQuery('select').addClass('inputSelect');
	
	// gestion du bouton ok sur form search
	jQuery('#nav_sub .inputSubmit').mouseenter(function() {
		jQuery(this).css('background','url(../images/layout/btn_ok_search_ON.gif)');													 
	});
	jQuery('#nav_sub .inputSubmit').mouseleave(function() {
		jQuery(this).css('background','url(../images/layout/btn_ok_search.gif)');													 
	});
	
	// NAXEO Credit! credit_naxeo
	jQuery('.credit').click(function() {
		jQuery('#credits').fadeIn();
	});
	
	jQuery('.fermer_credit').click(function() {
		jQuery('#credits').fadeOut();
	});	
	
	
	// Carroussel
	var tailleElem = jQuery('#carroussel LI').width();
	var nombreProduit = jQuery('#carroussel LI').size();
	
	
		var url_document = "" + document.location;
		var url_size = url_document.length;
			
		var pos_id_prod = url_document.lastIndexOf('id');
		var id_produit = url_document.substring(pos_id_prod, url_size);
		//alert(id_produit);
		id_produit = id_produit.substring(3, 7);
		//alert(id_produit);
		
		var i = 1;
		jQuery("#carroussel LI A").each(function(){
			jQuery(this).addClass(""+i);
			i++;
		});
		var pos_actif = jQuery("#carroussel LI A").filter(
															function(){ 
																return jQuery(this).attr('href').indexOf('id='+id_produit) != -1; 
															}
														).attr('class');
		pos_actif = parseInt(pos_actif);
		jQuery("#carroussel LI A").removeClass();
	
	
		if (pos_actif) {
			var milieu = pos_actif;
			//alert('milieu predefini');
		} else {
			var milieu = Math.round(nombreProduit/2);
			//alert('milieu calcule');
		}
	
	var initPosition = (milieu-2)*115-115
	var positionActuel;
	var destination;
	
	// init
	jQuery("#carroussel LI").eq(milieu-1).find("IMG").addClass("biggest");
	jQuery("#carroussel LI").eq(milieu).find("IMG").addClass("bigger");
	jQuery("#carroussel LI").eq(milieu-2).find("IMG").addClass("bigger");
	jQuery("#carroussel").css("left", -initPosition);
	jQuery("#carroussel P").hide();
	jQuery("#carroussel .biggest").parent().parent().find("P").show();
	
	jQuery("#carroussel_wrap .prev").click(function() {
		move(1);
	});	
	
	jQuery("#carroussel_wrap .next").click(function() {
		move(-1);
	});	
	
	function move(direction) {
		
		if (direction == 1) {
			if ( jQuery("#carroussel .biggest").parent().parent().prev().size() == 0 ) {
				return;
			}
		} else if (direction == -1) {
			if ( jQuery("#carroussel .biggest").parent().parent().next().size() == 0 ) {
				return;
			}
		}
		
		jQuery("#carroussel IMG").removeAttr("style");

		jQuery("#carroussel_wrap .prev, #carroussel_wrap .next").unbind('click');
		
		
		
		jQuery("#carroussel .biggest").parent().parent().next().find('img').removeClass();
		jQuery("#carroussel .biggest").parent().parent().prev().find('img').removeClass();
		
		if (direction == 1) {
			jQuery("#carroussel .biggest").parent().parent().prev().find('img')
					.css('width','80px').css('height','80px').css('margin','10px')
					.animate({width:115,height:115,margin:0}, 200).addClass('biggest');
			jQuery("#carroussel .biggest:last").removeClass();
			jQuery("#carroussel .biggest").parent().parent().prev().find('img')
					.css('width','50px').css('height','50px').css('margin','20px')
					.animate({width:80,height:80,margin:10}, 200).addClass('bigger');
			jQuery("#carroussel .biggest").parent().parent().next().next().find('img')
				.css('width','80px').css('height','80px').css('margin','10px')
				.animate({width:50,height:50,margin:20}, 200);
			jQuery("#carroussel .biggest").parent().parent().next().find('img')
					.css('width','115px').css('height','115px').css('margin','0')
					.animate({width:80,height:80,margin:10}, 200).addClass('bigger');
		} else if (direction == -1) {
			jQuery("#carroussel .biggest").parent().parent().next().find('img')
					.css('width','80px').css('height','80px').css('margin','10px')
					.animate({width:115,height:115,margin:0}, 200).addClass('biggest');
			jQuery("#carroussel .biggest:first").removeClass();
			jQuery("#carroussel .biggest").parent().parent().prev().prev().find('img')
					.css('width','80px').css('height','80px').css('margin','10px')
					.animate({width:50,height:50,margin:20}, 200);
			jQuery("#carroussel .biggest").parent().parent().prev().find('img')
					.css('width','115px').css('height','115px').css('margin','0')
					.animate({width:80,height:80,margin:10}, 200).addClass('bigger');
			jQuery("#carroussel .biggest").parent().parent().next().find('img')
					.css('width','50px').css('height','50px').css('margin','20px')
					.animate({width:80,height:80,margin:10}, 200).addClass('bigger');
		}	
		
		jQuery("#carroussel P").hide();
		jQuery("#carroussel .biggest").parent().parent().find("P").show();
		
		positionActuel = parseInt(jQuery("#carroussel").css("left"));
		jQuery("#carroussel").animate({
									  left: positionActuel+(tailleElem*direction) }
									  , 400
									  , function(){
										  jQuery("#carroussel_wrap .prev").bind('click'
															,function(){
																move(1);
																});
										   jQuery("#carroussel_wrap .next").bind('click'
															,function(){
																move(-1);
																});
										  });
	}

});