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){
	var comments = $("#historial_comment_comments_"+comment_id).val();
	$("#historial_comment_inputs_"+comment_id).toggle();
	if(comments == 0){
		$("#historial_comment_frame_"+comment_id).toggleClass("mood_comment_frame");
	}
}
function comment_historial_cancel(comment_id){
	var comments = $("#historial_comment_comments_"+comment_id).val();
	$("#historial_comment_inputs_"+comment_id).hide();
	if(comments == 0){
		$("#historial_comment_frame_"+comment_id).toggleClass("mood_comment_frame");
	}
}
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() == ""){
				alert("Elige un regalo!");
			}else{
				$(".step_1").hide();
				$(".step_2").fadeIn(1000);
				$(".step_3").hide();
			}
		break;
		case '3':
			if($("#para").val() == 0){
				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);
	}
}
$(document).ready(function (){
	$("#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{
				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);
	});
	
	$(".mood_comment_publish").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==''){
			alert("Introduce tu comentario!");
		}else{
			$("#flash_"+Id).show();
			$("#flash_"+Id).fadeIn(400).html('<img src="/images/loading_.gif" align="absmiddle"> cargando...');
			$.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;
	});
	$(".historial_comment_publish").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 comments = $("#historial_comment_comments_"+Id).val();
		//var dataString = 'comentario='+ comment + '&aid=' + Id + '&uid=' + uid + '&fid=' + fid + '&comments=' + comments;
		if(comment==''){
			alert("Introduce tu comentario!");
		}else{
			$("#flash_"+Id).show();
			$("#flash_"+Id).fadeIn(400).html('<img src="/images/loading_.gif" align="absmiddle"> cargando...');
			$.post( "http://www.imeev.com/ajax/publish_historial_comment.php",
				{
					comentario: comment,
					aid: Id,
					uid: uid,
					fid: fid,
					comments: comments
				},
				function(html){
					$("#historial_comment_load_"+Id).html(html);
					$("#flash_"+Id).hide();
				}
			);
		}
	});
	$('#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);
	});
});