var vnNotifications = new (function (){
	//var cached = null;
	var showing = false;
	function toggle(){
		showing = !showing;
		if (!showing){
			$('.ntbtn').removeClass('ntbtn-active');
			$('#ntpopup').hide();
			return;
		}
		$('.ntbtn').addClass('ntbtn-active');
		$('#ntpopup').show();

	};
	function init(){
	     $(document).bind('click', function(e){
                var $clicked = $(e.target);
                if (!($clicked.is('.ntbtn') || $clicked.is('#ntpopup') || $clicked.parents().is('#ntpopup'))) {
                    //click outside
                    $('.ntbtn').removeClass('ntbtn-active');
                    $('#ntpopup').hide();
                }
            });
            
		$('.ntbtn').click(function(evt){
			var t = evt.target;
			var s = t.className.substr(0, 5);
			if (s=='ntbtn'
				|| t.id.substr(0, 9)=='ntcounter')
				toggle();
		});
		$('.ntbtn').mouseenter(function(){
			$('.ntbtn').addClass('ntbtn-hover');
		});
		$('.ntbtn').mouseleave(function(){
			$('.ntbtn').removeClass('ntbtn-hover');
		});
		$('.ntmin').mouseenter(function(){
			$('.ntmin').addClass('ntmin-active');
		});
		$('.ntmin').mouseleave(function(){
			$('.ntmin').removeClass('ntmin-active');
		});
	}
	this.init = init;
})();

var vnRequestFriends = new (function (){
	var showing = false;
	function toggle(){
		showing = !showing;
		if (!showing){
			$('.rfbtn').removeClass('rfbtn-active');
			$('#rfpopup').hide();
			return;
		}
		$('.rfbtn').addClass('rfbtn-active');
		$('#rfpopup').show();

	};
	function init(){
	
  $(document).bind('click', function(e){
                var $clicked = $(e.target);
                if (!($clicked.is('.rfbtn') || $clicked.is('#rfpopup') || $clicked.parents().is('#rfpopup'))) {
                    //click outside
                    $('.rfbtn').removeClass('rfbtn-active');
                    $('#rfpopup').hide();
                }
            });

		
		$('.rfbtn').click(function(evt){
			var t = evt.target;
			var s = t.className.substr(0, 5);
			if (s=='rfbtn'
				|| s == 'rfmin'
				|| t.id.substr(0, 9)=='rfcounter')
				toggle();
		});
		$('.rfbtn').mouseenter(function(){
			$('.rfbtn').addClass('rfbtn-hover');
		});
		$('.rfbtn').mouseleave(function(){
			$('.rfbtn').removeClass('rfbtn-hover');
		});
//		$('.rfmin').mouseenter(function(){
//			$('.rfmin').addClass('rfmin-active');
//		});
//		$('.rfmin').mouseleave(function(){
//			$('.rfmin').removeClass('rfmin-active');
//		});
	}
	this.init = init;
})();

var msRequestFriends = new (function (){
	var showing = false;
	function toggle(){
		showing = !showing;
		if (!showing){
			$('.msbtn').removeClass('msbtn-active');
			$('#mspopup').hide();
			return;
		}
		$('.msbtn').addClass('msbtn-active');
		$('#mspopup').show();

	};
	function init(){
	
  $(document).bind('click', function(e){
                var $clicked = $(e.target);
                if (!($clicked.is('.msbtn') || $clicked.is('#mspopup') || $clicked.parents().is('#mspopup'))) {
                    //click outside
                    $('.msbtn').removeClass('msbtn-active');
                    $('#mspopup').hide();
                }
            });

		
		$('.msbtn').click(function(evt){
			var t = evt.target;
			var s = t.className.substr(0, 5);
			if (s=='msbtn')
				toggle();
		});
		$('.msbtn').mouseenter(function(){
			$('.msbtn').addClass('msbtn-hover');
		});
		$('.msbtn').mouseleave(function(){
			$('.msbtn').removeClass('msbtn-hover');
		});
	}
	this.init = init;
})();

//var opChat = new (function (){ 
//	//var cached = null;
//	var showing = false;
//	function toggle(){
//	   
//		showing = !showing;
//		if (!showing){
//			$('.opbtn').removeClass('opbtn-active');
//			$('#oppopup').hide();
//			return;
//		}
//		$('.opbtn').addClass('opbtn-active');
//		$('#oppopup').show();

//	};
//	function init(){
//	     $(document).bind('click', function(e){
//                var $clicked = $(e.target);
//                if (!($clicked.is('.opbtn') || $clicked.is('#oppopup') || $clicked.parents().is('#oppopup'))) {
//                    //click outside
//                    $('.opbtn').removeClass('opbtn-active');
//                    $('#oppopup').hide();
//                }
//            });
//            
//		$('.opbtn').click(function(evt){
//			var t = evt.target;
//			var s = t.className.substr(0, 5);
//			if (s=='opbtn'
//				|| t.id.substr(0, 9)=='opcounter')
//				toggle();
//		});
//		$('.opbtn').mouseenter(function(){
//			$('.opbtn').addClass('opbtn-hover');
//		});
//		$('.opbtn').mouseleave(function(){
//			$('.opbtn').removeClass('opbtn-hover');
//		});
//		$('.opmin').mouseenter(function(){
//			$('.opmin').addClass('opmin-active');
//		});
//		$('.opmin').mouseleave(function(){
//			$('.opmin').removeClass('opmin-active');
//		});
//	}
//	this.init = init;
//})();

$(document).ready(function(){
	vnNotifications.init();
	vnRequestFriends.init();
	msRequestFriends.init();
	//opChat.init();
});
