﻿/*
	Codes by Geoffrey Crofte
	http://www.creativejuiz.fr
	for Lamapix Website
	Lamapix Copyright
*/

/*
	Plugin by Geoffrey Crofte
	http://www.creativejuiz.fr
	Free for personal use (cc)
*/

(function($){
	var jz;
	
	$.fn.juizTips = function(args) {

		jz = $.extend({}, defaultSettings, args);		

		$(this).each(function(index,element){
			var valueT = $(this).attr("title"); //sélection des images (c'est un exemple) détentrices d'attribut title

			//---composition de l'infobulle---//
				//début de la div
				var hint_content = '<span class="hint">';
				
				//création du contenu
				var regex = new RegExp(jz.beforeURL + " (.*) " + jz.beforeTitle + " (.*)","gi");
				
				hint_content += valueT.replace(regex,"<a href=\"$1\" title=\"$2\">$1</a>");
				
				//fermeture de la div
				hint_content +='</span>';
				
				//on créé un parent neutre à chaque image
				$(this).wrap("<span class=\"hint_content\"></span>");
			
			
			//on affiche le hint puis on supprime le title
			var $firstParent = $(this).parents("span:first");
			$firstParent.prepend(hint_content);
			$(this).removeAttr("title"); //pour éviter le double usage
		});
		
		//on style nos class hint
		var styles = {
			'position' : 'absolute',
			'top' : jz.FromTop,
			'left' : jz.FromLeft,
			'width' : jz.tipsWidth,
			'display' : 'none',
			'opacity' : '0',
			'padding' : '7px',
			'border' : jz.borderTips,
			'font-size' : jz.textSizeTips,
			'line-height' : jz.lineHeightTips,
			'color' : jz.textColorTips,
			'background' : jz.bgTips,
			'-moz-border-radius' : jz.borderRadiusTips,
			'-webkit-border-radius' : jz.borderRadiusTips,
			'border-radius' : jz.borderRadiusTips,
			'-moz-box-shadow' : jz.boxShadowTips,
			'-webkit-box-shadow' : jz.boxShadowTips,
			'box-shadow' : jz.boxShadowTips,
			'word-wrap': 'break-word',
			'overflow':'hidden',
			'z-index':'1010'
		};
		var styles2 = {
			'position' : 'relative',
			'cursor' : jz.cursorTips,
			'display' : 'inline-block',
			'z-index':'1010'
		};
		
		$("span.hint").css(styles);
		$("span.hint_content").css(styles2);

		
		//on applique une fonction au survole
		$("span.hint_content").mouseover(function() {
			$(this).children("span.hint").stop(true); //stoppe l'animation sur l'élément et supprime celle en attente
			if($(this).children("span.hint").css("display")=="none") {
				$(this).children("span.hint").css({'display':'block'});
			}
			//on anime l'apparition du fils span (donc le span.hint fils)
			$(this).children("span.hint").animate({
				opacity:jz.gotoOpacity, 
				top:jz.gotoTop, 
				left:jz.gotoLeft
			}, jz.animTime);
		});
		
		$("span.hint_content").mouseout(function() {
			$(this).children("span.hint").delay(jz.waitingTime); 
			//on fait attendre un peu avant de passer à l'animation qui suit
			$(this).children("span.hint").animate({
					opacity:0,
					top:jz.FromTop,
					left:jz.FromLeft
			}, jz.animTime,
				function() {
					$(this).css({'display':'none'});
				}
			);
		});
	}
	
	var defaultSettings= {
		beforeURL		 : "aller à la page",
		beforeTitle 	 : "pour pouvoir",

		//	styles 
		textSizeTips 	 : "1.1em",
		lineHeightTips	 : "1.4em",
		textColorTips 	 : "#fff",
		tipsWidth		 : "225px",
		bgTips 			 : "#efab07",
		borderTips 		 : "3px solid #c08d11",
		borderRadiusTips : "8px",
		boxShadowTips	 : "2px 2px 9px #999",
		cursorTips	 	 : "help",

		//	animation information
		gotoOpacity : "0.95",
		FromTop 	: "-35px",
		gotoTop 	: "-35px",
		FromLeft 	: "0",
		gotoLeft 	: "0",
		animTime	: "250",
		waitingTime : "300"	
	};
})(jQuery);

/* Other scripts */

$(document).ready(function(){

	/* -- A supprimer après tests -- */
		$(".others").live('click', function(){
			$(this).removeClass("others");
			$(this).addClass("others2");
		});
		$(".others2").live('click', function(){
			$(this).removeClass("others2");
			$(this).addClass("others3");
		});
		$(".others3").live('click', function(){
			$(this).removeClass("others3");
			$(this).addClass("others");
		});
	/* -- Fin de à supprimer après tests -- */
	
	
	/* --- Information menu --- */
	if($("#information_menu li").size()>=1){
		
		$(".volet").css({
			'position':'absolute',
			'top':'65px',
			'left':'0'
		});
		$(".volet").hide();
		
		$("#information_menu li").each(function(){
			
			var input_focused = 0; //pour gérer les focus sur les champs de formulaire
			$(this).find("a").css("outline","none");
			
			/*permet de récupérer la valeur de l'ID ciblé par un anchor*/
			var link_name = $(this).find("a").attr("href");
			var regex = new RegExp("#(.*)","gi");
			link_name = link_name.replace(regex,"$1");
			
			/* on place l'élément ciblé par le lien juste derrière ce lien */
			$("div#"+link_name).insertAfter($(this).find("a"));
			
			/* Les actions */
			$(this).mouseenter(function(){
				
				input_focused=0;
				$(".volet").fadeOut(200);
				
				$(this).stop(true, true);
				$(this).find(".volet").stop(true, true);
				$(this).find("a").animate({top: '15px'},
				200,
					function(){
						$(this).next(".volet").slideDown(200);
					}
				);
				$(this).find("span.shadow").animate({top: '-18px'}, 200);
				
				return false;
				
			})
			.mouseleave(function(){
				
				$(this).stop(true, true);
				$(this).find(".volet").stop(true, true);
				$(this).find("a").animate({top: '0px'}, 
				200,
					function(){
						if(input_focused==0) {
							$(this).next(".volet").fadeOut(200);
						}
					}
				);
				$(this).find("span.shadow").animate({top: '-3px'}, 200);
				
				return false;
				
			});
			
			$(this).find("a").click(function(){
				return false; //pour stopper le comportement normal du lien au clic
			});
			
			/* access web*/
			$(this).find("a").focus(function(){
				$(this).trigger("mouseenter");
			})
			.blur(function(){
				$("#sendtoafriend form input").focus(function(){
					$("#sendtoafriend").css('display','block');
					$("#sendtoafriend a").css('top','15px');
					$("#sendtoafriend a span.shadow").css('top','-18px');
					
					input_focused = 1;
				});
				
				$(this).trigger("mouseleave");
			});
			$("#friend_submit").blur(function(){
				input_focused = 0;
				$(this).trigger("mouseleave");
			});
		});		
	}
	
	
	/* --- Form SendToAFriend --- */
	
	if($("#sendtoafriend form").size()==1){
		
		var default_val = $("#friend_email").val();
		$("#friend_email").focus(function(){
			if($(this).val()==default_val){
				$(this).val("");
			}
		})
		.blur(function(){
			if($(this).val()==''){
				$(this).val(default_val);
			}
		});
	}
	
	/* --- Promo bouton --- */
	/* if($("#promo").size()>=1){ */
	if($(".promotions").size()>=1){ 
		function promo_animate(){
			if ($.browser.msie) //&& $.browser.version=='7.0'
				/* var $this = $("#information_menu li.promo span span"); */
				var $this = $(".promotions");
			else
				/* var $this = $("#information_menu li.promo"); */
				var $this = $(".promotions img");
			
			$($this).animate({
				opacity:'0.1'
			}
			,700
			,function(){
				$($this).animate({
					opacity: '1'
				}
				,400
				,function(){
					$($this).animate({
						opacity:'0.1'
					}
					,400
					,function(){
						$($this).animate({
							opacity:'1'
						}, 400);
					});
				}); 
			});
		}
		promo_animate();
		auto_anim = setInterval(promo_animate, 10000);
		
		/* $("#information_menu li.promo").mouseenter(function(){ */
		$(".promotions").mouseenter(function(){
			clearInterval(auto_anim);
		});
		/* $("#information_menu li.promo").focus(function(){ 
			$(this).trigger("mouseenter");
		});*/
	}
	
	
	/* Gestion des tips */

	$(".juizTipsTotal, .juizTipsDescription").juizTips({
		'FromTop' 	: '-45px',
		'gotoTop' 	: '-45px'
	});
	
	/* correction mobiles */

    $(".zone_centrale_active").click(function(){

        $(".volet").hide();

    });


});
