.directive("runSocialSharing", function($ionicActionSheet, $timeout){
	return {
		controller: function($scope, $element, $attrs){
			$element.bind("click", showSocialSharing);
			function showSocialSharing(event){
				// Show the action sheet
				var hideSheet = $ionicActionSheet.show(
				{
					titleText: 'Share This',
					buttons: [
					{
						text: '<i class="ion-social-facebook"></i> Facebook'}, {
						text: '<i class="ion-social-twitter"></i> Twitter'}, {
						text: '<i class="ion-social-whatsapp"></i> Whatsapp'}, {
						text: '<i class="icon-left ion-ios-chatbubble"></i> Line'}, ],
					cancelText: 'Cancel',
					cancel: function(){
						// add cancel code.
					},
					buttonClicked: function(index)
					{
						switch (index)
						{
						case 0:
							var textMessage = window.encodeURIComponent($attrs.message) || "";
							var urlSchema = "https://facebook.com/sharer/sharer.php?u=" + textMessage;
							window.open(urlSchema, "_system", "location=yes");
							break;
						case 1:
							var textMessage = window.encodeURIComponent($attrs.message) || "";
							var urlSchema = "twitter://post?message=" + textMessage;
							window.open(urlSchema, "_system", "location=yes");
							break;
						case 2:
							var textMessage = window.encodeURIComponent($attrs.message) || "";
							var urlSchema = "whatsapp://send?text=" + textMessage;
							window.open(urlSchema, "_system", "location=yes");
							break;
						case 3:
							var textMessage = window.encodeURIComponent($attrs.message) || "";
							var urlSchema = "line://msg/text/" + textMessage;
							window.open(urlSchema, "_system", "location=yes");
							break;
						}
					}
				});
				$timeout(function()
				{
					hideSheet();
				}, 5000);
			};
		}
	};
})