$(document).ready(function(){


	$('#ap').qtip({
	   id: 'myTooltip',
	   content: {
			text: $("#ap_div"),
			title: {
				text: 'Área privada',
				button: 'Close'
      		}
	   },

		show:{
			event:"click"
		},
		hide:{
			event:"click"
		},
	   position: {
			my: 'top center',
			at: 'bottom center',
			adjust: {
         		y: -8
      		}
		},
    	style: {
      		classes: 'ui-tooltip-light ui-tooltip-jtools ui-tooltip-rounded'
   		}
	});

	$("#ap_div input[type='submit']").click(function(){
		$("#ap_div .error").hide();
		$.ajax({
			type: "POST",
			async: false,
			url: "ajax_login.php",
			data: "user="+$("#user").val()+"&password="+$("#password").val(),
			success: function(msg){
				if (msg=='true') {
					window.location=$("#areainterna").val();
				}
				else {
					$("#ap_div .error").text("Datos de acceso incorrectos");
					$("#ap_div .error").show();
				}
			}
   		});
	});

	$("ul.imatges a").fancybox({
		'zoomSpeedIn':	300,
		'zoomSpeedOut':	300,
		'overlayShow':	true,
		'padding': 4
	});

	$("a.gal").fancybox({
		'zoomSpeedIn':	300,
		'zoomSpeedOut':	300,
		'overlayShow': false,
		'padding': 4
	});

	$("a.podcast").fancybox({
		'zoomSpeedIn':	300,
		'zoomSpeedOut':	300,
		'overlayShow': false,
		'frameWidth':425,
		'frameHeight':125,
		'padding': 4
	});
});

function canviarLogin(el,url) {
	$("#login").attr('action',url+el.value+"/");
}
/* Mostra els comentaris d'una proposta */
function veureComentaris(pg,taula,id,num,idioma) {
	ret=true;
	$.ajax({
		type: "GET",
		async: false,
		url: "comentaris.php",
		data: "pg="+pg+"&id="+id+"&taula="+taula+"&comentaris="+num+"&lang="+idioma,
		success: function(msg){
			$("#comentaris").fadeOut("normal", function() {
      			$("#comentaris").html(msg);
			});
   		$("#comentaris").fadeIn('slow');
		}
   });
}

function viewElement(nom) {
	$("#"+nom).toggle();
}

function viewSlideElement(nom,nivell) {
	nivell=parseInt(nivell,10)+1;

	if ($("#"+nom).css('display')=='none') {
		$(".nivell"+nivell).each(function () {
			if ($(this).css('display')=='block') {
				$(this).slideToggle();
			}
		});

		$("#"+nom).slideToggle();
	}
}

function visita(id) {
	el=$('#anunci-'+id).css('display');
	if (el=='none') {
	$.ajax({
			type: "POST",
			url: "../ajax_visites.php",
			data: "id="+id
		});
	}
}

function votar(vot,id) {
	$.ajax({
			type: "POST",
			url: "../ajax_vot.php",
			data: "vot="+vot+"&id="+id,
			success: function(msg){
				if (msg==10001) {
					alert('Gràcies, per el teu vot');
				}
				else {
					if (msg==10002) {
						alert('No pots tornar a votar');
					}
					else {
						alert('Oooops,  hi ha agut algun error');
					}
				}
			}
		});
}


