// JavaScript Document
jQuery.noConflict();
(function($){
$(function(){

$(document).ready(function(){
	//Survol des panneaux en HP pour afficher texte relatif
	$('div.overPanneau a').hover(function(){
		var position = $('body table:first').position();
		
		$('body').append('<div id="boxInfo"></div>');
		$('#boxInfo').css('position','absolute')
					 .css('z-index','1000')
					 .css('width','194px')
					 .css('top',$(window).scrollTop()+100+'px')
					 .css('left',position.left+807+'px');
		var content = $(this).parent().children('div').html();
		$('#boxInfo').html(content);
	}, function(){
		$('#boxInfo').remove();
	});
	
	//submit du form shareWishList
	$('#submitShareWishList').live('click', function(){
		//On vérifie les champs du formulaire
		var arrayField = Array('userNom', 'userPrenom', 'userEmail');
		var errorField=0;
		var errorEmail=1;
		for(var i=0; i<arrayField.length;i++){
			if($('#'+arrayField[i]).val() == ''){
				$('#'+arrayField[i]).css('background','#2B7BA9');
				errorField = 1;
			}else{
				$('#'+arrayField[i]).css('background','#FFFFFF');
			}
		}
		//On v?rifie qu'au moins un email est saisis
		$('.emailCheck').each(function(){
			$(this).css('background','#FFFFFF');
			if($(this).val() != ''){
				errorEmail = 0;
			}
		});
		if(errorEmail==1){
			$('#email1').css('background','#2B7BA9');
		}
		//On envoi ou pas le formulaire
		if(errorEmail!=1 && errorField!=1){
			$('#formShareWishList').submit();
		}
	});
	
	//D?ploi les listes sauvegard?es
	$('a.deployListe').live('click', function(){
		var id = $(this).attr('id').substr(5, $(this).attr('id').length); 
		$('div.detailListe').each(function(){
			$(this).fadeOut(0);						   
		});
		$('div#detailListe'+id).fadeIn('fast');
	})
	
	//Gestion du clic sur les bords droit et gauche du fond du site
	var linkright = '';
	var linkleft = '';
	$.ajax({
			type: 'POST',
			url: "http://"+window.location.host+"/fr/ajax/get_bg_link.php",
			dataType: "json",
			async: false,
			data: "action=getLink",
			success: function(json){
				if(json.link.right != '') linkright = json.link.right;
				if(json.link.left != '') linkleft = json.link.left;
				if(linkright!='' && linkleft == '') linkleft = linkright;
				if(linkright=='' && linkleft != '') linkright = linkleft;
			}
		});
	if(linkright!='' && linkleft != ''){
		var position = $('#logo-pos').position();
		var limiteG = Number(position.left);
		var limiteD = limiteG+Number($('body table:first').css('width').substr(0,$('body table:first').css('width').length-2));
//alert('limiteG : '+limiteG+', limiteD : '+limiteD);
		$('body').mousemove(function(event){
			var posX = Number(event.pageX);
			if(posX<=limiteG){
				$('body').css('cursor','pointer');
				$(this).click(function(){
					window.location.href = linkleft;
					$(this).unbind('click');
				});
			}else if(posX>=limiteD){
				$('body').css('cursor','pointer');
				$(this).click(function(){
					window.location.href = linkright;
					$(this).unbind('click');
				});
			}else{
				$('body').css('cursor','default');
				$(this).unbind('click');
			}
		});
	}
});
		   
});
})(jQuery);