/*
 * Created: Samuel
 * Used: all pages listing (comparatifs)
 * 
 */

$(document).ready(function ()
{
	// Commun
	$('.commandes_affichage .aide').qtip({
	   	position: { corner: { target: 'rightMiddle', tooltip: 'leftMiddle' }, adjust: { x: 10, y: -30 } },
	   	style: { border: { width: 2, radius: 3,	color: 'green' }}	
	});	
	$('.liens .aide').qtip({
	   	position: { corner: { target: 'rightTop', tooltip: 'leftBottom' }, adjust: { x: -60, y: 10 } },
	   	style: { border: { width: 2, radius: 3,	color: 'green' }}	
	});
	$('.liens .aideg').qtip({
	   	position: { corner: { target: 'leftTop', tooltip: 'rightBottom' }, adjust: { x: 60, y: 10 } },
	   	style: { border: { width: 2, radius: 3,	color: 'green' }}	
	});
	$('.lien_tri .aide').qtip({
	   	position: { corner: { target: 'rightTop', tooltip: 'leftBottom' }, adjust: { x: -40, y: -20 } },
	   	style: { border: { width: 1, radius: 3,	color: 'green' }}	
	});
	
	$('.sites_marchands').each(function(i){
		$(this).qtip({
			hide: { delay: 500, when: 'mouseout', fixed: true },
			content: $(".liste_sites_marchands:eq("+i+")"),
			position: {	corner: {target: 'leftBottom',tooltip: 'rightTop'},adjust: {x: 0,y: 0}},
			style: {width: 500, border: {width: 1, radius: 3,color: 'green'}}
		});
	});
	
	// Comparatif
	$(".element_comparatif").hover(
      		function () {
        	$(this).addClass("element_comparatif_hover");
      	}, 
      		function () {
        	$(this).removeClass("element_comparatif_hover");
      		}
	);
	$(".aide_comparatif").qtip({
		hide: { when: { event: 'unfocus' }, fixed: true },
		content: {text :$('#aide_comparatif'), title: { text: 'Un peu d\'aide pour utiliser cette page', button: 'Fermer'}},
		position: {	corner: {target: 'rightTop',tooltip: 'rightBottom'},adjust: {x: -10,y: -10}},
		style: {tip: 'bottomRight', width: 570, title: {'background' : '#C6E5B7', 'color' : '#2A5C42' }, button: { 'color': 'red', 'font-weight': 'bold' }, border: {width: 1, radius: 3,color: 'green'}},
		show: { solo: true }
	});
	
	//$("#amount").val($("#slider-range-max").slider("value"));
	$("#slider-range-max").slider({
		orientation: "vertical",
		range: "max",
		min: 40,
		max: 600,
		value: 600,
		slide: function(event, ui) {
			$("#amount").val(ui.value);
		}
	});	
	$('.tri').bind('click', function(e) {  
 		$("#imgProg").show();	
		$('.pseudo').qtip("destroy");   
		$('.tri').removeClass("selected");
		$(this).addClass("selected");
		$('.element_tri').removeClass("selected_element_tri");
		$($(this).parent()).addClass("selected_element_tri");		
		var url = $(this).attr('href');
		var prix = $('#amount').val();
		var marque = $("input[name='marque']:checked").val();
		
		var minuteur = $("input[name='minuteur']:checked").val();
		var minuteur2 = $("input[name='minuteur']:checked").val();
		if (minuteur == ""){var minuteur = "Oui";var minuteur2 = "Non";};
		
		var thermostat = $("input[name='thermostat']:checked").val();
		var thermostat2 = $("input[name='thermostat']:checked").val();		
		if (thermostat == ""){var thermostat = "Oui";var thermostat2 = "Non";};
		
		var air = $("input[name='air']:checked").val();
		var air2 = $("input[name='air']:checked").val();		
		if (air == ""){var air = "Oui"; var air2 = "Non";};

		var ind = $("input[name='ind']:checked").val();
		
		$('div#resultat_compare').load(
			url,
			{'prix': prix, 'ind': ind, 'marque': marque ,'minuteur':minuteur,'minuteur2':minuteur2,'thermostat':thermostat,'thermostat2':thermostat2,'air':air,'air2':air2},
			function() {
				$("#imgProg").hide();				
				$('.sites_marchands').each(function(i){
					$(this).qtip({
						hide: { delay: 500, when: 'mouseout', fixed: true },
						content: $(".liste_sites_marchands:eq("+i+")"),
						position: {	corner: {target: 'leftBottom',tooltip: 'rightTop'},adjust: {x: 0,y: 0}},
						style: {width: 500, border: {width: 1, radius: 3,color: 'green'}}
					})
				});
				$('.pseudo').each(function(i){
					var annonce = $(this).attr('title');
					var annonce = $(this).attr('id');
					$(this).qtip({
						hide: { when: { event: 'unfocus' }, fixed: true },
						content: { url: 'details_pseudo.php', data: { id: annonce }, title: { text: 'Contacter le vendeur', button: 'Fermer'  } },
						position: {	corner: {target: 'leftBottom',tooltip: 'rightTop'},adjust: {x: 0,y: 0}},
						style: {tip: 'topRight', width: 400, height: 400, title: {'background' : '#C6E5B7', 'color' : '#2A5C42' }, button: { 'color': 'red', 'font-weight': 'bold' }, border: {width: 1, radius: 3,color: 'green'}},
						show: { solo: true }
					})
				});				
				}				
			); 
		e.preventDefault(); // stop the browser from following the link
	});
	$('.tri2').bind('click', function(e) {  
		$("#imgProg").show();	
		$('.pseudo').qtip("destroy");
		$('.tri').removeClass("selected");
		$('.element_tri').removeClass("selected_element_tri");   
		var url = $(this).attr('href');
		var prix = $('#amount').val();
		var marque = $("input[name='marque']:checked").val();
		
		var minuteur = $("input[name='minuteur']:checked").val();
		var minuteur2 = $("input[name='minuteur']:checked").val();
		if (minuteur == ""){var minuteur = "Oui";var minuteur2 = "Non";};
		
		var thermostat = $("input[name='thermostat']:checked").val();
		var thermostat2 = $("input[name='thermostat']:checked").val();		
		if (thermostat == ""){var thermostat = "Oui";var thermostat2 = "Non";};
		
		var air = $("input[name='air']:checked").val();
		var air2 = $("input[name='air']:checked").val();		
		if (air == ""){var air = "Oui"; var air2 = "Non";};

		var ind = $("input[name='ind']:checked").val();
		
		$('div#resultat_compare').load(
			url,
			{'prix': prix, 'ind': ind, 'marque': marque, 'minuteur':minuteur,'minuteur2':minuteur2,'thermostat':thermostat,'thermostat2':thermostat2,'air':air,'air2':air2},
			function() {
				$("#imgProg").hide();
				$('.sites_marchands').each(function(i){
					$(this).qtip({
						hide: { delay: 500, when: 'mouseout', fixed: true },
						content: $(".liste_sites_marchands:eq("+i+")"),
						position: {	corner: {target: 'leftBottom',tooltip: 'rightTop'},adjust: {x: 0,y: 0}},
						style: {width: 500, border: {width: 1, radius: 3,color: 'green'}}
					});
				});
				$('.pseudo').each(function(i){
					var annonce = $(this).attr('title');
					var annonce = $(this).attr('id');
					$(this).qtip({
						hide: { when: { event: 'unfocus' }, fixed: true },
						content: { url: 'details_pseudo.php', data: { id: annonce }, title: { text: 'Contacter le vendeur', button: 'Fermer'  } },
						position: {	corner: {target: 'leftBottom',tooltip: 'rightTop'},adjust: {x: 0,y: 0}},
						style: {tip: 'topRight', width: 400, height: 400, title: {'background' : '#C6E5B7', 'color' : '#2A5C42' }, button: { 'color': 'red', 'font-weight': 'bold' }, border: {width: 1, radius: 3,color: 'green'}},
						show: { solo: true }
					});
				});				
				}		
			); 
		//$('div#resultat_compare').load(url+'?prix='+prix+'&amp;minuteur='+minuteur+'&amp;minuteur2='+minuteur2+'&amp;thermostat='+thermostat+'&amp;thermostat2='+thermostat2+'&amp;air='+air+'&amp;air2='+air2); 
		e.preventDefault(); // stop the browser from following the link
	});	
	$('#compare').bind('click', function(e) {           
		var prix = $('#amount').val();
		$('div#resultat_compare').load("compare.php", {'var': prix}); 
		e.preventDefault(); // stop the browser from following the link
	});
	
	//Occaz listing
	$('.pseudo').each(function(i){
		var annonce = $(this).attr('id');
		$(this).qtip({
			hide: { when: { event: 'unfocus' }, fixed: true },
			content: { url: 'details_pseudo.php', data: { id: annonce }, title: { text: 'Contacter le vendeur', button: 'Fermer'  } },
			position: {	corner: {target: 'leftBottom',tooltip: 'rightTop'},adjust: {x: 0,y: 0}},
			style: {tip: 'topRight', width: 400, height: 400, title: {'background' : '#C6E5B7', 'color' : '#2A5C42' }, button: { 'color': 'red', 'font-weight': 'bold' }, border: {width: 1, radius: 3,color: 'green'}},
			show: { solo: true }
		});
	});
   	$('.contact_annonce').livequery(function(){
		var annonce = $('#id_annonce').attr('value');
		$(this).FormValidate({
			phpFile:"contact_annonce.php",
			ajax:true,
			validCheck: false,
			resultId: 'contact_annonce_'+annonce
		});	
	});  	
});
