$(document).ready(function() {
/**
 * Gestion des switch d'images.
 */
if($(".s_visuel").length>0){
	var sVisuel = $(".s_visuel");
	sVisuel.each(
		function(i){
			$("#"+sVisuel[i].id).click(
				function(){
					var img = $("#"+this.id+" > img").attr("src");
					var alt = $("#"+this.id+" > img").attr("alt");
					
					if($(".jqzoom").length > 0){
					
						var zoom = img.replace("mobile/", "mobile/z-");
	
						var urlIMG = '<a class="jqzoom" name="'+alt+'" href="'+zoom+'"><img src="'+img+'" title="'+alt+'" alt="'+alt+'" width="157" height="373" class="visuel" /></a>';
					
						$("#bVisuel").html(urlIMG);
						initZoom();	
					}else{
						$("#bVisuel").html('<img src="'+img+'" title="'+alt+'" alt="'+alt+'" width="157" height="373" class="visuel" />');
					}
				}
			);
		}
	);
}

/**
 * Gestion des avis internautes
 */
	if( $("#bt-avis-internautes").length) {
		$("#bt-avis-internautes").click(
			function(){
				$(".zone-texte-nav > .ui-corner-top ").removeClass("ui-state-active");
				$(".zone-texte-nav > .ui-corner-top ").removeClass("ui-tabs-selected");
				$("#o-avis").addClass("ui-state-active");
				$("#o-avis").addClass("ui-tabs-selected");
				$(".zone-texte-content > .ui-tabs-panel").addClass("ui-tabs-hide");
				$("#avis-internautes").parent().removeClass("ui-tabs-hide");
			}
		);
	}
/**
 * Gestion du changement de prix. 
 */
	/**
	 * Ecrit le prix sur la fiche article
	 */
	function wrPrice(prix, promotion) {
	 	if (prix == 0) {
	 		$('.prix2').text('Offert');
	 	}
	 	else {
	 		prix = prix - promotion;
	 		$('.prix2').text(prix + '€');
	 	}
	}
 /**
  * Ecrit le prix remplacé
  */
 	function wrAuLieu(prix, odr) {
 		$('#au_lieu_de').text('Soit ' + prix + '€ - ' + odr + '€ remboursés');
 	}
 
  /**
   * Affiche la vignette libre
   */
  function wrVignetteLibre(img, url) {
	  if (img != 0) {
		  $('#vignette_libre_placement').css('display', 'block');
		  $('#vignette_libre_img').attr('src', '/medias/image/' + img);
		  $('#vignette_libre_url').attr('href', url);
	  }
	  else {
		  $('#vignette_libre_placement').css('display', 'none');
	  }
  }
  
  /**
   * Affiche la vignette promotion et la remplit
   */
  function wrPromotion(prix, promotion, promotion_texte) {
	  if (promotion>0) {
		  $('#promotion').css('display', 'block');
	  }
	  else {
		  $('#promotion').css('display', 'none');
	  }
	  $('#promotion_prix').text(prix - promotion);
	  $('#promotion_au_lieu_de').text(prix);
	  $('#promotion_texte').text(promotion_texte);
  }
  
	$('.r_pta').click(function() {
		$('#a_art_pta_odr').attr('href', '/medias/pdf/' + $(this).attr('rel'));
		$('#a_art_pta_odr').text($(this).attr('rel2') + '€');
		wrPrice(parseInt($(this).attr('rel3'))-parseInt($(this).attr('rel2')), parseInt($(this).attr('rel5')));
		wrAuLieu(parseInt($(this).attr('rel3')), parseInt($(this).attr('rel2')));
		wrPromotion(parseInt($(this).attr('rel3')), parseInt($(this).attr('rel5')), $(this).attr('rel6'));
		wrVignetteLibre($(this).attr('rel7'), $(this).attr('rel8'));
		
	});
	$('.hasOdr').click(function() {
		$('#promo-title').css('display', 'block');
		$('#bloc-promo').css('display', 'block');
		$('#au_lieu_de').css('display', 'block');
	});
	$('.noOdr').click(function(){
		$('#promo-title').css('display', 'none');
		$('#bloc-promo').css('display', 'none');
		$('#au_lieu_de').css('display', 'none');
	});
	
	$('.r_pta:checked').click();


	$('#mobile-detail .add').each(function(){
		$(this).mouseover(function(){
				$(this).find('.btnBuy .submit').stop().animate({"backgroundPosition":"0 -60px"}, 0);
				$(this).find('.btnBuy').stop().animate({"width":"198px"}, 200);
			}).mouseleave(function(){
				$(this).find('.btnBuy .submit').stop().animate({"backgroundPosition":"0 0"}, 0);
				$(this).find('.btnBuy').stop().animate({"width":"70px"}, 500);
	
		});
	});
	
	$('#mobile-detail .add').each(function(){
		$(this).mouseover(function(){
				$(this).find('.btnBuy .submitnews').stop().animate({"backgroundPosition":"0 -52px"}, 0);
				$(this).find('.btnBuy').stop().animate({"width":"198px"}, 200);
			}).mouseleave(function(){
				$(this).find('.btnBuy .submitnews').stop().animate({"backgroundPosition":"0 0"}, 0);
				$(this).find('.btnBuy').stop().animate({"width":"70px"}, 500);
	
		});
	});



/**
 * Switch sur l'onglet internautes depuis le bouton dans la fiche article.
 */
	var $tabs = $('.tabs').tabs();
	$('#switch-tab-internautes').click(function() { 
	    $tabs.tabs('select', 3);
	    return false;
	});
});//doc ready
