function hideup() {
$("#upform").hide();
$("#showme").show();
}

//REPORT
function report(removeid,type) {
$.post("/add/report/", { id: removeid, t:type, js:1 },
  function(data){
    //alert("Done: " + data);
$("#reportmsg").show();
  });
}

// TAGS
function addtags() {
var tagid = $("#tagid").val();
var taginput = $("#taginput").val();
$.post("/add/tag/", { id: tagid, tag: taginput, js:1 },
  function(data){
	$("#comments").hide('fast');
	$("#report").hide('fast');
	$('#fav').hide('fast');
	$("#tags").html('<strong>Thanks for adding tags for this gif!</strong>');
   // alert("Done: " + taginput + data);
  });
}//end tags

// COMMENTS
function addcomment() {
var cid = $("#cid").val();
var cv = $("#commentinput").val();
$.post("/add/comment/", { id: cid, comment: cv, js:1 },
  function(data){
	$("#tags").hide('fast');
	$("#report").hide('fast');
	$('#fav').hide('fast');
	$("#comments").html('<strong>Thanks for commenting on this gif!</strong>');
    //alert("Done: " + comment + data);
  });
}//end comment

// FAV
function fav(url) {
var favid = $("#favid").val();
$.post(url, { js: 1 },function(data){
if(data == 'removed') {
$("#favbtn").html('Add Favorite');
$("#favlink").attr('href','/add/fav/'+favid+'/');
$("#favimg").attr('src','/images/icons/heart.png');
$("#fav").html('<img src="/images/icons/accept.png" /><strong>Favorite Removed!</strong>');
}
if(data == 'added') {
$("#favbtn").html('Remove Favorite');
$("#favlink").attr('href','/del/fav/'+favid+'/');
$("#favimg").attr('src','/images/icons/heart_break.png');
$("#fav").html('<img src="/images/icons/accept.png" /><strong>Favorite Added!</strong>');
}
});
}//end fav

function checkLogin(what) {
var id = $("#favid").val();
var msg = 'You must be <a href="/login/'+id+'" class="link">logged in</a> ';
$.post("/check/", { js: 1 },
  function(data){
	if(data != 'no user') {
		if(what == 'comments') {
			$("#comments").show('fast');
			$("#commentinput").focus();
		}//end comments
		if(what == 'fav') {
			$('#fav').show('fast');
			fav($("#favlink").attr('href'));
		}//end fav

	} else {//not logged in

		if(what == 'comments') {
			$("#comments").html(msg + 'to add comments.');
			$("#comments").show('fast');
		}
		if(what == 'fav') {
			$("#fav").html(msg + 'to add favorites.');
			$('#fav').show('fast');
		}
	} //end checking
});//end post
}//end function

//// DOC READY
$(document).ready(function () { //begin document ready

$("#user").focus();

$("#commentlink").click(function() {
$("#report").hide('fast');
$("#tags").hide('fast');
$('#fav').hide('fast');
checkLogin('comments');
return false;
});

$("#reportlink").click(function() {
$("#comments").hide('fast');
$("#tags").hide('fast');
$('#fav').hide('fast');
$("#report").show('fast');
return false;
});

$("#favlink").click(function() { 
$("#comments").hide('fast');
$("#tags").hide('fast');
$("#report").hide('fast');
checkLogin('fav');
return false;
});

$("#taglink").click(function () {
$("#comments").hide('fast');
$("#report").hide('fast');
$('#fav').hide('fast');
$("#tags").show('fast');
$("#taginput").focus();
return false;
});

///// END LINKS

$("#reportr").click(function() {
var gi = $("#gifid").val();
report($(this).attr('name'),gi);
$("#reportd").attr('disabled','disabled');
$(this).attr('disabled','disabled');
return false;
});

$("#reportd").click(function() {
var gi = $("#gifid").val();
report($(this).attr('name'),gi);
$("#reportr").attr('disabled','disabled');
$(this).attr('disabled','disabled');
return false;
});

$(".removeOrig").click(function () {
dup($(this).attr('name'));
});

$(".removeDup").click(function () {
dup($(this).attr('name'));
});

$("#gif").change(function () {
$("#showcat").show();
$("#showtags").show();
});

$("#tagupdate").submit(function() {
if($("#taginput").val()) {
addtags();
}
return false;
});

$("#commentform").submit(function() {
if($("#commentinput").val()) {
addcomment();
}
return false;
});


}); // end document ready