jQuery(function($) {
	var auth_token = $("#user_token").val();

	$("a.tweet-rec-up").click(function(evt) {
		killEvent(evt);
		var cThis = this;
		
		jQuery.post($(this).attr('href'),{user_token:auth_token}
			, function() {
					
			                $(cThis).parents("div.tweetContainer").find("div.rec_count_value").fadeIn(500);
					$(cThis).parents("div.tweetContainer").find("div.rec_count_value").incrementValue(1);
					var newValue = parseInt($(cThis).parents("div.tweetContainer").find("div.rec_count_value").text());
					$(cThis).parents("div.tweetContainer").find("div.rec_count_label").text(newValue == 1 ? "Rec" : "Recs");
					
					$(cThis).parents("div.tweetContainer").find("div.report_container").hide(100).remove();
					
					$(cThis).parents("div.tweetContainer").find("#reced").removeClass();
					$(cThis).parents("div.tweetContainer").find("#reced").addClass("tweet-rec-up-inactive");
					
					$(cThis).remove();
			}
		);
	});
		
	
	$("a.report_default").click(function(evt) { 
		killEvent(evt);	
		var cThis = this;
		jQuery.post($(this).attr('href'),{user_token:auth_token},function() {
			var eParents = $(cThis).parents("div.tweetContainer");
			eParents.addClass("reported"); 
			eParents.find("ul.tweet-related-list").hide(100).remove();
			eParents.find("img.tweet-avatar").removeClass('tweet-avatar').addClass('tweet-avatar-greyed');
			
			eParents.find("div.tweet").hide(100).remove();	
		});	
	});
	
	$("div.tweet_reportness_menu a").click(function(evt) {
		// report(this,evt);
		killEvent(evt);	
		var cThis = this;
		jQuery.post($(this).attr('href'),{user_token:auth_token},function() {
			var eParents = $(cThis).parents("div.tweetContainer");
			eParents.addClass("reported"); 
			eParents.find("ul.tweet-related-list").hide(100).remove();
			eParents.find("img.tweet-avatar").removeClass('tweet-avatar').addClass('tweet-avatar-greyed');
			
			eParents.find("div.tweet").hide(100).remove();	
		});			
		
		$(this).parents('div.tweet_menu').hide(200);
	});

	var killEvent = function(evt) {
		evt.stopPropagation();
		evt.preventDefault();		
	}
	var hideOpenMenus = function() {
		$("div.tweet_menu.menu_open").hide();
	}	
	$("body").click(function() {
		hideOpenMenus();
	});
	$("div.tweet_menu").click(function(evt) {
		if(evt.target.tagName != 'A') {
			$.killEvent(evt);
		}
	});
	
	$.fn.extend({
		menuTrigger : function(options) {
			options = options||{}
			var handleTrigger = function(evt) {
				hideOpenMenus();
				killEvent(evt);
				var pos = $(this).position();
				var iRight = (pos.left-$(this).next('div.tweet_menu').outerWidth())+$(this).outerWidth();
				var eMenu  = $(this).next('div.tweet_menu');
				eMenu.addClass('menu_open').css({left:(iRight)+"px",top:(pos.top+16)+"px"}).show(100,function() {
					if(typeof options.onOpen == 'function') {
						options.onOpen(eMenu,options);
					}					
				});
			}
			$(this).each(function() {
				$(this).click(handleTrigger);
			});
			return this;
		}, 
		incrementValue : function(amt) {
			$(this).each(function() {
				$(this).text(parseInt($(this).text())+amt);
			});
			return this;
		}
	});
});

$(document).ready(
    function() 
    {
        var xOffset = 602;
        var yOffset = -13;
        
        var xOffsetStores = 640;
        var yOffsetStores = 0;
        

        $("#lnkMore").hover(
            function() {

                $("#divMoreCategoriesHover")
                    .css(
                    {
                        "display": "block",
                        "top": $("#nav").position().top + $("#nav").height() + yOffset,
                        "left": $("#nav").position().left + xOffset
                    });

                $("#divMoreCategoriesHover").hover(
                    function() {
                        $("#divMoreCategoriesHover").css("display", "block");
                        $("#divMoreCategoriesHover").css("z-index", "1000");
                        $("#divMoreCategoriesHover").css("BACKGROUND-COLOR", "solid");
                        $("#lnkMore").css("background-color", "#627D4D");
                    },
                    function() {
                        $("#divMoreCategoriesHover").css("display", "none");
                        $("#lnkMore").css("background-color", "#17A141");
                    });
                    
                 $("#lnkMore").css("background-color", "#627D4D");
            },
            function() {
                $("#divMoreCategoriesHover").css("display", "none");
                $("#lnkMore").css("background-color", "#17A141");
            });
            
    }
);