

var page_title= '',notifs_past=0,not_notif=0,not_mail=0,not_reqs=0,searching=0,doing=0,publishScroll=1,notifs=0;
function tag_select(fid) {
	$("#friend_list li").removeClass("tag_select");
	$("#friend_list li[uid='"+fid+"']").addClass("tag_select");
	$("#tagged").val(fid);
}
function agregarLider(gid){
	Sexy.prompt('Introduce tu contrase&ntilde;a.', null,{'password':true,onComplete :
		function(resp){
			if(resp != false){
				var lid = $("#new-leader").val();
				$.post("http://www.imeev.com/ajax/group_system.php?a=guardarLider",{gid:gid,lid:lid,resp:$.md5(resp)},
					function(html){
						if(html != 'ERROR'){
							$("#group-leaders").append(html);
							$("#new-leader").val('');
							$("li.token-input-token-imeev").remove();
						}
				});
			}
		}
	});
}
function expulsarGrupo(lid,gid,username){
	Sexy.prompt('Introduce tu contrase&ntilde;a para expulsar a <b>'+username+'</b> del Grupo.', '',{'password':true,onComplete :
		function(resp){
			if(resp != false){
				$.post("http://www.imeev.com/ajax/group_system.php?a=expulsarLider",{gid:gid,lid:lid,resp:$.md5(resp)},
					function(_ans){
						if(_ans == 'OK'){
							$(".leader"+lid).fadeOut();
						}
				});
			}
		}
	});
}
function stopScrollField() {
	publishScroll = 0;
	$(".publishField").removeClass('fixed');
	$("#historial-field").css('marginTop',0);
}
function expand_image(id,src,width) {
	if(!parseInt($("#image-"+id).attr('expanded')))
		$("#image-"+id).attr('src','http://img.imeev.com/display/500px/'+src+'.jpg').attr('style','max-width:'+width+'px').attr('expanded','1');
	else
		$("#image-"+id).attr('src','http://img.imeev.com/display/thumbs/'+src+'.jpg').attr('style','max-width:200px').attr('expanded','0');

}
function related_posts(histid,fecha,accion,uid) {
	$.post("http://www.imeev.com/includes/actividades.php?type=new",
		{
			fecha:fecha,
			accion:accion,
			uid:uid,
			histid:histid
		},
		function(resp){
			$("#related-"+histid).html(resp);
		}
	);
}
function insertTab(o, e)
{
	var kC = e.keyCode ? e.keyCode : e.charCode ? e.charCode : e.which;
	if (kC == 9 && !e.shiftKey && !e.ctrlKey && !e.altKey)
	{
		var oS = o.scrollTop;
		if (o.setSelectionRange)
		{
			var sS = o.selectionStart;
			var sE = o.selectionEnd;
			o.value = o.value.substring(0, sS) + "\t" + o.value.substr(sE);
			o.setSelectionRange(sS + 1, sS + 1);
			o.focus();
		}
		else if (o.createTextRange)
		{
			document.selection.createRange().text = "\t";
			e.returnValue = false;
		}
		o.scrollTop = oS;
		if (e.preventDefault)
		{
			e.preventDefault();
		}
		return false;
	}
	return true;
}
function delete_tag(id) {
	if(id > 0) {
		$.post("http://www.imeev.com/ajax/tag_engine.php?a=remove",{
				tag	: id
			}, function(resp){
				$("#cancelnote").click();
				$("#image-tag-"+id).remove();
				$(".user-tag-"+id).remove();
				var tag_html = $(".tagged_people").html();
				var spans = $(".tagged_people span").size();
				if(spans == 1) {
					$(".tagged_people").html(tag_html.replace(', ',''));
					$(".tagged_people").html(tag_html.replace(' y ',''));
				}
				if($(".tagged_people").html() == '')
					$(".tagged_people").html('No hay etiquetas en la im&aacute;gen');
				
		});
	}
}
function tag_image(id) {
	var tagged = $("#tagged").val();
	if(tagged > 0) {
		var note_x = $("#NoteX1").val();
		var note_y = $("#NoteY1").val();
		var note_width = $("#NoteWidth").val();
		var note_height = $("#NoteHeight").val();
		$.post("http://www.imeev.com/ajax/tag_engine.php?a=put",{
				note_x		:	note_x,
				note_y		:	note_y,
				note_width	:	note_width,
				note_height	:	note_height,
				imagen		:	id,
				fid			:	tagged
			}, function(resp){
				$("#cancelnote").click();
				var datos = resp.split('-@-');
				notes = [{"x1":note_x,"y1":note_y,"height":note_height,"width":note_width,"note":'<b>'+datos[0]+'</b>',"id":datos[1]}];
				//appendnote_ext(notes);
				$('#tern').imgNotes();
		});
	}else {
		Sexy.alert("Selecciona una persona a etiquetar.");	
	}
}
function no_suggest(fid,is_group) {
	$.post("http://www.imeev.com/ajax/user_options.php?type=no_suggest",{is_group:is_group,fid:fid},function(){
		switch(parseInt(is_group)) {
			case 0:
				$("#related-friend-"+fid).fadeOut('fast',function(){
					$("#related-friend-"+fid).remove();	
					if($("#maybeuknow").html() == '')
						$(".relatedfriends").fadeOut();
				});
				break;
			case 1:
				$("#related-group-"+fid).fadeOut('fast',function(){
					$("#related-group-"+fid).remove();	
					if($("#wanna_join").html() == '')
						$(".related_groups").fadeOut();
				});
				break;
		}
	});
}
function uploadify_go(space,grupo) {
	var estado = $(".comment-textarea").val();
	var comment_to = $(".comment-to").val();
	var social_fbk = $(".socialfbk").val();
	var social_twr = $(".socialtwr").val();
	var social_tb = $(".socialtb").val();
	var lugar = $("#lugar").val();
	var direccion = $("#direccion").val();
	var coords = $("#coords").val();
	var show_coords = $("#show_coords:checked").val();
	$("#"+space).uploadifySettings("scriptData",{
		"status"	: estado,
		"comment-to": comment_to,
		"socialfbk"	: social_fbk,
		"socialtwr"	: social_twr,
		"socialtb"	: social_tb,
		"grupo" 	: grupo,
		"lugar"		: lugar,
		"direccion"	: direccion,
		"coords"	: coords,
		"show_coords": show_coords
	});
	$('#'+space).uploadifyUpload(
		$('.uploadifyQueueItem').last().attr('id').replace(space,'')
	);
	$("#upload_video").hide();
	$("#upload_photo").hide();
	$("#listo-ready").fadeIn();
}
function expand_panel_event(classid){
	if($(".event-"+classid).is(":visible") == true){
		$(".event-"+classid).slideUp('fast');
		$('.event-anchor-'+classid+' .plusminus').html('+');
	}else{
		$(".event-"+classid).slideDown('fast');
		$('.event-anchor-'+classid+' .plusminus').html('&#8211;');
	}
}
function loadVideos(uid,last,videos){
	$.post("http://www.imeev.com/ajax/video_system.php?a=profileLoad",{uid:uid,last:last,videos:videos},
		function(html){
			$(".loadVideos-"+last).after(html);
			$(".loadVideos-"+last).remove(); 
			$('.video-thumb a').hover(function() {
				$(this).children(".video-info").animate({bottom: '0'});								 
			},function(){
				$(this).children(".video-info").animate({bottom: '-125'});	
			});
		}
	);
}
function loadGroupVideos(gid,last,videos){
	$.post("http://www.imeev.com/ajax/video_system.php?a=groupLoad",{gid:gid,last:last,videos:videos},
		function(html){
			$(".loadVideos-"+last).after(html);
			$(".loadVideos-"+last).remove(); 
			$('.video-thumb a').hover(function() {
				$(this).children(".video-info").animate({bottom: '0'});								 
			},function(){
				$(this).children(".video-info").animate({bottom: '-125'});	
			});
		}
	);
}
function group_cat_expand(id){
	var classid = "#reg-group-"+id+" .reg-group-wrapper";
	if($("#reg-group-"+id).is(":visible") == true){
		$("#reg-group-"+id).slideUp('fast');
		$(classid).html('');
	}else{
		$(".reg-group").slideUp('fast');
		$(".reg-group .reg-group-wrapper").html('');
		if($(classid).html() == ''){
			$(classid).html('<div id="espacio" class="loading" style="width:285px">Cargando... <img src="/images/ajax-loader.gif"/></div>');
			$.post("http://www.imeev.com/ajax/group_system.php?a=creation-form",{cat:id},
				function(html){
					$(classid).html(html);
					showRecaptcha("recaptcha-group-"+id);
				}
			);
		}
		$("#reg-group-"+id).slideDown('fast');
	}
}
function showRecaptcha(element) {
	Recaptcha.create("6LeP-7wSAAAAANSCGbFvcs0tPETknYkww2s2i2vk", element, {
		theme: "clean",
		lang: "es",
		callback: Recaptcha.focus_response_field
	});
}
function delete_list_entry(lid,gid,prio){
	Sexy.confirm('&iquest;Est&aacute;s seguro/a de eliminar esta entrada?'	, {onComplete :
		function(resp){
			if(resp == true){
				$.ajax({
					type: "POST",
					url: "http://www.imeev.com/ajax/group_lists.php?a=delete_entry",
					data: "gid="+gid+"&lid="+lid,
					cache: false,
					success: function(){
						$(".list-item-"+lid).fadeOut("fast",function(){
							$(".list-item-"+lid).remove();
							if($("#priority-"+prio).html() == ""){
								$(".priority-"+prio).fadeOut("fast");
							}
						});
					}
				});
			}
		}
	});
}
function check_list_entry(lista,prio,gid,tipo){
	$(".check-list-"+lista).attr("disabled",true);
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/group_lists.php?a=entry_done",
		data: "gid="+gid+"&lid="+lista,
		cache: false,
		success: function(html){
			if(tipo == 'done'){
				$(".list-item-"+lista).fadeOut("fast",function(){
					$(".list-item-"+lista).remove();
					if($("#priority-"+prio).html() == ""){
						$(".priority-"+prio).fadeOut("fast");
					}
					order_list(html,'done',gid);
				});
			}
			$(".check-list-"+lista).attr("disabled",false);
		}
	});
}
function edit_list_entry(list,gid,orden,lista){
	if(doing ==0){
		doing = 1;
		if($(".edit-list-content-"+list).is(":visible") == true){
			$(".edit-list-content-"+list).hide();
			$(".edit-list-entry-"+list).show();
			doing = 0;
		}else{
			var entry_name = $(".entry-name-"+list).val();
			if(entry_name == ''){
				Sexy.alert('Introduce un t&iacute;tulo para la entrada.');
				doing = 0;
			}else{
				var entry_desc = $(".entry-desc-"+list).val();
				var entry_pri = $(".prioridad-"+list).val();
				var entry_limit = $(".entry-limit-"+list).val();
				$("#lista-list").fadeOut('fast');
				$.post("http://www.imeev.com/ajax/group_lists.php?a=edit_entry",{gid:gid,lid:list,item_name:entry_name,item_desc:entry_desc,prioridad:entry_pri,limite:entry_limit},
					 function(){
						$(".edit-list-content-"+list).show();
						$(".edit-list-entry-"+list).hide();
						order_list(lista,orden,gid);
						doing = 0;
						$("#lista-list").fadeIn('fast');
					}
				);
			}
		}
	}
}
function order_list(list,orden,gid){
	$("#forum-menu span").fadeIn('fast');
	$("#lista-list").fadeOut('fast');
	$("#lista-list").load("http://www.imeev.com/ajax/listas.php?gid="+gid+"&lista="+list+"&orden="+orden,function(){
		$(".tipsy-n").tipsy({gravity:'s'});
		$(".tipsy-w").tipsy({gravity:'e'});
		$(".mood_comment_textarea").elastic();
   		$(".entry-limit").datepicker({'dateFormat':'yy-mm-dd'});
		$("#lista-list").fadeIn('fast');
		$("#forum-menu span").fadeOut('fast');
	});
}
function create_list_item(list,gid){
	if(doing == 0){
		doing = 1;
		var entry_name = $("#entry-name").val();
		var entry_desc = $("#entry-desc").val();
		var entry_pri = $("#prioridad").val();
		var entry_limit = $("#entry-limit").val();
		if(entry_name == ''){
			$(".popup-options span").html('Introduce un t&iacute;tulo para la entrada.');
		}else{
			$.post("http://www.imeev.com/ajax/group_lists.php?a=create_entry",{gid:gid,lid:list,item_name:entry_name,item_desc:entry_desc,prioridad:entry_pri,limite:entry_limit},
				   function(){
					   $("#lista-list").load("http://www.imeev.com/ajax/listas.php?gid="+gid+"&lista="+list);
				   }
			);
			$("#new-list-entry").slideUp();
			$("#entry-name").val('');
			$("#entry-desc").val('');
			var field = $('#prioridad');
 			field.val($('.selectme', field).val());
			doing = 0;
		}
	}
	$(".popup-options span").show();
	setTimeout(function(){
		$(".popup-options span").fadeOut();
	},3000);
}
function show_and_hide(classid){
	if($(classid).is(":visible") == true){
		$(classid).slideUp('fast');
	}else{
		$(classid).slideDown('fast');	
	}
}
function show_gnotifs(gid){
	if($(".pro_bigheader .notifs-spawn").is(":visible") == true){
		$(".pro_bigheader .notifs-spawn").hide();
	}else{
		$(".pro_bigheader .notifs-spawn").html('<div id="espacio" class="loading" style="width:285px">Cargando... <img src="/images/ajax-loader.gif"/></div>').show();
		$(".pro_bigheader .notifs-spawn").load("http://www.imeev.com/notifications.php?gid="+gid);
		$(".gnotifs").hide();
	}
}
function delete_group_post(post){
	if(doing == 0){
		doing = 1;
		$.post("http://www.imeev.com/ajax/group_forum.php?a=delete_post",{pid:post},
		   function(html){
				$(".post-holder-"+post).fadeOut();
				doing = 0;
		   }
		);
	}
}
function edit_group_post(post){
	var butt = $(".edit-button-"+post).html();
	var p_body = $(".post-edit-"+post).val();
	if(butt == 'Editar'){
		$(".edit-button-"+post).html('Guardar');
		$(".post-"+post).hide();
		$(".post-edit-"+post).show();
	}else{
		if(doing == 0){
			doing = 1;
			$.post("http://www.imeev.com/ajax/group_forum.php?a=edit_post",{t_body:p_body,pid:post},
			   function(html){
				   $(".post-"+post).html(html);
					doing = 0;
			   }
			);
		}
		$(".edit-button-"+post).html('Editar');
		$(".post-"+post).show();
		$(".post-edit-"+post).hide();
	}
}
function check4minicomments(feed,key){
	var Id = $('table.comment-from-feed-'+feed+':last').attr('id');
	//alert(Id);
	$.post("http://www.imeev.com/ajax/check-feed.php",{feed:feed,last:Id,key:key},
	   function(html){
		   if(html != ''){
				$('.more-mini-holder-'+feed+' table').removeClass('new-mini-comment');
				$(html).hide().appendTo(".more-mini-holder-"+feed).fadeIn("slow");
		   }
	   }
	);
}
function del_mail(mail){
	$.post("http://www.imeev.com/ajax/mail.php",{mailid:mail},
		function(){
			$(".mail"+mail).fadeOut('fast',function(){
					$(".mail"+mail).remove();
					setTimeout(function(){
						if($("#correo_info").html() == ''){
							$("#correo_info").html('<div id="espacio"><b>No hay correos disponibles.</b></div>');
							$("input[name=save_mail]").hide();
							$(".reply-mail").html('');
						}
					},100);
			}); 
		}
	);
}
function soon(){
	Sexy.alert('Pr&oacute;ximamente...');		
}
function vote_poll(poll){
	var poll_choice = $("input[name='poll"+poll+"']:checked").val();
	if(poll_choice > 0){
		$("#poll_vote"+poll).addClass("hide");						  
		$.post("http://www.imeev.com/ajax/poll_system.php", {a:'vote',poll_id: poll,choice:poll_choice},
			function(){
				show_poll_votes(poll);
			}
		);
	}else{
		Sexy.alert('Selecciona una opci&oacute;n primero.');
	}
}
function soc_del(soc){
	var arreglo = $("#soc_array").val();
	$.post("http://www.imeev.com/ajax/soc_to_array.php?delete=true",{icon:soc,arreglo:arreglo},
	function(html){
		$("#soc_array").val(html);
		$("li."+soc).remove().fadeOut('fast');
	});
}
function add_soc(){
	var soc_url = $("#networks option:selected").attr('url');
	var soc_name = $("#networks").val();
	var username = $(".add_soc_username").val();
	var parsed_url = soc_url.replace('%s',username);
	var arreglo = $("#soc_array").val();
	var network_name = $("#networks option:selected").text();
	var html = '<li class="'+soc_name+'"><a href="javascript:;" onclick="soc_del(\''+soc_name+'\')"><span class="delete-icon"></span></a><img src="/images/social/icons/'+soc_name+'_32.png">'+network_name+'<div>'+parsed_url+'</div></li>';
	$(".add_soc_list").append(html);
	$("#add_soc_spawn").html('');
	$(".add_soc").addClass('hide');
	$("#soc_icon").attr('src','http://www.imeev.com/images/0.png');
	$("#networks")[0].selectedIndex = 0;
	$.post("http://www.imeev.com/ajax/soc_to_array.php",{name:network_name,icon:soc_name,url:parsed_url,arreglo:arreglo},
		function(html){
			$("#soc_array").val(html);
		}
	);
}
function disableEnterKey(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     
	
     return (key != 13);
}
function disableEnterKey_and_go(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     
	if(key == 13){$("#adjuntar-link").click();}
     return (key != 13);
}
function page_loader(what,uid){
	$.post("http://www.imeev.com/ajax/loader.php",{page: what,uid: uid},
			function(html){
				$(".ante_loader").html(html);
			}
	);
}
function edit_address(){
	if($("#editable-address").is(":visible") == true){
		$("#editable-address").hide();
		$("#static-address").html($("#direccion").val().replace(/\n/g,'<br />'));
		$("#static-address").show();
	}else{
		$("#editable-address").show();
		$("#static-address").hide();
	}
}
function remove_location() {
	$("#location").html('');
	tb_remove();	
}
function add_location(){
	$("#location").show().html('<div align="center" class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif" /> Obteniendo ubicaci&oacute;n...</div>');
	if (navigator.geolocation) {
		navigator.geolocation.getCurrentPosition(function(position) {	
			var longitude = position.coords.longitude;
			var latitude = position.coords.latitude;
			if(longitude != ''){
				$.ajax({
					type: "POST",
					url: "http://www.imeev.com/ajax/location.php",
					data: "longitude="+longitude+"&latitude="+latitude,
					cache: true,
					success: function(html){
						$("#location").html(html);
					}
				});
			}else{
				$("#location").html('<div align="center" class="loading">Ubicaci&oacute;n no disponible.</div>');	
			}
		},function errorCallback(code){
			$("#location").html('<div align="center" class="loading">Ubicaci&oacute;n no disponible.</div>');	
		});
	}else{
		$("#location").html('<div align="center" class="loading">Ubicaci&oacute;n no disponible.</div>');
	}
}
function nl2br(str) { return str.replace(/\n/g, '<br />'); }
function edit_location() {
	$("#location span").html(nl2br($("#direccion").val()));
	tb_remove();
}
function get_hash(){
	return window.location.hash.replace('#','');	
}
	function load_pro_tab(tabid){
			$.ajax({
				   type: "POST",
				   url: "http://www.imeev.com/ajax/tab_engine.php?a=load",
				   data: 'tabid='+tabid,
				   cache: false,
				   success: function(html){
						$("#content_"+tabid).html(html);   
				   }
			});
	}
function meev_sa(tipo,aid,key){
	$.post("http://www.imeev.com/ajax/meevs.php",{type: tipo,aid: aid,key:key},
		   function(html){
			   var datos = html.split("|");
			   tipo = tipo.replace(".","");
			   if(datos[0] == 0){
					$('.meev-'+aid+tipo).html('<span class="sys"><b>&times;</b> Meev\'d</span>'); 
			   }else{
					$('.meev-'+aid+tipo).html('Meev!');   
			   }
			   
			   if(datos[1] == 1){
				    $("#meev-button-"+aid+tipo).removeClass('hide'); //Mostrar la cantidad de Meevs
					$("#meev-button-"+aid+tipo).attr('title','A t&iacute; te gusta esto.');
					$("#meev-button-"+aid+tipo+" .meev-q").html('1'); //Actualizar cantidad de Meevs
					//$(".meevs-"+histid).removeClass('hide'); //Mostrar quien ha dado Meev
			   		//$('.meevs-'+histid+' a span').html('&hearts; 1 persona ha hecho Meev a esto.');
			   }else{
				   if(datos[1] == 0){
					    $("#meev-button-"+aid+tipo+" .meev-q").html('0'); //Actualizar cantidad de Meevs
						//$('.meevs-'+histid+' a span').html('&hearts; Nadie ha dado Meev a esto.');
						$("#meev-button-"+aid+tipo).addClass('hide'); //Ocultar cantidad de Meevs
				   }else{
						//$(".meevs-"+histid).removeClass('hide'); //Mostrar quien ha dado Meev
						//$('.meevs-'+histid+' a span').html('&hearts; '+datos[1]+' personas han hecho Meev a esto.'); 
						$("#meev-button-"+aid+tipo+" .meev-q").html(datos[1]); //Actualizar cantidad de Meevs
				   }
			   }
		}
	);
}
function meev(tipo,aid,histid,key){
	$.post("http://www.imeev.com/ajax/meevs.php",{type: tipo,aid: aid,histid: histid,key:key},
		   function(html){
			   var datos = html.split("|");
			   if(datos[0] == 0){
					$('.meev-'+aid+histid).html('<span class="sys"><b>&times;</b> Meev\'d</span>'); 
			   }else{
					$('.meev-'+aid+histid).html('Meev!');   
			   }
			   
			   if(datos[1] == 1){
				   	$('<a href="javascript:;" onclick="tb_show(\'Personas que les gust&oacute; esto\',\'http://www.imeev.com/popups/who.php?id='+histid+'&width=350&height=300#TB_iframe\')" title="A t&iacute; te gust&oacute; esto." class="meevit activity-button tipsy-sw" id="meev-button-'+aid+histid+'"><img src="/images/mini/meev_.png" class="in_social" border="0"/> <span class="meev-q">1</span></a>').insertAfter('.meev-'+aid+histid);
				   //$("#meev-button-"+aid+histid).removeClass('hide'); //Mostrar la cantidad de Meevs
					//$("#meev-button-"+aid+histid).attr('title','A t&iacute; te gusta esto.');
					//$("#meev-button-"+aid+histid).addClass('activity-button');
					//$("#meev-button-"+aid+histid+" .meev-q").html('1'); //Actualizar cantidad de Meevs
					//$(".meevs-"+histid).removeClass('hide'); //Mostrar quien ha dado Meev
			   		//$('.meevs-'+histid+' a span').html('&hearts; 1 persona ha hecho Meev a esto.');
			   }else{
				   if(datos[1] == 0){
					    $("#meev-button-"+aid+histid+" .meev-q").html('0'); //Actualizar cantidad de Meevs
						//$('.meevs-'+histid+' a span').html('&hearts; Nadie ha dado Meev a esto.');
						$("#meev-button-"+aid+histid).removeClass('activity-button');
						//$("#meev-button-"+aid+histid).addClass('hide'); //Ocultar cantidad de Meevs
						$("#meev-button-"+aid+histid).remove();
				   }else{
						//$(".meevs-"+histid).removeClass('hide'); //Mostrar quien ha dado Meev
						//$('.meevs-'+histid+' a span').html('&hearts; '+datos[1]+' personas han hecho Meev a esto.'); 
						$("#meev-button-"+aid+histid+" .meev-q").html(datos[1]); //Actualizar cantidad de Meevs
				   }
			   }
		}
	);
}
function meev_mini(cid,key){
	$.post("http://www.imeev.com/ajax/meevs_mini.php",{cid:cid,key:key},
		   function(html){
			   var datos = html.split("|");
			   if(datos[0] == 0){
					$('.meev-mini-'+cid).html('<span class="sys"><b>&times;</b> Meev\'d</span>'); 
			   }else{
					$('.meev-mini-'+cid).html('Meev!');   
			   }
			   
			   if(parseInt(datos[1]) == 1){
				   
				    $("#meev-mini-button-"+cid).removeClass('hide'); //Mostrar la cantidad de Meevs
					$("#meev-mini-button-"+cid).attr('title','A t&iacute; te gusta esto.');
					$("#meev-mini-button-"+cid+" .meev-q").html('1'); //Actualizar cantidad de Meevs
					//$(".meevs-"+histid).removeClass('hide'); //Mostrar quien ha dado Meev
			   		//$('.meevs-'+histid+' a span').html('&hearts; 1 persona ha hecho Meev a esto.');
			   }else{
				   if(parseInt(datos[1]) == 0){
					    $("#meev-mini-button-"+cid+" .meev-q").html('0'); //Actualizar cantidad de Meevs
						//$('.meevs-'+histid+' a span').html('&hearts; Nadie ha dado Meev a esto.');
						$("#meev-mini-button-"+cid).addClass('hide'); //Ocultar cantidad de Meevs
				   }else{
						//$(".meevs-"+histid).removeClass('hide'); //Mostrar quien ha dado Meev
						//$('.meevs-'+histid+' a span').html('&hearts; '+datos[1]+' personas han hecho Meev a esto.'); 
						$("#meev-mini-button-"+cid+" .meev-q").html(datos[1]); //Actualizar cantidad de Meevs
				   }
			   }
		}
	);
}
function delete_account(){
	Sexy.confirm('&iquest;Est&aacute;s seguro/a de eliminar tu cuenta?'	, {onComplete :
		function(resp){
			if(resp == true){
				Sexy.confirm('Perder&aacute;s todo lo que hayas subido y creado en iMeev. No podr&aacute;s recuperar tu cuenta. &iquest;En verdad deseas hacerlo?'	, {onComplete :
					function(resp){
						if(resp == true){
							Sexy.confirm('&Uacute;ltima advertencia. Es una acci&oacute;n <b>permanente</b>. No podr&aacute;s recuperar tu cuenta. &iquest;En verdad deseas hacerlo?'	, {onComplete :
								function(resp){
									if(resp == true){
										Sexy.alert('Sentimos mucho que te vayas...');
										$.post("http://www.imeev.com/ajax/delete_account.php",{delete_account: 'true'},
											   function(){location.href ='/?action=nos_vemos_luego_y_gracias';}
										);
									}
								}
							 });
						}
					}
				});
			}
		}
	});
}
function load_moodicons(){
	$.post("http://www.imeev.com/ajax/load_moodicons.php",{loadme: 'plz'},function(icons){$("#emoticon-list-popups").html(icons);});
}
function get_notifs(uid){
	$.post("http://www.imeev.com/notifications.php?getnotifs=true",{ uid: uid},function(notif_array){
		notifs = notif_array.split("|");
		//alert(notif_array
		if(parseInt(notifs[0]) > 0){not_notif = 1;}
		if(parseInt(notifs[1]) > 0){not_mail = 1;}
		if(parseInt(notifs[2]) > 0){not_reqs = 1;}
		var total_notif = parseInt(notifs[0])+parseInt(notifs[1])+parseInt(notifs[2]);
		total_notifs = parseInt(total_notif);
				//Sexy.alert(total_notifs);
		if(parseInt(total_notifs) == 0 /*&& page_title != ''*/){
			/*document.title = page_title;*/
			page_title = '';
			not_notif = 0;
			not_mail = 0;
			not_reqs = 0;
		}
		/*if(parseInt(total_notifs) > parseInt(notifs_past) && page_title != ''){
			document.title = '('+total_notifs+') '+page_title;	
		}
		if(parseInt(total_notifs) > parseInt(notifs_past) && page_title == ''){
			page_title = document.title;
			document.title = '('+total_notifs+') '+page_title;	
		}*/
		if(total_notifs > 0) Tinycon.setBubble(total_notifs);
		notifs_past = parseInt(total_notifs);
		get_notif_notifs(notifs[0]);
		get_mail_notifs(notifs[1]);
		get_req_notifs(notifs[2]);

	});
}
function get_notif_notifs(notifs){
	notifs = parseInt(notifs);
	if(notifs > 0){
		if($("#notif_alerts").is(":visible")){
			$("#notif_alerts_spawn").load('http://www.imeev.com/notifications.php');
		}else{
			$(".notif_alerts #notif_balloon").html(notifs);
			$(".notif_alerts img").attr("src","/images/mini/bell_new.png");
			$(".notif_alerts #notif_balloon").show();
			//jqcc.cometchat.setAlert('notificaciones',notifs);
			anim_notif('alerts');
		}
	}
	if(notifs == 0){
		//$(".chat_alert").remove();
		$(".notif_alerts #notif_balloon").hide();
	}
}
function get_mail_notifs(notifs){
	if(notifs > 0){
		if($("#notif_mail").is(":visible")){
			$.post( "http://www.imeev.com/ajax/notif_system.php",
				{
					notif : 'mail'
				},
				function(html){
					$("#notif_mail_spawn").html(html);
				}
			);
		}else{
			$(".notif_mail #notif_balloon").html(notifs);
			$(".notif_mail img").attr("src","/images/mini/mail_new.png");
			$(".notif_mail #notif_balloon").show();
			//jqcc.cometchat.setAlert('notificaciones',notifs);
			anim_notif('mail');
		}
	}
	if(notifs == 0){
		//$(".chat_alert").remove();
		$(".notif_mail #notif_balloon").hide();
	}
}
function get_req_notifs(notifs){
	if(notifs > 0){
		if($("#notif_req").is(":visible")){
			$.post( "http://www.imeev.com/ajax/notif_system.php",
				{
					notif : 'friend_reqs'
				},
				function(html){
					$("#notif_req_spawn").html(html);
				}
			);
		}else{
			$(".notif_req #notif_balloon").html(notifs);
			$(".notif_req img").attr("src","/images/mini/friends_new.png");
			$(".notif_req #notif_balloon").show();
			//jqcc.cometchat.setAlert('notificaciones',notifs);
			anim_notif('req');
		}
	}
	if(notifs == 0){
		//$(".chat_alert").remove();
		$(".notif_req #notif_balloon").hide();
	}
}
function anim_notif(what){
	$('.notif_'+what+' #notif_balloon').animate({
		top: '-=5'
	  }, 'fast', function() {
		$('.notif_'+what+' #notif_balloon').animate({
			top: '+=5'
		},'fast');
	});	
}

function show_pimper(s){
	if(s == null){
		if($("#profile_editor").is(":visible") == true){
			$("#profile_editor").slideUp();
		}else{
			show_pimper('principal');
			$("#profile_editor").slideDown();
			$(".profile_editor_menu li").removeClass('pro_edit_active');	
			$(".profile_editor_menu li:first-child").addClass('pro_edit_active');
		}
	}else{
		$(".profile_editor_content").html('<div align="center" class="loading" style="position:absolute;left:350px;top:90px"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
		$.post("http://www.imeev.com/ajax/profile_editor.php",{
			s: s
		},function(html){
			$(".profile_editor_content").html(html);
		});
	}
}
function blog_index(action,section,total){
	var first = $("#first-blog").val()*1;
	var last = $("#last-blog").val()*1;
	var conteo = $("#blog-count").val()*1;
	if(action == 'prev' && first >= 0 || action == 'next' && conteo > 0){
		$(".blog-loading").fadeIn();
		$.post("http://www.imeev.com/ajax/blog_engine.php",{
				a: action,
				s: section,
				first: first,
				last: last
			},function(html){
				switch(action){
					case 'next':
						var last_val = last+10;
						if(last_val > total){last_val = total;}
						$("#first-blog").val(first+10);
						$("#last-blog").val(last+10);
						$(".conteo").html((11+(first+10))+" a "+last_val+", de "+total);
					break;
					case 'prev':
						var last_val = last-10;
						$("#first-blog").val(first-10);
						$("#last-blog").val(last-10);
						$(".conteo").html((11+(first-10))+" a "+last_val+", de "+total);
					break;
				}
				$("#blog-entry-list").html(html);
				$(".blog-loading").fadeOut();
			}
		);
	}
}
function confirmfirst_del(goto,what){
	Sexy.confirm('&iquest;Est&aacute;s seguro/a de eliminar '+what+'?', {onComplete :
		function(resp){
			if(resp == true){location.href = goto;}
		}
	});
}
function confirm_first(goto,what){
	Sexy.confirm('&iquest; Est&aacute;s seguro/a de	'+what+'?', {onComplete :
		function(resp){
			if(resp == true){location.href = goto;}
		}
	});
}
function letsgo(where,from){
	location.href = where+$(from).val();
}
function edit_tab(id,action){
	if($("#tabcontent-"+id).is(":visible") == true){
		$("#tabcontent-"+id).hide();
		$("#edittab-"+id).show();
	}else{
		if(action == 'cancel'){
			$("#edittab-"+id).hide();
			$("#tabcontent-"+id).show();
		}else{
			var title = $("#edit-tab-title-"+id).val();
			var content = $("#edit-tab-content-"+id).val();
			if(content == ''){
				content = tinyMCE.activeEditor.getContent();
			}
			if(title.length == 0 || title.length > 25){Sexy.alert('El t&iacute;tulo de la pesta&ntilde;a no debe estar vac&iacute;o o contener mas de 25 caracteres.');}
			if(content.length == 0){Sexy.alert('El contenido de la pesta&ntilde;a no debe estar vac&iacute;o.');}
			if(title.length > 0 && title.length <= 25 && content.length > 0){
			$.post("http://www.imeev.com/ajax/tab_engine.php?a=edit",{
				   id: id,
				   content: content,
				   title: title
				  },function(html){
						$("#edittab-"+id).hide();
						$("#tabcontent-"+id).html(html);
						$("#tab-"+id).text(title);
						$("#tabcontent-"+id).show();
					}
				);
			}
		}
	}
}
function delete_tab(id){
	Sexy.confirm('&iquest;Estas seguro(a) de eliminar esta pesta&ntilde;a?', {onComplete: 
          function(resp) { 
			if(resp == true){
				$.ajax({
					type: "POST",
					url: "http://www.imeev.com/ajax/tab_engine.php?a=delete",
					data: "id="+id,
					cache: false,
					success: function(html){
						$("#tab-"+id).hide();
						$("#content_"+id).hide();
						$("#tab-1").click();
					}
				});
			}
		  }
	});
}
function groupValidate(){
	var group_name = $("#group-name").val();
	var desc_corta = $("#desc_corta").val();
	var desc_larga = $("#desc_larga").val();
	var gurl = $("#gurl").val();
	
	if(group_name.length == 0){
		Sexy.alert('Introduce un nombre para tu Grupo.');
		$("#group_name").focus();
		return false;	
	}
	if(desc_corta.length == 0){
		Sexy.alert('Introduce una descripci&oacute;n corta para tu Grupo.');
		$("#desc_corta").focus();
		return false;	
	}
	if(desc_larga.length == 0){
		Sexy.alert('Introduce una descripci&oacute;n larga para tu Grupo.');
		$("#desc_larga").focus();
		return false;	
	}
}
function tabValidate(){
	var tab_title = $("#tab-title").val();	
	//var tab_content = $("#tab-content").val();
	var tab_content = tinyMCE.activeEditor.getContent();
	if ((tab_title.length == 0) || (tab_title.length > 25)) {
		Sexy.alert("El t&iacute;tulo de la pesta&ntilde;a no debe estar vac&iacute;o o contener mas de 25 caracteres.");
		$("#tab-title").focus();
		return false;
	}
	if (tab_content.length == 0) {
		Sexy.alert("El contenido de la pesta&ntilde;a no debe estar vac&iacute;o.");
		$("#tab-content").focus();
		return false;
	}
}
function load_more_things(lastid,uid,what){
	$(".things").html('<div align="center" class="loading" style="padding:5px"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
	if(lastid > 0){
		$.ajax({
			type: "POST",
			url: "http://www.imeev.com/ajax/load_more_things.php",
			data: "lastid="+ lastid + "&uid=" + uid + "&w=" + what,
			cache: false,
			success: function(html){
				$("#more-actions").append(html);
				$("#more"+lastid).remove(); // removing old more button
			}
		});
	}else{
		$(".things#more"+lastid).remove();// no results
	}
}
function apply_profile_style(sty,uid){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/profile_system.php",
		data: "style="+sty,
		cache: false,
		success: function(html){
			if(sty == 0){
				$("#content_act").remove();
				$(".content_act").remove();
				$("#content_1").html('<div id="activities-holder"></div>');
				$("#activities-holder").load("http://www.imeev.com/ajax/load_more.php?uid="+uid);
			}else{
				$("#content_1").html(html).fadeIn('slow');
			}
		}
	});
}
function shield_down(histid){
	$(".protected-"+histid).show();
	$(".protected-msg-"+histid).remove();
}
function display_class(clase){
	if($("."+clase).is(":visible") == true){
		$("."+clase).slideUp();
	}else{
		$("."+clase).slideDown();	
	}
}
function display_id(id){
	if($("#"+id).is(":visible") == true){
		$("#"+id).slideUp();
	}else{
		$("#"+id).slideDown();	
	}
}
function show_poll_votes(pid){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/poll_system.php",
		data: "poll_id="+pid+"&a=viewresults",
		cache: false,
		success: function(html){
			$("#poll-"+pid).html(html).slideDown(500);
				if(typeof window.reloadbar == 'function'){
				setTimeout(function(){reloadbar();},500);
			}
		}
	});
}
function show_poll(pid){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/poll_system.php",
		data: "poll_id="+pid+"&a=viewpoll",
		cache: false,
		success: function(html){
			$("#poll-"+pid).html(html).slideDown(500);
				if(typeof window.reloadbar == 'function'){
					setTimeout(function(){reloadbar();},500);
			}

		}
	});	
}
function create_poll(grupo) {
	var question = $("#question").val();
	var opciones = $("input[name='opcion']").serializeArray();
	var estado = $(".comment-textarea").val();
	var lugar = $("#lugar").val();
	var direccion = $("#direccion").val();
	var coords = $("#coords").val();
	var show_coords = $("#show_coords:checked").val();
	if(question != '') {
		$("#post_poll").hide();
		$("#listo-ready").fadeIn();
		$.post("http://www.imeev.com/ajax/poll_system.php?a=create",{
			estado:estado,
			grupo:grupo,
			opcion:opciones,
			question:question,
			lugar:lugar,
			direccion:direccion,
			show_coords:show_coords,
			coords:coords
		},function(html){
			$(html).hide().prependTo("#group_activities").fadeIn("slow");
			$(html).hide().prependTo("#panel-updates-holder").fadeIn("slow");
			$(html).hide().prependTo("#activities-holder").fadeIn("slow");
			$(".comment-textarea").val('');
			closeshare();
		});
	}else{
		Sexy.alert('Incluye una pregunta para tu encuesta.');
	}
}
function add_poll_option(opid){
	var nopid = (opid*1) + 1;
	$(".add_poll_option-"+opid).html('<div>'+opid+'. <input type="text" name="opcion" style="width:250px"></div><span class="add_poll_option-'+nopid+'"><div><a href="javascript:;" onclick="add_poll_option(\''+nopid+'\')">Agregar otra opci&oacute;n</a></div></span></div>');
}
function accept_friend(uid,fid,type){
	$('.loading-req-'+uid+fid).fadeIn('fast');
	$("#friend-req-"+uid+fid+" .req_msg").html('<img src="http://www.imeev.com/images/ajax-loader.gif">');
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/friend_system.php",
		data: "uid="+uid+"&fid="+fid+"&answer=yes",
		cache: false,
		success: function(html){
			switch(type){
				case 'panel':
					if(html == 'END'){
						$("#friend-req-"+uid+fid).fadeOut(500);
						$(".friends-holder").html('<div align="center" id="espacio" style="margin-bottom:85px;font-size:18px;position:relative;top:40px">No tienes solicitudes pendientes</div>');	
					}
					if(html == 'OK'){
						$("#friend-req-"+uid+fid).fadeOut();
					}
					if(html == 'ERROR'){
						Sexy.alert("Lo sentimos, ha ocurrido un error inesperado, intentalo de nuevo mas tarde.");
					}
				break;
				case 'bar':
					if(html == 'END'){
						$("#friend-req-"+uid+fid).fadeOut(500);
						$("#notif_req_spawn").html('<div class="notif_note" style="padding-left:3px">No tienes solicitudes pendientes</div>');	
					}
					if(html == 'OK'){
						$("#friend-req-"+uid+fid).fadeOut();
					}
					if(html == 'ERROR'){
						Sexy.alert("Lo sentimos, ha ocurrido un error inesperado, intentalo de nuevo mas tarde.");
					}
				break;
			}
			$('.loading-req-'+uid+fid).fadeOut('fast');
		}
	});	
}
function reject_friend(uid,fid,type){
	$("#friend-req-"+uid+fid+" .req_msg").html('<img src="http://www.imeev.com/images/ajax-loader.gif">');
	$('.loading-req-'+uid+fid).fadeIn('fast');
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/friend_system.php",
		data: "uid="+uid+"&fid="+fid+"&answer=no",
		cache: false,
		success: function(html){
			switch(type){
				case 'panel':
					if(html == 'END'){
						$("#friend-req-"+uid+fid).fadeOut(500);
						$(".friends-holder").html('<div align="center" id="espacio" style="margin-bottom:85px;font-size:18px;position:relative;top:40px">No tienes solicitudes pendientes</div>');	
					}
					if(html == 'OK'){
						$("#friend-req-"+uid+fid).fadeOut();
					}
					if(html == 'ERROR'){
						Sexy.alert("Lo sentimos, ha ocurrido un error inesperado, intentalo de nuevo mas tarde.");
					}
				break;
				case 'bar':
					if(html == 'END'){
						$("#friend-req-"+uid+fid).fadeOut(500);
						$("#notif_req_spawn").html('<div class="notif_note" style="padding-left:3px">No tienes solicitudes pendientes</div>');	
					}
					if(html == 'OK'){
						$("#friend-req-"+uid+fid).fadeOut();
					}
					if(html == 'ERROR'){
						Sexy.alert("Lo sentimos, ha ocurrido un error inesperado, intentalo de nuevo mas tarde.");
					}
				break;
			}
			$('.loading-req-'+uid+fid).fadeOut('fast');
		}
	});	
}
function show_video(id,histid,w,h){
	if(w == '580' && h == '320')
		$(".share-desc-"+histid).css({'width':'570px','margin-top':'5px'});
	else if(w == '470' && h == '280')
		$(".share-desc-"+histid).css({'width':'450px','margin-top':'5px'});
	else
		$(".share-desc-"+histid).css({'width':'690px','margin-top':'5px'});
	//PANEL V3
	if(w == 0 || w == null){w = '580';}
	if(h == 0 || h == null){h = '320';}
	//PANEL V4
	//if(w == null){w = '650';}
	//if(h == null){h = '320';}
	$("."+id+"_"+histid).html('<iframe src="http://www.imeev.com/tv/v/?id='+id+'&autoplay=true" width="'+w+'" height="'+h+'" frameborder="0"></iframe>');
	if(typeof window.reloadbar == 'function'){
		//setTimeout(function(){reloadbar();},500);
	}
}
function show_embed(histid,w,h,url){
	if(w == '580' && h == '320')
		$(".share-desc-"+histid).css({'width':'570px','margin-top':'5px'});
	else if(w == '470' && h == '250')
		$(".share-desc-"+histid).css({'width':'450px','margin-top':'5px'});
	else
		$(".share-desc-"+histid).css({'width':'690px','margin-top':'5px'});
	//PANEL V3
	if(w == 0 || w == null){w = '580';}
	if(h == 0 || h == null){h = '320';}
	//PANEL V4
	//if(w == 460 ){w = '580';}
	//if(h == 250){h = '300';}
	$(".embed_"+histid).html('<object width="'+w+'" height="'+h+'"><param name="movie" value="'+url+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+url+'" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'" allowscriptaccess="always" allowfullscreen="true"></embed></object>');	
	if(typeof window.reloadbar == 'function'){
		//setTimeout(function(){reloadbar();},500);
		//reloadbar();
	}
}
function nomorechanges(){
	setTimeout(function(){
		$("#changes").slideUp();			
	},1000);
}
function show_more_acts(id){
	$("#showmore-"+id).hide();
	$("#"+id).slideDown(500);
}
function comment(id,tipo){
	$(".commentbutton").addClass("hide");
	$(".loading").fadeIn(500);
	var comment = $("#comment-textarea").val();
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/publish_comment.php",
		data: "id="+id+"&tipo="+tipo+"&comentario="+comment,
		cache: false,
		success: function(html){
			$(html).hide().prependTo("#comment-spawn").fadeIn("slow");
		}
	});	
	$("#comment-textarea").val('');
	$(".loading").fadeOut(500);
	$(".commentbutton").removeClass("hide");
	$(".nocomments").hide();
}
function show_more_minicomments(histid){
	$(".more-mini-"+histid).html('<div align="left" class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/more_minicomments.php",
		data: "histid="+histid,
		cache: false,
		success: function(html){
			$(".more-mini-"+histid).hide();
			$(".more-mini-holder-"+histid).html(html);
		}
	});
}
function show_more_group_minicomments(histid,gid){
	$(".more-mini-"+histid).html('<div align="left" class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/more_minicomments.php",
		data: "histid="+histid+"&grupo="+gid,
		cache: false,
		success: function(html){
			$(".more-mini-"+histid).hide();
			$(".more-mini-holder-"+histid).html(html);
		}
	});
}
function edit_top(whatdo,top){
	switch(whatdo){
		case 'show':
			$("#friends_top_pop").show();
			change_top(top);
		break;
		case 'hide':
			$("#friends_top_pop").hide();
		break;
	}
}
function change_top(top){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/user_options.php?type=load_top",
		data: "top="+top,
		cache: false,
		success: function(html){
			$(".friend_top_list").html(html);
		}
	});
}
function delete_post(pid,topic,isgid){
	if(isgid == 'true'){ingroup = 'true';}else{ingroup = 'false';}
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/forum_options.php?a=remove_post&ingroup="+ingroup,
		data: "postid="+pid+"&topic="+topic,
		cache: false,
		success: function(html){
			$('.post'+pid).fadeOut();
		}
	});
}
function edit_post(pid,isgid){
	if($(".post-body"+pid).is(":visible") == true){
		$(".post-body"+pid).hide();
		$("#edit-post"+pid).show();	
		$(".edit-button"+pid).text("Guardar");
	}else{
		var postbody = $(".edit-post"+pid).val();
		//alert(postbody);
		if(isgid == 'true'){ingroup = 'true';}else{ingroup = 'false';}
		$.ajax({
			type: "POST",
			url: "http://www.imeev.com/ajax/forum_options.php?a=update_post&ingroup="+ingroup,
			data: "postid="+pid+"&cuerpo="+postbody,
			cache: false,
			success: function(html){
				$("#edit-post"+pid).hide();
				$(".post-body"+pid).html(html);
				$(".post-body"+pid).show();	
				$(".edit-button"+pid).text("Editar");
				$(".post-body"+pid+" a").embedly({maxWidth: 675, maxHeight: 350, wrapElement: 'div'});
			}
		});
	}
}
function trend_add(trend,target) {
	var word = /\B[#]([a-zA-Z0-9_]{1,20})/;
	var old=$("#"+target).val();
	var content=old.replace(word,trend);
	
	$("#"+target).val(content);
	$("#mentions").hide();
	$("#mentions").html('');
	$("#"+target).focus();
}
function mention_add(username,target) {
	var word = /\B[@]([a-zA-Z0-9_]{1,20})/;
	var old=$("#"+target).val();
	var content=old.replace(word,username);
	
	$("#"+target).val(content);
	$("#mentions").hide();
	$("#mentions").html('');
	$("#"+target).focus();
}
function change_img_title(){
	var uid = $("#uid").val();
	var Id =  $(this).attr("id");
	var current = $(this).val();
	var previous = $(".photo_"+Id).val();
	//alert(previous+'->'+current+' ID:'+Id+' UID:'+uid);
	if(current != previous){
		$('#loading-'+Id).fadeIn();
		$.post("http://www.imeev.com/ajax/photos_ajax.php",{a: 'ptitle',uid: uid,imgid: Id,data: current},
		 function(html){
				$('#loading-'+Id).fadeOut();
		});
	}
}
	function updatemood(uid){
		var estado = $('#estado').val();
		var mood_text = $('#mood_text').val();
		var emoticon_id = $("#emoticon_id").val();
		var estado_past = $('#estado_past').val();
		var mood_text_past = $('#mood_text_past').val();
		var emoticon_id_past = $("#emoticon_id_past").val();
		var dynamic_url = $("#dynamic_url:checked").val();
		var protected = $("#protected").val();
		var lugar = $("#lugar").val();
		var direccion = $("#direccion").val();
		var coords = $("#coords").val();
		var show_coords = $("#show_coords:checked").val();
		if(dynamic_url == null){dynamic_url = 0;}
		var social_fbk = $(".socialfbk").val();
		var social_twr = $(".socialtwr").val();
		var social_tb = $(".socialtb").val();
		//Musica
		var song = $(".share-song").val();
		var song_title = $("#song_title").val();
		var song_author = $("#song_author").val();
		var song_album = $("#song_album").val();
		//Posible link?
		var linkurl = $("#linkurl").val();
		var share_link = $("#share-link").val();
		var url_title = $("#url-title").val();
		var url_desc = $("#url-desc").val();
		var video_src = $("#video-src").val();
		var thumbid = $("#thumbid").val();
		
		$.post("http://www.imeev.com/ajax/mood.php",{
				uid: 			uid,
				estado: 		estado,
				dynamic_url: 	dynamic_url,
				protected: 		protected,
				social_fbk: 	social_fbk,
				social_twr: 	social_twr,
				social_tb: 		social_tb,
				lugar: 			lugar,
				direccion: 		direccion,
				coords: 		coords,
				show_coords: 	show_coords,
				linkurl: 		linkurl,
				share_link: 	share_link,
				url_title: 		url_title,
				url_desc: 		url_desc,
				video_src: 		video_src,
				thumbid: 		thumbid,
				music:			song,
				song_title: 	song_title,
				song_author:	song_author,
				song_album:		song_album
			  },
			 function(html){
				//$("#panel-updates-holder").load("http://www.imeev.com/includes/actividades_beta.php?type=friends");
				$("#panel-updates-holder").prepend(html);
				var icon = $(this).attr("src");
				$("#moodicon").attr("src",icon);
				$("#moodspan").text($("#mood_text").val());
				//Cufon.replace('.post-title',{fontFamily:'Gnuolane Free'});
				$(".comment-textarea,.mood_comment_textarea").elastic();
			}
		);
		tb_remove();
	}
	$("#listo").live("click",function(){
		$("#listo").attr("disabled",true);
		$("#estado").attr("disabled",true);
		$("#listo-ready").fadeIn();
		$(".more-share-options,.protected").hide();
		setTimeout(function(){
			$("#listo-ready").fadeOut('normal',function(){
				closeshare();
				$("#estado").val('');
				$("#listo").attr("disabled",false);
				$("#estado").attr("disabled",false);
				$(".more-share-options,.protected").show();								  
			});
		},1000);								  
	});
	function removemood(mid,uid,from){
		var dataString = 'remove='+ mid + '&uid=' + uid;
		$.ajax({
			type: "POST",
			url: "http://www.imeev.com/ajax/mood.php",
			data: dataString,
			cache: false,
			success: function(){
				//var icon = $(this).attr("src");
				/*$("#friend-moods-div").html('<div align="center" style="margin-top:50px"><img src="http://www.imeev.com/images/ajax-loader.gif"></div>');
				if(from == 0){
					$("#friend-moods-div").load("http://www.imeev.com/includes/friends_moods.php");
				}else{
					$("#friend-moods-div").load("http://www.imeev.com/includes/friends_moods.php?id="+uid);		
				}*/
				$(".linked-mood-"+mid).fadeOut();
				$("#moodid-"+mid).fadeOut();
				$(".linked-mood-div-"+mid).fadeIn();				
			}
		});
		tb_remove();
	}
function share_option(id){
	$("#share-box,.share-box").html('<div align="center"><img src="http://www.imeev.com/images/ajax-loader.gif" /></div>');
	switch(id) {
		case 'photo':
			$("#listo").hide();
			$(".uploadbutton").hide();
			$("#comment-profile").hide();
			$("#comment-group").hide();
			$("#upload_video").hide();	
			$("#upload_photo").show();	
			$(".comment-profile").hide();
			$("#post_poll").hide();
		break;
		case 'video':
			$("#listo").hide();
			$("#upload_video").show();	
			$("#upload_photo").hide();
			$("#comment-profile").hide();
			$(".comment-profile").hide();
			$("#comment-group").hide();
			$(".uploadbutton").hide();
			$("#post_poll").hide();
			break;
		case 'poll':
			$("#listo").hide();
			$("#post_poll").show();
			$("#upload_video").hide();	
			$("#upload_photo").hide();	
			$("#comment-profile").hide();
			$(".comment-profile").hide();
			$("#comment-group").hide();
			$(".uploadbutton").hide();
		break;
		default:
			$("#comment-group").show();
			$(".uploadbutton").hide();
			$("#listo").show();
			$("#comment-profile").show();
			$("#upload_video").hide();	
			$("#upload_photo").hide();	
			$(".comment-profile").hide();
			$("#post_poll").hide();
			break;
	}
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/share-options.php",
		data: "share="+id,
		cache: false,
		success: function(html){
			$("#share-box,.share-box").html(html);	
			//Cufon.replace('.share-header',{fontFamily:'Gnuolane Free'});
		}
	});
}
function group_share_option(id){
	$("#share-box").html('<div align="center"><img src="http://www.imeev.com/images/ajax-loader.gif" /></div>');
	if(id == 'photo' ||  id == 'link' || id == 'poll'){
			$("#comment-group").hide();
			$(".uploadbutton").show();
	}else{
			$(".uploadbutton").hide();
			$("#comment-group").show();
	}
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/share-options.php",
		data: "share="+id,
		cache: false,
		success: function(html){
			$("#share-box").html(html);	
			//Cufon.replace('.share-header',{fontFamily:'Gnuolane Free'});
		}
	});
}
function char_limit(Id){
	$(".pre"+Id).hide();
	$("#"+Id).show();
}
function hidemeandshow(ocultar,mostrar){
	$(ocultar).hide();
	$(mostrar).show();
}
function hideme_slideup(classid){
	$(classid).slideUp();
}
function change_wall(uid,wall,tipo){
		$.ajax({
			type: "POST",
			url: "http://www.imeev.com/ajax/change_wall.php",
			data: "uid="+uid+"&wall="+wall+"&tipo="+tipo,
			cache: false,
			success: function(html){
				if(html == 'nowidget'){
					Sexy.alert('Lo sentimos, pero para cambiar tu fondo necesitas comprar la funcion de Fondo Personalizado.');	
				}
				if(html == 'OK'){
					$('#wall-image').attr('src','http://www.imeev.com/images/themes/thumb_'+wall+'.jpg');
					Sexy.alert('Fondo aplicado!\nNo es necesario guardar los cambios.');	
				}
			}
		});
}
function buywidget(uid,wid,gid){
	//ARREGLAR!!!!
	$('.widget-'+wid+' .plus').html('<img src="/images/ajax-loader.gif" border="0">');
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/buywidget.php",
		data: "uid="+uid+"&wid="+wid+"&gid="+gid,
		cache: false,
		success: function(html){
			if(html == 'nopoints'){Sexy.alert('Lo sentimos, no tienes puntos suficientes');$('#widget-'+wid+' .plus').html('+');}else{
				$('.widget-'+wid).fadeOut();
				location.reload();
			}
		}
	});
}
//REMOVER LA IMAGEN DE UN EVENTO EN UNA AGENDA
function remove_event_image(evento,uid){
	var dataString = 'event='+evento+'&uid='+uid;
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/change_event_img.php?action=remove",
		data: dataString,
		cache: false,
		success: function(html){
			$("#delete_event_image").hide();
			$("#event_image_span").html(html);
		}
	});
}
//REEMPLAZA <3 POR &hearts;
function heart(texto){
	var ret = texto.replace("<3","&hearts;");
	return ret;
}
//MUESTRA MAS ESTADOS DE ANIMO EN FRIENDS_MOODS
function show_more_moods(mood_id){
	$("#same-user-moods-"+mood_id).slideDown("slow");
	$("#same-user-mood-option-"+mood_id).hide();
}
//MUESTRA EL EVENTO EN EL PANEL DE CONTROL, CONVOCADO DESDE EL CALENDARIO
function show_event(anio,mes,dia,uid){
	mes = (mes*1)+1;
	$("#showevent").html('<div align="center" style="margin:5px" class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/load_dates.php",
		data: "action=loadevents&id="+uid+"&anio="+anio+"&mes="+mes+"&dia="+dia,
		cache: false,
		success: function(html){
				$("#showevent").html(html);
		}
	});
}
//AGREGA AL USUARIO A UN GRUPO
function add_group(gid,uid,sig){
	$("#related-group-"+gid+" #popular-options").hide();
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/add_group.php",
		data: "uid="+uid+"&gid="+gid+"&sig="+sig,
		cache: false,
		success: function(html){
			$(this).html('');
			$("#related-group-"+gid+" #popular-options").fadeIn(500,function(){
				if(html == 'OK')
					$(this).html("<b>Te has unido.</b>");
				else
					$(this).html("<b>Ha ocurrido un error.</b>");
			});																  
		}
	});
}
//REMUEVE COMMENTS
function remove_comment(id){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/remove_engine.php",
		data: "id="+id+"&a=comment",
		cache: false,
		success: function(){
			$(".comment-"+id).fadeOut().remove();
		}
	});
}
function remove_comment_adv(id,type,linker){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/remove_engine.php",
		data: "id="+id+"&a="+type,
		cache: false,
		success: function(){
			$(linker+id).fadeOut().remove();
		}
	});
}
function remove_comment_pro(id,type,linker,action){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/remove_engine.php",
		data: "id="+id+"&a="+action+"&type="+type,
		cache: false,
		success: function(){
			$(linker+id).fadeOut().remove();
		}
	});
}
function remove_history(id,grupo){
		if(grupo > 0){
			tb_show('Eliminar u Ocultar','http://www.imeev.com/popups/delete.php?hid='+id+'&group='+grupo+'&height=124&width=400&modal=true');	
		}else{
			tb_show('Eliminar u Ocultar','http://www.imeev.com/popups/delete.php?hid='+id+'&height=124&width=400&modal=true');	
		}
}
function remove_history_comment(id){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/remove_engine.php",
		data: "id="+id+"&a=historial_comment",
		cache: false,
		success: function(){
			$(".mini-comment-"+id).fadeOut().remove();
			$("#mini-comment-"+id).fadeOut().remove();
		}
	});
}
function remove_group_comment(id){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/remove_engine.php",
		data: "id="+id+"&a=group_comment",
		cache: false,
		success: function(){
			$(".comment-"+id).fadeOut();
		}
	});
}
function remove_minicomment(id,type){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/remove_engine.php",
		data: "id="+id+"&a=mini-comment&type="+type,
		cache: false,
		success: function(){
			$("#mini-comment-"+id).fadeOut();
		}
	});
}
function Change_This(aList)
{
	var x=document.getElementById("otro")
	if(aList.selectedIndex == 0){
		x.disabled=false
	}else{
		x.disabled=true;
		x.value = '';
	}

}
function cargaragenda(uid){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/load_dates.php",
		data: "action=loadcalendar&id="+uid,
		cache: false,
		dataType: "json",
		success: function(calendarEvents){ 
			$("#calendar-event-list").datepicker({
				changeYear: true,
				changeMonth: true,
				// [rows, columns] if you want to display multiple calendars.                         
				numberOfMonths: [1, 1],
				showCurrentAtPos: 0,
				beforeShowDay: function (date){
					for (i = 0; i < calendarEvents.length; i++) {
					  	if (date.getMonth() == calendarEvents[i][0] - 1 
					  	&& date.getDate() == calendarEvents[i][1]
					  	&& date.getFullYear() == calendarEvents[i][2]) {
							return [true,"ui-datepicker-current-day ui-state-active",calendarEvents[i][3],uid]; 
						}
					}
					return [true, "",false,uid];//enable all other days
				}
			});
		}
	});
}
function show_friends(type,uid,orden){
	if(type == 'panel_top'){
		$("#friends-frame").html('<div align="center" style="margin:5px 0px 0px 14px;width:163px" class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif"> Guardando amigos...</div>');
	}else{
		$("#friends-frame").html('<div align="center" style="margin:5px" class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando amigos...</div>');
	}
	$.post("http://www.imeev.com/ajax/show_friends.php",
		{type: type, uid: uid,orden: orden},
		 function(html){
			$("#friends-frame").html(html);
		}
	);
}
function profile_page(uid,url){
	$(".ante_loader").load("http://www.imeev.com/profile_pages/"+url+".php");
	return false;	
}
function comment_mood(comment_id,cambio){
	$("#mood_comment_inputs_"+comment_id).toggle();
	if(cambio == 0){
		$("#mood_comment_frame_"+comment_id).toggleClass("mood_comment_frame");
	}
}
function load_cats_gift_shop(uid){
	var categoria = $("#gift_cats_shop").val();
	$("#gift_lastid").val('');
	$("#gifts_load").load('http://www.imeev.com/gifts_loader.php?uid=' + uid + '&cat=' + categoria);
}
function comment_mood_cancel(comment_id,cambio){
	$("#mood_comment_inputs_"+comment_id).hide();
	if(cambio == 0){
		$("#mood_comment_frame_"+comment_id).toggleClass("mood_comment_frame");
	}
}
function comment_historial(comment_id,comments,feed){
	$("#historial_comment_inputs_"+comment_id).toggle();
	comments = $("#historial_comment_comments_"+comment_id).val();
	if(comments == 0 && feed != 1)
		$("#historial_comment_frame_"+comment_id).toggleClass("mood_comment_frame");
}
function comment_historial_cancel(comment_id,comments,feed){
	$("#historial_comment_inputs_"+comment_id).hide();
	if(comments == 0 && feed != 1){
		$("#historial_comment_frame_"+comment_id).toggleClass("mood_comment_frame");
	}
}
function load_more_videos(lastvid,user){
	$("#morevids"+lastvid).html('<div align="center" class="loading" style="padding:5px"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
	if(lastvid > 0){
		$.ajax({
			type: "POST",
			url: "http://www.imeev.com/ajax/load_more_videos.php",
			data: "vid="+ lastvid + "&uid=" + user,
			cache: false,
			success: function(html){
				$("#last-vids").append(html);
				$("#morevids"+lastvid).remove(); // removing old more button
			}
		});
	}else{
		$("#morevids"+lastvid).remove();// no results
	}
}
function load_more_group_videos(lastvid,group){
	$("#morevids"+lastvid).html('<div align="center" class="loading" style="padding:5px"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
	if(lastvid > 0){
		$.ajax({
			type: "POST",
			url: "http://www.imeev.com/ajax/load_more_videos.php",
			data: "vid="+ lastvid + "&gid=" + group,
			cache: false,
			success: function(html){
				$("#last-vids").append(html);
				$("#morevids"+lastvid).remove(); // removing old more button
			}
		});
	}else{
		$("#morevids"+lastvid).remove();// no results
	}
}
function load_more_activities(lastid,user,panel,tipo,filtro){
	$("#lasthistid").val(lastid);
	$("#more"+lastid).html('<div align="center" class="loading" style="padding:5px"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
	if(lastid > 0){
		var php = '';
		if(panel == '0'){php = 'includes/actividades_beta.php?type='+tipo+'&filter='+filtro;}else{php = 'ajax/load_more.php?type='+tipo+'&filter='+filtro;}
		$.ajax({
			type: "POST",
			url: "http://www.imeev.com/"+php,
			data: "lastmsg="+ lastid + "&uid=" + user,
			cache: false,
			success: function(html){
				$("#last-activities").append(html);
				$("#more"+lastid).remove(); // removing old more button
				//Cufon.replace('.post-title',{fontFamily:'Gnuolane Free'});
				$(".in_social").tipsy({gravity: 's'});
				$(".comment-textarea,.mood_comment_textarea").elastic();
			}
		});
	}else{
		$("#more"+lastid).remove();// no results
	}
}
function load_more_group_acts(lastid,group,tipo,filtro){
	$("#lasthistid").val(lastid);
	$("#more"+lastid).html('<div align="center" class="loading" style="padding:5px"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
	if(lastid > 0){
		$.ajax({
			type: "POST",
			url: "http://www.imeev.com/includes/group_activities.php?type="+tipo+"&filter="+filtro,
			data: "lastmsg="+ lastid + "&gid=" + group,
			cache: false,
			success: function(html){
				$("#last-activities").append(html);
				$("#more"+lastid).remove(); // removing old more button
				//Cufon.replace('.post-title',{fontFamily:'Gnuolane Free'});
				$(".in_social").tipsy({gravity: 's'});
				$(".comment-textarea,.mood_comment_textarea").elastic();
			}
		});
	}else{
		$("#more"+lastid).remove();// no results
	}
}

function next_gift_step(step){
	switch(step){
		case '1':
				$(".step_1").fadeIn(1000);
				$(".step_2").hide();
		break;
		case '2':
			if($("#gift_lastid").val() == 0 || $("#gift_lastid").val() == ""){
				Sexy.alert("Elige un regalo!");
			}else{
				$(".step_1").hide();
				$(".step_2").fadeIn(1000);
				$(".step_3").hide();
			}
		break;
		case '3':
			if($("#para").val() == 0){
				Sexy.alert("Elige un amigo!");
			}else{
				$(".step_2").hide();
				$(".step_3").fadeIn(1000);
				$(".step_4").hide();
			}
		break;
		case '4':
			$(".step_3").hide();
			$(".step_4").fadeIn(1000);
			$("#gift_para").text($("#para :selected").text());	
		break;
	}
}
function gift_box_click(boxid,precio_caja,caja,nombre){
	var precio_regalo = $("#gift_price").val();
	var total = (precio_caja * 1)+(precio_regalo * 1);
	$("#gift_box_img").attr("src","http://www.imeev.com/images/gifts/boxes/"+ caja + ".png");
	$("#gift_total").text(total);
	$("#total_price").val(total);
	$("#gift_box_price_val").text(precio_caja);
	$("#box_price").text(precio_caja);
	$("#gift_box_title").text(nombre);
}
function select_gift(giftid,precio,category,regalo,nombre,tipo){	
	var lastid = $("#gift_lastid").val();
	$("#gift_inner_"+lastid).toggleClass("gift_outer_click");
	$("#gift_lastid").val(giftid);
	$("#gift_inner_"+giftid).toggleClass("gift_outer_click");
	$("#gift_total").val(precio);
	$("#gift_price").val(precio);
	$("#gift_price_val").text(precio);
	var precio_regalo = $("#gift_price").val();
	var precio_caja = $("#gift_box_price_val").text();
	var total = (precio_caja * 1)+(precio_regalo * 1);
	$("#gift_total").text(total);
	$("#total_price").val(total);
	$("#gift_title").text(nombre);
	if(tipo == 0){
		$("#gift_img").attr("src","http://www.imeev.com/images/gifts/" + category + "/big/" + regalo);
	}else{
		$("#gift_img").attr("src","http://www.imeev.com/custom_gifts/" + category + "/big/" + regalo);
	}
}
function slide_plz(id,name){
	if($("#"+id).css('display') == 'none'){
		$("#"+id).slideDown();
		$("#"+id+"_click").html('&#9660; '+name);
	}else{
		$("#"+id).slideUp();
		$("#"+id+"_click").html('&#9658; '+name);
	}
}
function closeshare(){
	console.log('Shared Closing...');
	$("#share-js").fadeOut();
	$(".share-js").fadeOut();
	$("#share-box").html('');
	$(".uploadbutton").hide();
	$("#upload_video").hide();	
	$("#listo").show();
	$("#comment-profile").show();
	$("#comment-group").show();
	$("#listo-ready").hide();
	$("#post_poll").hide();
	console.log('Shared closed');
}
$(document).ready(function (){
	$(window).bind('keypress', function(e) {
		var code = (e.keyCode ? e.keyCode : e.which);
		if(code == 27)
			tb_remove();
	});
	$("#networks").live("change",function(){
		var soc_url = $("#networks option:selected").attr('url');
		var soc_name = $("#networks").val();
		if( soc_url == null){
			$(".add_soc").addClass('hide');	
			$("#add_soc_spawn").html('');
			$("#soc_icon").attr('src','http://www.imeev.com/images/0.png');
		}else{
			$(".add_soc").removeClass('hide');
			spawn = soc_url.replace('%s','<input type="text" class="add_soc_username" />');
			$("#add_soc_spawn").html(spawn);
			$("#soc_icon").attr('src','http://www.imeev.com/images/social/icons/' + soc_name + '_16.png');
		}
	});
	$(".panel-social-icon").live("click",function(){
		var Id = $(this).attr('id');
		if($(".social"+Id).val() == '1'){
			$(this).addClass('opacity-50');
			$(".social"+Id).val('0');
		}else{
			$(this).removeClass('opacity-50');
			$(".social"+Id).val('1');
		}
	});
	$(".protected").live("click",function(){
		if($("#protected").val() == '1'){
			$(this).addClass('opacity-50');
			$(this).attr('title','El contenido no estar&aacute; protegido contra menores de edad.');
			$("#protected").val('0');
		}else{
			$(this).removeClass('opacity-50');
			$(this).attr('title','El contenido estar&aacute; protegido contra menores de edad.');
			$("#protected").val('1');
		}
	});
	
	$(".filter-list ul li").live("click",function(){
		var donde = $(this).attr('donde');
		var tipo = $(this).attr("id");
		var destino = '';
		var gid = $(this).attr('gid');
		$(".filter-list ul li").css('background','#EFEFEF');
		$(this).css('background','#CCD7E0');
		$("#updates-type a").removeClass('sel');
		switch(donde) {
			case 'perfil':
				tipo = tipo + '&uid=' + $(this).attr('uid');
				destino = 'ajax/load_more';
				type = 'mix';
				var espacio = 'activities-holder';
			break;
			default:
				destino = 'includes/actividades_beta';
				type = 'friends';
				var espacio = 'historial-field';
			break;
			case 'grupo':
				destino = 'includes/group_activities';
				type = 'all';
				var espacio = 'group_activities';
				tipo = tipo+'&gid='+gid;
			break;
		}
		$("#updates-type a#"+type).addClass('sel');
		$("#"+espacio).html('<div align="center" class="loading" style="padding:20px 0px"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
		$('#'+espacio).load("http://www.imeev.com/"+destino+".php?type="+type+"&filter="+tipo,function(){
			//Cufon.replace('.post-title',{fontFamily:'Gnuolane Free'});		
			$(".in_social").tipsy({gravity: 's'});
			$(".comment-textarea,.mood_comment_textarea").elastic();
		});
	});
	
	$("#updates-type a").live("click",function(){
		if($(".filter-list").is(":visible") == true){
			$(".filter-option").click();	
		}
		var destino = '';
		var tipo = $(this).attr('id');
		var donde = $(this).attr('donde');
		var gid = $(this).attr('gid');
		switch(donde) {
			case 'perfil':
				destino = 'ajax/load_more';
				tipo = tipo + '&uid=' + $(this).attr('uid');
				var espacio = 'activities-holder';
			break;
			case 'panel':
			default:
				destino = 'includes/actividades_beta';
				var espacio = 'historial-field';
			break;
			case 'grupo':
				destino = 'includes/group_activities';
				var espacio = 'group_activities';
				tipo = tipo+'&gid='+gid;
			break;
		}
		$("#"+espacio).html('<div align="center" class="loading" style="padding:20px 0px"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
		$(".filter-list ul li").css('background','#EFEFEF');
		$("#updates-type a").removeClass('sel');
		$(this).addClass('sel');
		$('#'+espacio).load("http://www.imeev.com/"+destino+".php?type="+tipo,function(){
			//Cufon.replace('.post-title',{fontFamily:'Gnuolane Free'});	
			$(".in_social").tipsy({gravity: 's'});
			$(".comment-textarea,.mood_comment_textarea").elastic();
		});
	});
	$("#subscribed-bar input[type=checkbox]").click(function(){
		if ( $(this).parent('label').hasClass("listSelected") ) {
			$(this).parent('label').removeClass('listSelected');
		}else{
			$(this).parent('label').addClass('listSelected');
		}
	});
	$(".uploadbutton").live("click",function(){
		$(".uploadbutton").hide();
		$("#listo-ready").fadeIn();
	});
	$("#estadocivil").live("change",function(){
		var valor = $("#estadocivil").val();
		if(valor > 0 && valor <= 3){
			$(".relationship-with").removeClass('hide');
		}else{
			$(".relationship-with").addClass('hide');	
		}
	});
	$(".event_hover").hover(function(){
		var Id = $(this).attr("id");
		$("."+Id).fadeIn('fast',function(){
				if($("."+Id).html() == '' || $("."+Id).html() == 'undefined'){
					$("."+Id).html('<div align="left" class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
					$.ajax({
						type: "POST",
						url: "http://www.imeev.com/ajax/event_loader.php",
						data: "eid="+Id,
						cache: false,
						success: function(html){
							$("."+Id).html(html);
						}
					});
				}
		});
	},function(){
		var Id = $(this).attr("id");
		$("."+Id).fadeOut('fast');	
	});
	$("#publish-post").live("click",function(){
		//alert("YEAH!");
		$(".loading").fadeIn(400);
		var message = $("#topic_message").val();
		var uid = $("#userid").val();
		var topic = $("#topic").val();
		//alert("MENSAJE: "+message);
		$.post("http://www.imeev.com/ajax/forum_options.php?a=reply",
			{uid: uid ,topic: topic, cuerpo: message},
			function(html){
				$(html).hide().prependTo("#forum-posts").fadeIn("slow");
				$(".loading").fadeOut(400);
				$("#topic_message").val('');
			}
		);
		setTimeout(function(){
			$(".post-content a").embedly({maxWidth: 675, maxHeight: 350, wrapElement: 'div'});
		},1000);
		
	});
	$("#adjuntar-link").live('click',function(){
		var url = $("#share-link").val();
		$(".share-content").html('<div align="center" class="loading"><img src="/images/ajax-loader.gif" /> Obteniendo informaci&oacute;n del sitio...</div>');
		$.post("http://www.imeev.com/ajax/share-options.php",{url:url,share: 'fetch-site-info'},
			function(html){
				$(".share-content").html(html);																		 
			}
		);
	});
$("#estado").live("keyup",function(){
		var word = /\B[@]([a-zA-Z0-9_]{1,20})/;
		var content=$("#estado").val();
		var name= content.match(word);
		if(name == null)
			name = 0;
		if(name.length>0) {
			$("#mentions").html('<div id="espacio">Escribe el nombre de un amigo/a...</div>');
			texto = String(name).split(",");
			var dataString = 'searchword='+ texto[1];
			if(texto[1].length >=3){
				$("#mentions").css({'width':$("#estado").width()+5,'left':'3px'});
				$("#mentions").load("http://www.imeev.com/ajax/mentions.php?target=estado&t=friends&"+dataString,function(){
					$("#mentions").show();
				});
			}
				if($("#mentions").html() == '')
					$("#mentions").html('<div id="espacio">Escribe el nombre de un amigo/a...</div>');
		}else {
			$("#mentions").hide();
		}
	});
$("#profile-comment").live("keyup",function(){
		var word = /\B[#]([a-zA-Z0-9_]{1,20})/;
		var content=$("#profile-comment").val();
		var name= content.match(word);
		if(name == null)
			name = 0;
		if(name.length>0) {
			$("#mentions").html('<div id="espacio">Escribe el nombre de un Trend...</div>');
			texto = String(name).split(",");
			var dataString = 'searchword='+ texto[1];
			if(texto[1].length >=3){
					$("#mentions").load("http://www.imeev.com/ajax/mentions.php?target=profile-comment&t=trend&"+dataString,function(){
					$("#mentions").css('width',$("#profile-comment").width());
					$("#mentions").show();
				});
			}
			if($("#mentions").html() == '')
					$("#mentions").html('<div id="espacio">Escribe el nombre de un Trend...</div>');
		}else {
			$("#mentions").hide();
		}
	});
$("#estado").live("keyup",function(){
		var word = /\B[#]([a-zA-Z0-9_]{1,20})/;
		var content=$("#estado").val();
		var name= content.match(word);
		if(name == null)
			name = 0;
		if(name.length>0) {
			$("#mentions").html('<div id="espacio">Escribe el nombre de un Trend...</div>');
			texto = String(name).split(",");
			var dataString = 'searchword='+ texto[1];
			if(texto[1].length >=3){
					$("#mentions").css({'width':$("#estado").width()+5,'left':'3px'});
					$("#mentions").load("http://www.imeev.com/ajax/mentions.php?target=estado&t=trend&"+dataString,function(){
					$("#mentions").show();
				});
			}
			if($("#mentions").html() == '')
				$("#mentions").html('<div id="espacio">Escribe el nombre de un Trend...</div>');
		}else {
			$("#mentions").hide();
		}
	});
$("#estado,#profile-comment").blur(function() {
	if($("#mentions").is(":visible"))
		setTimeout(function(){
			$("#mentions").hide();
		},250);
});
$(".act_user_ava").hover(function(){
	var id = $(this).attr("histid");
	$(".user-slider-"+id).show();
},function(){
	var id = $(this).attr("histid");
	$(".user-slider-"+id).hide();	
});

$("#estado,#profile-comment").bind("focus",function() {
	if($("#mentions").html() != '')
		$("#mentions").show();
});
$("#profile-comment").live("keyup",function(){
		var word = /\B[@]([a-zA-Z0-9_]{1,20})/;
		var content=$("#profile-comment").val();
		var name= content.match(word);
		if(name == null)
			name = 0;

		if(name.length>0) {
			$("#mentions").html('<div id="espacio">Escribe el nombre de un amigo/a...</div>');
			texto = String(name).split(",");
			var dataString = 'searchword='+ texto[1];
			if(texto[1].length >=3){
				$("#mentions").load("http://www.imeev.com/ajax/mentions.php?target=profile-comment&t=friends&"+dataString,function(){
					$("#mentions").css('width',$("#profile-comment").width());
					$("#mentions").show();
				});
			}
			if($("#mentions").html() == '')
				$("#mentions").html('<div id="espacio">Escribe el nombre de un amigo/a...</div>');
		}else {
			$("#mentions").hide();
		}
	});
	$("#rvsp").live("click",function(){
		var rvsp = $("#rvsp:checked").val();
		var uid = $("#uid").val();
		var eid = $("#eid").val();
		var e_inv = $("#e_inv").val();
		$.ajax({
			type: "POST",
			url: "http://www.imeev.com/ajax/events_ajax.php?a=rvsp&eid="+eid,
			data: "uid="+ uid+"&rvsp="+rvsp,
			cache: false,
			success: function(html){
				if(e_inv == 1){
					$("#other_invited").load("http://www.imeev.com/ajax/events_ajax.php?a=other&eid="+eid);
					$("#confirmed_invited").load("http://www.imeev.com/ajax/events_ajax.php?a=confirmed&eid="+eid);
				}
			}
		});
		//alert(rvsp);
	});
	$('#photo-options').hover(function(){
		$(".photo-ops").show();   
	},function(){
		$(".photo-ops").hide();
	});
	$("#comment-profile").live("click",function(){
		$("#comment-profile").attr('disabled',true);									
		var comment_to = $("#comment-to").val();
		var comment_from = $("#comment-from").val();
		var comment = $("#profile-comment").val();
		var lugar = $("#lugar").val();
		var direccion = $("#direccion").val();
		var coords = $("#coords").val();
		var show_coords = $("#show_coords:checked").val();
		//Musica
		var song = $(".share-song").val();
		var song_title = $("#song_title").val();
		var song_author = $("#song_author").val();
		var song_album = $("#song_album").val();
		//Posible link?
		var linkurl = $("#linkurl").val();
		var share_link = $("#share-link").val();
		var url_title = $("#url-title").val();
		var url_desc = $("#url-desc").val();
		var video_src = $("#video-src").val();
		var thumbid = $("#thumbid").val();
		$.post("http://www.imeev.com/ajax/publish_profile_comment.php",
		{
			uid:			comment_from,
			fid:			comment_to, 
			comentario: 	comment,
			lugar: 			lugar,
			direccion:		direccion,
			coords:			coords,
			show_coords:	show_coords,
			linkurl:		linkurl,
			share_link: 	share_link,
			url_title: 		url_title,
			url_desc: 		url_desc,
			video_src:		video_src,
			thumbid: 		thumbid,
			music:			song,
			song_title: 	song_title,
			song_author:	song_author,
			song_album:		song_album
		},
		function(html){
			console.log('Rehabilitando boton...');
			$("#comment-profile").attr("disabled",false);
			console.log('Prepending...');
			$("#activities-holder").prepend(html);
			console.log('Vaciando caja de texto...');
			$("#profile-comment").val('');
			closeshare();
		});
	});
	$("#entry-limit,.entry-limit" ).datepicker({dateFormat:'yy-mm-dd'});

	$("#comment-profile-sect").live("click",function(){
		$("#comment-profile-sect").attr('disabled',true);									
		var comment_to = $("#comment-to").val();
		var comment_from = $("#comment-from").val();
		var comment = $("#profile-comment").val();
		$.post("http://www.imeev.com/ajax/publish_profile_comment.php",
		{uid: comment_from,fid: comment_to, comentario: comment,type: 'sect'},
		function(last){
			$("#comments-holder").html('<div align="center" class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
			setTimeout(function(){
				last = last+1;
				$("#comments-holder").load("http://www.imeev.com/ajax/load_more_comments.php?uid="+comment_to+"&from="+comment_from);
				$("#profile-comment").val('');
				$("#comment-profile-sect").removeAttr("disabled");	
			},1000);
		});
	});
	$("#comment-group").live("click",function(){
		$(".loading").fadeIn();
		$("#comment-group").attr('disabled',true);									
		var comment_to = $("#comment-to").val();
		var comment_from = $("#comment-from").val();
		var comment = $("#group-comment").val();
		//Posible link?
		var linkurl = $("#linkurl").val();
		var share_link = $("#share-link").val();
		var url_title = $("#url-title").val();
		var url_desc = $("#url-desc").val();
		var video_src = $("#video-src").val();
		var thumbid = $("#thumbid").val();
		//Musica
		var song = $(".share-song").val();
		var song_title = $("#song_title").val();
		var song_author = $("#song_author").val();
		var song_album = $("#song_album").val();
		//GPS
		var lugar = $("#lugar").val();
		var direccion = $("#direccion").val();
		var coords = $("#coords").val();
		var show_coords = $("#show_coords:checked").val();
		$.post("http://www.imeev.com/ajax/publish_comment.php",
		{
			uid: comment_from,
			id: comment_to, 
			tipo: 'group', 
			comentario: comment,
			linkurl: linkurl,
			share_link: share_link,
			url_title: url_title,
			url_desc: url_desc,
			video_src: video_src,
			thumbid: thumbid,
			music:			song,
			song_title: 	song_title,
			song_author:	song_author,
			song_album:		song_album,
			lugar: 			lugar,
			direccion: 		direccion,
			coords: 		coords,
			show_coords: 	show_coords
			
		},
		function(last){
			$("#group_activities").prepend(last);
			$("#group-comment").val('');
			$("#comment-group").removeAttr("disabled");	
			closeshare();
			$(".loading").fadeOut();
		});
	});
	$(".location_hover").live("click",function(e){
		if($("#location_box").is(":visible") == true){
			$("#location_box").hide();
		}else{
			var mx = e.pageX-520;
			var my = e.pageY-345;
			var location = $("#direccion").val();
			$("#location_box .map_here").html('<img src="http://maps.google.com/maps/api/staticmap?center='+location+'&zoom=15&size=330x110&markers=size:mid%7Ccolor:blue%7C'+location+'&path=fillcolor:0xAA000033%7Ccolor:0xFFFFFF00%7Cenc:encoded_data&sensor=true" />');
			$("#location_box").css({'top':my,'left':mx});
			$("#location_box").show();
		}
	});
	
	//PIMP v2
	$('#changecss').live('click',function(){
		var color = "#"+$("#csscolor").val();
		var colour = "background-color:"+color+" !important";
		$('div.my_header').attr('style',colour);	
		$('.tab').attr('style',colour);
		$('#whitebg').attr('style',colour);
		$("body").css("color",color);
		var bgimg = "url('"+$("#bgimg_url").val()+"')";
		$("body").css("background-image",bgimg);
	});
	$("#comment-event").live("click",function(){
		$("#comment-event").attr('disabled',true);									
		var comment_to = $("#comment-to").val();
		var comment_from = $("#comment-from").val();
		var comment = $("#event-comment").val();
		$.post("http://www.imeev.com/ajax/publish_comment.php",
		{uid: comment_from,id: comment_to, tipo: 'eventos', comentario: comment},
		function(last){
			$("#activities-holder").html('<div align="center" class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
			setTimeout(function(){
				$("#activities-holder").html(last);
				$("#event-comment").val('');
				$("#comment-event").removeAttr("disabled");	
			},1000);
		});
	});
	$("#box_image").click(function (){
		$.post("http://www.imeev.com/update_gift_status.php", {
			llave: $('#llave_gift').text()
		});
	});
	$("#send_gift").click(function (){
			if(
				($("#mypoints").text() * 1) >= ($("#total_price").text() * 1) 
			){
				return true;
			}else{
				Sexy.alert("No tienes los puntos suficientes!");	
			}
			return false;
	});
	$("#gift_frame").click(function (){ 
		if($("#para_gift").text() == $("#viendo_gift").text()){
			$("#box_image").fadeOut(500);
			setTimeout(function () {
				$("#gift_image").fadeIn(500);
			},1000);
			$("#box_caption").text("");
		}else{
			$("#box_caption").text("No puedes abrir un regalo que no es tuyo!");
		}
   });
	$('#gift_cats').change(function (){
		var categoria = $("#gift_cats").val();
		$("#gift_lastid").val('');
		$("#gifts_load").load('http://www.imeev.com/gifts_loader.php?cat=' + categoria);
	});
	$('.video-thumb a').hover(function() {
		$(this).children(".video-info").animate({bottom: '0'});								 
	},function(){
		$(this).children(".video-info").animate({bottom: '-125'});	
	});
	$('.photo-frame').hover(function() {
		$(this).children(".photo-info").animate({bottom: '0'});								 
	},function(){
		$(this).children(".photo-info").animate({bottom: '-35'});	
	});
	$(".mood_comment_publish").live("click",function(){
		var element = $(this);
		var Id = element.attr("id");
		var comment = $("#mood_comment_textarea_"+Id).val();
		var uid = $("#mood_comment_myid_"+Id).val();
		var fid = $("#mood_comment_fromid_"+Id).val();
		var comments = $("#mood_comment_comments_"+Id).val();
		//var dataString = 'comentario='+ comment + '&aid=' + Id + '&uid=' + uid + '&fid=' + fid + '&comments=' + comments;
		if(comment==''){
			Sexy.alert("Introduce tu comentario!");
		}else{
			$("#flash_"+Id).show();
			$("#flash_"+Id).fadeIn(400).html('<span  class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif" align="absmiddle"> Cargando...</span>');
			$.post("http://www.imeev.com/ajax/publish_mood_comment.php",
				    {
					 	comentario: comment,
						aid: Id,
						uid: uid,
						fid: fid,
						comments: comments
					},
				 	function(html){
					$("#mood_comment_load_"+Id).html(html);
					$("#flash_"+Id).hide();
				}
			);
		}
		return false;
	});
	$(".profile_editor_menu li").click(function(){
		$(".profile_editor_menu li").removeClass('pro_edit_active');	
		$(this).addClass('pro_edit_active');
	});
	$(".historial_comment_publish").live("click",function(){											  
		var Id = $(this).attr("id");
		$("input#"+Id).attr("disabled","disabled");
		var comment = $("#historial_comment_textarea_"+Id).val();

		var uid = $("#historial_comment_myid_"+Id).val();
		var fid = $("#historial_comment_fromid_"+Id).val();
		var comments = $("#historial_comment_comments_"+Id).val();
		var tipo = $("#historial_comment_type_"+Id).val();
		var feed = $("#historial_feed_"+Id).val();
		var grupo = $("#grupo_id").val();
		if(tipo == '' || tipo == null){tipo = 'own';}
		//var dataString = 'comentario='+ comment + '&aid=' + Id + '&uid=' + uid + '&fid=' + fid + '&comments=' + comments;
		if(comment==''){
			Sexy.alert("Introduce tu comentario!");
			$("input#"+Id).attr("disabled",false);
		}else{
			$("#flash_"+Id).show();
			$("#flash_"+Id).fadeIn(400).html('<span class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif" align="absmiddle"> Publicando...</span>');
			$.post( "http://www.imeev.com/ajax/publish_historial_comment.php",
				{
					comentario: comment,
					type: tipo,
					aid: Id,
					uid: uid,
					fid: fid,
					comments: comments,
					feed: feed,
					grupo: grupo
				},
				function(html){
					$("#historial_comment_load_"+Id).fadeIn().html(html);
					$("#flash_"+Id).fadeOut(400);
					$("input#"+Id).attr("disabled",false);
				}
			);
		}
	});
	$(".event_minicomment_publish").live('click',function(){
		var element = $(this);
		var Id = element.attr("id");
		var comment = $("#historial_comment_textarea_"+Id).val();
		var uid = $("#historial_comment_myid_"+Id).val();
		var fid = $("#historial_comment_fromid_"+Id).val();
		var bid = $("#historial_comment_gid_"+Id).val();
		var comments = $("#historial_comment_comments_"+Id).val();
		var tipo = $("#historial_comment_type_"+Id).val();
		//var dataString = 'comentario='+ comment + '&aid=' + Id + '&uid=' + uid + '&fid=' + fid + '&comments=' + comments;
		if(comment==''){
			Sexy.alert("Introduce tu comentario!");
		}else{
			$("#flash_"+Id).show();
			$("#flash_"+Id).fadeIn(400).html('<span class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif" align="absmiddle"> Publicando...</span>');
			$.post( "http://www.imeev.com/ajax/publish_event_comment.php",
				{
					comentario: comment,
					type: tipo,
					aid: Id,
					uid: uid,
					fid: fid,
					bid: bid,
					comments: comments
				},
				function(html){
					$("#historial_comment_load_"+Id).html(html);
					$("#flash_"+Id).hide();
				}
			);
		}
	});
	$(".more-share-options").hover(function(){
		$(".more-share-options-box").show();
		$(".more-share-options a").addClass('more-share-options-class');
	},function(){
		$(".more-share-options-box").hide();
		$(".more-share-options a").removeClass('more-share-options-class');
	});
	$(".filter-option").click(function(){
		if($(".filter-list").is(":visible") == true){
			$(".filter-list").hide();
			$(".filter-option").css('background','');
			$(".filter-option").css('border','transparent solid 1px');
			$(".filter-option").removeClass('color-333');
		}else{
			$(".filter-option").css('-moz-border-radius','4px 4px 0px 0px');
			$(".filter-option").css('-webkit-border-radius','4px 4px 0px 0px');
			$(".filter-option").css('border-radius','4px 4px 0px 0px');
			$(".filter-option").css('border-top','#CCC solid 1px');
			$(".filter-option").css('border-left','#CCC solid 1px');
			$(".filter-option").css('border-right','#CCC solid 1px');
			$(".filter-option").css('background','#EFEFEF');
			$(".filter-option").css('z-index','9999999');
			$(".filter-option").addClass('color-333');
			$(".filter-list").show();
		}
	});
	$(".group_minicomment_publish").live('click',function(){
		var element = $(this);
		var Id = element.attr("id");
		var comment = $("#historial_comment_textarea_"+Id).val();
		var uid = $("#historial_comment_myid_"+Id).val();
		var fid = $("#historial_comment_fromid_"+Id).val();
		var bid = Id;
		var comments = $("#historial_comment_comments_"+Id).val();
		var tipo = $("#historial_comment_type_"+Id).val();
		$("#"+Id).attr("disabled",true);
		//var dataString = 'comentario='+ comment + '&aid=' + Id + '&uid=' + uid + '&fid=' + fid + '&comments=' + comments;
		if(comment==''){
			Sexy.alert("Introduce tu comentario!");
		}else{
			$("#flash_"+Id).show();
			$("#flash_"+Id).fadeIn(400).html('<span class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif" align="absmiddle"> Publicando...</span>');
			$.post( "http://www.imeev.com/ajax/publish_group_comment.php",
				{
					comentario: comment,
					type: tipo,
					aid: Id,
					uid: uid,
					fid: fid,
					bid: bid,
					comments: comments
				},
				function(html){
					$("#historial_comment_load_"+Id).html(html);
					$("#flash_"+Id).hide();
				}
			);
		}
		$("#"+Id).attr("disabled",false);
	});
	$('#mood_comment_publish').click(function(){
		$.post("http://www.imeev.com/publish_mood_comment.php", {
			comentario: $('#mood_comment_textarea').val(),
			uid: $('#mood_comment_myid').val(),
			aid: $('#mood_comment_id').val()
		});
		uid = $('#fid').val();
		 $("#comments-popup").fadeOut(500); 
		 setTimeout(function () {
		 	$("#comments_frame").load("http://www.imeev.com/profile_pages/comments.php?uid=" + uid);
			$('#comentario').val() = '';
		 }, 1000);
	});
	$(".search_box").focus(function(){
		var cont = $("#suggest_box").html();
		if(cont != ''){
			$("#suggest_box").show();
		}
	});
	$(".search_box").blur(function(){
		setTimeout(function(){
		$("#suggest_box").hide();
		},200);
	});
	$("#friend-list label input[type='checkbox']").live("click",function(){
		if($(this).is(":checked")){
			$(this).parent("label").css("background-color","#3A73AB");	
		}else{
			$(this).parent("label").css("background-color","transparent");	
		}
	});
	$(".search_box").keyup(function(e){
		var searchbox = $(this).val();
		var dataString = 'buscando='+ searchbox;
		if(searchbox != '' && searching == 0 && (e.keyCode >= 65 && e.keyCode <= 90 || e.keyCode == 8)){
			searching = 1;
			$("#suggest_box").html('<div class="loading" style="background:#FFF;padding-left:5px" align="left"><img src="/images/ajax-loader.gif" /> Buscando...</div>').show();
			$.ajax({
				type: "POST",
				url: "http://www.imeev.com/ajax/suggest.php",
				data: dataString,
				cache: true,
				success: function(html){
					$("#suggest_box").html(html);
					searching = 0;
				}
			});
		}
		if(searchbox == ''){
			$("#suggest_box").hide();
		}return false;
	});

$('.my_emoticon').live("click",function() {
			if($("#emoticon-list-popups").is(":visible")){
				$("#emoticon-list-popups").hide();
				$(".my_emoticon").css("-moz-border-radius","5px");
				$(".my_emoticon").css("-webkit-border-radius","5px");
				$(".my_emoticon").css("border-radius","5px");
				$(".my_emoticon").css("border","#81B1CF solid 2px");
				$(".my_emoticon").css("background","none");	
			}else{
				$("#emoticon-list-popups").show();
				$(".my_emoticon").css("-moz-border-radius","5px 5px 0px 0px");
				$(".my_emoticon").css("-webkit-border-radius","5px 5px 0px 0px");
				$(".my_emoticon").css("border-radius","5px 5px 0px 0px");
				$(".my_emoticon").css("border","#81B1CF solid 2px");
				$(".my_emoticon").css("background","#F2F2F2");	
			}
		});
		$('.avatar_select').hover(function() {
			$("#my_avatar_options").show();
			$(".mini_avatar").css("-moz-border-radius","5px 0px 5px 5px");
			$(".mini_avatar").css("-webkit-border-radius","5px 0px 5px 5px");
			$(".mini_avatar").css("border-radius","5px 0px 5px 5px");
			$(".mini_avatar").css("border","#81B1CF solid 2px");
		},function(){
			$("#my_avatar_options").hide();
			$(".mini_avatar").css("-moz-border-radius","5px");
			$(".mini_avatar").css("-webkit-border-radius","5px");
			$(".mini_avatar").css("border-radius","5px");
			$(".mini_avatar").css("border","#FFFFFF solid 2px");
		});

	$(".notif_mail").click(function(){
		if($("#notif_mail").is(":visible") == true){
			$(this).removeClass('notif_sel');	
			$("#notif_mail").hide();
			$(".notif_mail img").attr("src","/images/mini/mail_blk.png");
			$("#notifs .arrow_up").hide();
		}else{
			$(".notif_mail img").attr("src","/images/mini/mail_new.png");
			if(!notifs[0])
				$(".notif_alerts img").attr("src","/images/mini/bell_blk.png");
			if(!notifs[2])
				$(".notif_req img").attr("src","/images/mini/friends_blk.png");
			$("#notifs .arrow_up").css("left","0px");
			$("#notifs .arrow_up").show();
			if(notifs[1] >0 || $("#notif_mail_active").val() == 0){
				not_mail = 0;
				/*if(not_mail == 0 && not_reqs == 0 && not_notif == 0 && page_title != ''){document.title = page_title;page_title = '';}*/
				$(".notif_mail #notif_balloon").hide();
				$("#notif_mail_spawn").html('<span class="loading" style="margin:5px;padding-bottom:5px"><img src="http://www.imeev.com/images/ajax-loader.gif" align="absmiddle"> Cargando...</span>');
				$.post( "http://www.imeev.com/ajax/notif_system.php",
					{
						notif : 'mail'
					},
					function(html){
						$("#notif_mail_spawn").html(html);
					}
				);
				$("#notif_mail_active").val(1);
			}
			total_notifs-=parseInt(notifs[1]);
			notifs[1] = 0;
			Tinycon.setBubble(total_notifs);
			$("div#notifs span").removeClass('notif_sel');
			$(this).addClass('notif_sel');	
			$("#notif_mail").show();
			$("#notif_req").hide();
			$("#notif_alerts").hide();
		}
	});
	$(".notif_req").click(function(){
		if($("#notif_req").is(":visible") == true){
			$(this).removeClass('notif_sel');	
			$("#notif_req").hide();
			$(".notif_req img").attr("src","/images/mini/friends_blk.png");
			$("#notifs .arrow_up").hide();
		}else{
			$(".notif_req img").attr("src","/images/mini/friends_new.png");
			if(!notifs[0])
				$(".notif_alerts img").attr("src","/images/mini/bell_blk.png");
			if(!notifs[1])
				$(".notif_mail img").attr("src","/images/mini/mail_blk.png");
			$("#notifs .arrow_up").css("left","28px");
			$("#notifs .arrow_up").show();
			if(notifs[2]>0 || $("#notif_req_active").val() == 0){
				not_reqs = 0;
				/*if(not_mail == 0 && not_reqs == 0 && not_notif == 0 && page_title != ''){document.title = page_title;page_title = '';}*/
				$(".notif_req #notif_balloon").hide();
				$("#notif_req_spawn").html('<span class="loading" style="margin:5px;padding-bottom:5px"><img src="http://www.imeev.com/images/ajax-loader.gif" align="absmiddle"> Cargando...</span>');
				$.post( "http://www.imeev.com/ajax/notif_system.php",
					{
						notif : 'friend_reqs'
					},
					function(html){
						$("#notif_req_spawn").html(html);
					}
				);
				$("#notif_req_active").val(1);
			}
			total_notifs-=parseInt(notifs[2]);
			Tinycon.setBubble(total_notifs);
			notifs[2] = 0;
			$("div#notifs span").removeClass('notif_sel');
			$(this).addClass('notif_sel');	
			$("#notif_req").show();
			$("#notif_mail").hide();
			$("#notif_alerts").hide();
		}
	});
	$(".notif_alerts").live("click",function(){
		if($("#notif_alerts").is(":visible") == true){
			$(this).removeClass('notif_sel');	
			$("#notif_alerts").hide();
			$(".notif_alerts img").attr("src","/images/mini/bell_blk.png");
			$("#notifs .arrow_up").hide();
		}else{
			$(".notif_alerts img").attr("src","/images/mini/bell_new.png");
			if(!notifs[1])
				$(".notif_mail img").attr("src","/images/mini/mail_blk.png");
			if(!notifs[2])
				$(".notif_req img").attr("src","/images/mini/friends_blk.png");
			$("#notifs .arrow_up").css("left","-28px");
			$("#notifs .arrow_up").show();
			if(notifs[0] >0 || $("#notif_alerts_active").val() == 0){
				not_notif = 0;
				/*if(not_mail == 0 && not_reqs == 0 && not_notif == 0 && page_title != ''){document.title = page_title;page_title = '';}*/
				$("#notif_alerts_spawn").html('<span class="loading" style="margin:5px;padding-bottom:5px"><img src="http://www.imeev.com/images/ajax-loader.gif" align="absmiddle"> Cargando...</span>');
				$("#notif_alerts_spawn").load('http://www.imeev.com/notifications.php');
				$("#notif_alerts_active").val(1);
			}
			$(".notif_alerts #notif_balloon").hide();
			total_notifs-=parseInt(notifs[0]);
			notifs[0] = 0;
			Tinycon.setBubble(total_notifs);
			$("div#notifs span").removeClass('notif_sel');
			$(this).addClass('notif_sel');	
			$("#notif_req").hide();
			$("#notif_mail").hide();
			$("#notif_alerts").show();
		}
	});
	$("a.tab").live("click",function(){
		$(".active").removeClass("active");
		$(this).addClass("active");
		$(".content").fadeOut(0);
		var content_show = $(this).attr("tab");
		$("#"+content_show).fadeIn(250,function(){
		});
	});
	var div= $('div#pro_tabbed'),ul=$('ul.pro_tabs'),ulPadding=15;
	var divWidth=div.width();
	div.css({overflow:'hidden'});
	var lastLi=ul.find('li:last-child');
	div.mousemove(function(e){
		var ulWidth=lastLi[0].offsetLeft+lastLi.outerWidth()+ulPadding;
		var left=(e.pageX-div.offset().left)*(ulWidth-divWidth)/divWidth;
		div.scrollLeft(left);
	});
	div= $('div#friend-slider'),ul=$('ul.slider-amigos'),ulPadding=5;
	divWidth=div.width();
	div.css({overflow:'hidden'});
	lastLi=ul.find('li:last-child');
	div.mousemove(function(e){
		var ulWidth=lastLi[0].offsetLeft+lastLi.outerWidth()+ulPadding;
		var left=(e.pageX-div.offset().left)*(ulWidth-divWidth)/divWidth;
		div.scrollLeft(left);
	});
});
(function($){

    var rotateLeft = function(lValue, iShiftBits) {
        return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
    }

    var addUnsigned = function(lX, lY) {
        var lX4, lY4, lX8, lY8, lResult;
        lX8 = (lX & 0x80000000);
        lY8 = (lY & 0x80000000);
        lX4 = (lX & 0x40000000);
        lY4 = (lY & 0x40000000);
        lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
        if (lX4 & lY4) return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
        if (lX4 | lY4) {
            if (lResult & 0x40000000) return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
            else return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
        } else {
            return (lResult ^ lX8 ^ lY8);
        }
    }

    var F = function(x, y, z) {
        return (x & y) | ((~ x) & z);
    }

    var G = function(x, y, z) {
        return (x & z) | (y & (~ z));
    }

    var H = function(x, y, z) {
        return (x ^ y ^ z);
    }

    var I = function(x, y, z) {
        return (y ^ (x | (~ z)));
    }

    var FF = function(a, b, c, d, x, s, ac) {
        a = addUnsigned(a, addUnsigned(addUnsigned(F(b, c, d), x), ac));
        return addUnsigned(rotateLeft(a, s), b);
    };

    var GG = function(a, b, c, d, x, s, ac) {
        a = addUnsigned(a, addUnsigned(addUnsigned(G(b, c, d), x), ac));
        return addUnsigned(rotateLeft(a, s), b);
    };

    var HH = function(a, b, c, d, x, s, ac) {
        a = addUnsigned(a, addUnsigned(addUnsigned(H(b, c, d), x), ac));
        return addUnsigned(rotateLeft(a, s), b);
    };

    var II = function(a, b, c, d, x, s, ac) {
        a = addUnsigned(a, addUnsigned(addUnsigned(I(b, c, d), x), ac));
        return addUnsigned(rotateLeft(a, s), b);
    };

    var convertToWordArray = function(string) {
        var lWordCount;
        var lMessageLength = string.length;
        var lNumberOfWordsTempOne = lMessageLength + 8;
        var lNumberOfWordsTempTwo = (lNumberOfWordsTempOne - (lNumberOfWordsTempOne % 64)) / 64;
        var lNumberOfWords = (lNumberOfWordsTempTwo + 1) * 16;
        var lWordArray = Array(lNumberOfWords - 1);
        var lBytePosition = 0;
        var lByteCount = 0;
        while (lByteCount < lMessageLength) {
            lWordCount = (lByteCount - (lByteCount % 4)) / 4;
            lBytePosition = (lByteCount % 4) * 8;
            lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount) << lBytePosition));
            lByteCount++;
        }
        lWordCount = (lByteCount - (lByteCount % 4)) / 4;
        lBytePosition = (lByteCount % 4) * 8;
        lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
        lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
        lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
        return lWordArray;
    };

    var wordToHex = function(lValue) {
        var WordToHexValue = "", WordToHexValueTemp = "", lByte, lCount;
        for (lCount = 0; lCount <= 3; lCount++) {
            lByte = (lValue >>> (lCount * 8)) & 255;
            WordToHexValueTemp = "0" + lByte.toString(16);
            WordToHexValue = WordToHexValue + WordToHexValueTemp.substr(WordToHexValueTemp.length - 2, 2);
        }
        return WordToHexValue;
    };

    var uTF8Encode = function(string) {
        string = string.replace(/\x0d\x0a/g, "\x0a");
        var output = "";
        for (var n = 0; n < string.length; n++) {
            var c = string.charCodeAt(n);
            if (c < 128) {
                output += String.fromCharCode(c);
            } else if ((c > 127) && (c < 2048)) {
                output += String.fromCharCode((c >> 6) | 192);
                output += String.fromCharCode((c & 63) | 128);
            } else {
                output += String.fromCharCode((c >> 12) | 224);
                output += String.fromCharCode(((c >> 6) & 63) | 128);
                output += String.fromCharCode((c & 63) | 128);
            }
        }
        return output;
    };


    $.extend({
        md5: function(string) {
                 var x = Array();
                 var k, AA, BB, CC, DD, a, b, c, d;
                 var S11=7, S12=12, S13=17, S14=22;
                 var S21=5, S22=9 , S23=14, S24=20;
                 var S31=4, S32=11, S33=16, S34=23;
                 var S41=6, S42=10, S43=15, S44=21;
                 string = uTF8Encode(string);
                 x = convertToWordArray(string);
                 a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
                 for (k = 0; k < x.length; k += 16) {
                     AA = a; BB = b; CC = c; DD = d;
                     a = FF(a, b, c, d, x[k+0],  S11, 0xD76AA478);
                     d = FF(d, a, b, c, x[k+1],  S12, 0xE8C7B756);
                     c = FF(c, d, a, b, x[k+2],  S13, 0x242070DB);
                     b = FF(b, c, d, a, x[k+3],  S14, 0xC1BDCEEE);
                     a = FF(a, b, c, d, x[k+4],  S11, 0xF57C0FAF);
                     d = FF(d, a, b, c, x[k+5],  S12, 0x4787C62A);
                     c = FF(c, d, a, b, x[k+6],  S13, 0xA8304613);
                     b = FF(b, c, d, a, x[k+7],  S14, 0xFD469501);
                     a = FF(a, b, c, d, x[k+8],  S11, 0x698098D8);
                     d = FF(d, a, b, c, x[k+9],  S12, 0x8B44F7AF);
                     c = FF(c, d, a, b, x[k+10], S13, 0xFFFF5BB1);
                     b = FF(b, c, d, a, x[k+11], S14, 0x895CD7BE);
                     a = FF(a, b, c, d, x[k+12], S11, 0x6B901122);
                     d = FF(d, a, b, c, x[k+13], S12, 0xFD987193);
                     c = FF(c, d, a, b, x[k+14], S13, 0xA679438E);
                     b = FF(b, c, d, a, x[k+15], S14, 0x49B40821);
                     a = GG(a, b, c, d, x[k+1],  S21, 0xF61E2562);
                     d = GG(d, a, b, c, x[k+6],  S22, 0xC040B340);
                     c = GG(c, d, a, b, x[k+11], S23, 0x265E5A51);
                     b = GG(b, c, d, a, x[k+0],  S24, 0xE9B6C7AA);
                     a = GG(a, b, c, d, x[k+5],  S21, 0xD62F105D);
                     d = GG(d, a, b, c, x[k+10], S22, 0x2441453);
                     c = GG(c, d, a, b, x[k+15], S23, 0xD8A1E681);
                     b = GG(b, c, d, a, x[k+4],  S24, 0xE7D3FBC8);
                     a = GG(a, b, c, d, x[k+9],  S21, 0x21E1CDE6);
                     d = GG(d, a, b, c, x[k+14], S22, 0xC33707D6);
                     c = GG(c, d, a, b, x[k+3],  S23, 0xF4D50D87);
                     b = GG(b, c, d, a, x[k+8],  S24, 0x455A14ED);
                     a = GG(a, b, c, d, x[k+13], S21, 0xA9E3E905);
                     d = GG(d, a, b, c, x[k+2],  S22, 0xFCEFA3F8);
                     c = GG(c, d, a, b, x[k+7],  S23, 0x676F02D9);
                     b = GG(b, c, d, a, x[k+12], S24, 0x8D2A4C8A);
                     a = HH(a, b, c, d, x[k+5],  S31, 0xFFFA3942);
                     d = HH(d, a, b, c, x[k+8],  S32, 0x8771F681);
                     c = HH(c, d, a, b, x[k+11], S33, 0x6D9D6122);
                     b = HH(b, c, d, a, x[k+14], S34, 0xFDE5380C);
                     a = HH(a, b, c, d, x[k+1],  S31, 0xA4BEEA44);
                     d = HH(d, a, b, c, x[k+4],  S32, 0x4BDECFA9);
                     c = HH(c, d, a, b, x[k+7],  S33, 0xF6BB4B60);
                     b = HH(b, c, d, a, x[k+10], S34, 0xBEBFBC70);
                     a = HH(a, b, c, d, x[k+13], S31, 0x289B7EC6);
                     d = HH(d, a, b, c, x[k+0],  S32, 0xEAA127FA);
                     c = HH(c, d, a, b, x[k+3],  S33, 0xD4EF3085);
                     b = HH(b, c, d, a, x[k+6],  S34, 0x4881D05);
                     a = HH(a, b, c, d, x[k+9],  S31, 0xD9D4D039);
                     d = HH(d, a, b, c, x[k+12], S32, 0xE6DB99E5);
                     c = HH(c, d, a, b, x[k+15], S33, 0x1FA27CF8);
                     b = HH(b, c, d, a, x[k+2],  S34, 0xC4AC5665);
                     a = II(a, b, c, d, x[k+0],  S41, 0xF4292244);
                     d = II(d, a, b, c, x[k+7],  S42, 0x432AFF97);
                     c = II(c, d, a, b, x[k+14], S43, 0xAB9423A7);
                     b = II(b, c, d, a, x[k+5],  S44, 0xFC93A039);
                     a = II(a, b, c, d, x[k+12], S41, 0x655B59C3);
                     d = II(d, a, b, c, x[k+3],  S42, 0x8F0CCC92);
                     c = II(c, d, a, b, x[k+10], S43, 0xFFEFF47D);
                     b = II(b, c, d, a, x[k+1],  S44, 0x85845DD1);
                     a = II(a, b, c, d, x[k+8],  S41, 0x6FA87E4F);
                     d = II(d, a, b, c, x[k+15], S42, 0xFE2CE6E0);
                     c = II(c, d, a, b, x[k+6],  S43, 0xA3014314);
                     b = II(b, c, d, a, x[k+13], S44, 0x4E0811A1);
                     a = II(a, b, c, d, x[k+4],  S41, 0xF7537E82);
                     d = II(d, a, b, c, x[k+11], S42, 0xBD3AF235);
                     c = II(c, d, a, b, x[k+2],  S43, 0x2AD7D2BB);
                     b = II(b, c, d, a, x[k+9],  S44, 0xEB86D391);
                     a = addUnsigned(a, AA);
                     b = addUnsigned(b, BB);
                     c = addUnsigned(c, CC);
                     d = addUnsigned(d, DD);
                 }
                 var tempValue = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d);
                 return tempValue.toLowerCase();
             }
    });
})(jQuery);
