var share_type = "";
var sid = 0;

var share_track_data = {};

var conf = { 
  APIKey: '2_KTgQOl2bioD75z_EpZOdKNVm4K2pqWbiGIrvPxpNk7tlBoYeY515PM0tVXwBkNmk',
  enabledProviders: 'facebook,google,foursquare'
};

var shareConf = { 
  APIKey: '2_KTgQOl2bioD75z_EpZOdKNVm4K2pqWbiGIrvPxpNk7tlBoYeY515PM0tVXwBkNmk',
  enabledProviders: 'facebook,twitter'
};

function showShareUI(title,desc,url,img,usermsg,type,id,track_data) {
	share_type = type;
	sid = id;
	share_track_data = track_data;

	url = url.replace("staging", "www");

  var act = new gigya.services.socialize.UserAction();  
  act.setUserMessage(usermsg);  
  act.setTitle(title+' on CityMaps');  
  act.setDescription(desc);  
  act.setLinkBack(url);   
  act.addActionLink("Check out the map",url);
  var video = {  
      src: img,
  	  href: url,
      type: 'image'  
  }  
  act.addMediaItem(video);
  // Parameters for the showShareUI method, including the UserAction object  
  var params =   
  {  
      userAction: act  // The UserAction object enfolding the newsfeed data.    
  ,operationMode: 'multiSelect' // Opens the Share Plugin either in Simple or Multiselect mode according to the user connection status.   
  ,snapToElementID: "btnShare" // Snaps the Simple Share Plugin to the share button  
  ,context: 'multiSelect'           
  ,showMoreButton: true // Enable the "More" button and screen  
  ,showEmailButton: true // Enable the "Email" button and screen
  ,emailBody: getEmailTemplate(title,desc,url,img)
  ,useHTML: true  // Use the HTML implementation of the Plugin (rather then Flash implementation)
  ,onSendDone: onSendDone(track_data)

  };  

  // Show the "Share" dialog  
  gigya.services.socialize.showShareUI(shareConf, params);
}

function onSendDone(track_data){
	track_data["bucket"] = null;
	if(share_type == "business") {
		mpmetrics.track("shareBusiness", track_data);
		track_data["bucket"] = "bid-"+track_data['postingBusinessId'];
  	mpmetrics.track("shareBusinessBucket", track_data);
	}
	if(share_type == "posting") {
		mpmetrics.track("sharePosting", track_data);
		track_data["bucket"] = "pid-"+track_data['postingId'];
  	mpmetrics.track("sharePostingBucket", track_data);
	}
}

function getEmailTemplate(title,desc,url,img) {
	var email_template = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\
<html>\
<head>\
	<title>Citymaps</title>\
	<style type="text/css">.ExternalClass{display:block !important;}</style>\
	<style type="text/css">.yshortcuts, .yshortcuts a, .yshortcuts a:link, .yshortcuts a:visited, .yshortcuts a:hover, .yshortcuts a span { color:#666; text-decoration: none !important; border-bottom: none !important; background: none !important;}</style>\
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\
</head>\
<body marginheight="0" marginwidth="0" leftmargin="0" topmargin="0" bgcolor="#e7f1fb">\
<br>\
<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0" bgcolor="#e7f1fb">\
	<tr>\
		<td>\
			<table width="772" cellpadding="0" cellspacing="0" border="0" align="center">\
				<tr><td style="font-size:0; line-height:0;"><img src="blank.gif" width="1" height="35"></td></tr>\
				<tr>\
					<td>\
						<table width="100%" cellpadding="0" cellspacing="0" border="0">\
							<tr>\
								<td width="86"></td>\
								<td width="686" style="font-size:0; line-height:0;">\
									<a href="#"><img src="http://www.citymaps.com/images/email-logo.gif" align="left" vspace="0" hspace="0" border="0" width="287" height="56" alt="City maps" ></a>\
								</td>\
							</tr>\
						</table>\
					</td>\
				</tr>\
				<tr><td style="font-size:0; line-height:0;"><img src="blank.gif" width="1" height="13"></td></tr>\
				<tr><td style="font-size:0; line-height:0;"><img src="http://www.citymaps.com/images/email-bg-t.gif" align="left" vspace="0" hspace="0" width="772" height="13"></td></tr>\
				<tr>\
					<td>\
						<table width="100%" cellpadding="0" cellspacing="0" border="0">\
							<tr>\
								<td width="85"></td>\
								<td width="1" bgcolor="#d5d5d5"></td>\
								<td width="29" bgcolor="#ffffff"></td>\
								<td width="542" bgcolor="#ffffff">\
									<table width="100%" cellpadding="0" cellspacing="0" border="0">\
										<tr><td style="font-size:0; line-height:0;"><img src="blank.gif" width="1" height="16"></td></tr>\
										<tr>\
											<td style="line-height:21px;">\
												<table width="100%" cellpadding="0" cellspacing="0" border="0">\
												<tr>\
													<td>\
														<center><a href="'+url+'"><img src="'+img+'"></a></center>\
													</td>\
												</tr>\
												<tr>\
													<td>\
														<br><br>\
														Hello,<br>\
														A friend of yours has shared something with you from <a href="'+url+'">CityMaps.com</a>\
														<br><br>$userMsg$\
														<br><br>\
														<strong>'+title+'</strong>\
														<br>'+desc+'<br>\
														<br><a href="'+url+'">Click here</a> to check it out!<br><br>\
													</td>\
												</tr>\
												</table>\
											</td>\
										</tr>\
										<tr><td style="font-size:0; line-height:0;"><img src="blank.gif" width="1" height="43"></td></tr>\
									</table>\
								</td>\
								<td width="29" bgcolor="#ffffff"></td>\
								<td width="1" bgcolor="#d5d5d5"></td>\
								<td width="85"></td>\
							</tr>\
						</table>\
					</td>\
				</tr>\
				<tr>\
					<td>\
						<table width="100%" cellpadding="0" cellspacing="0" border="0">\
							<tr>\
								<td width="85"></td>\
								<td width="1" bgcolor="#d5d5d5"></td>\
								<td width="29" bgcolor="#ffffff"></td>\
								<td width="542" bgcolor="#ffffff">\
									<table width="100%" cellpadding="0" cellspacing="0" border="0">\
										<tr>\
											<td style="line-height:21px;">\
												<font face="Arial, Helvetica, sans-serif" color="#666666" size="3" style="line-height:21px; font-size:16px;">\
													Enjoy your city!\
													<br>\
													<img src="http://www.citymaps.com/images/email-signature.gif" width="203" height="29" align="left" vspace="0" hspace="0" alt="The City Maps team" >\
												</font>\
											</td>\
										</tr>\
									</table>\
								</td>\
								<td width="29" bgcolor="#ffffff"></td>\
								<td width="1" bgcolor="#d5d5d5"></td>\
								<td width="85"></td>\
							</tr>\
						</table>\
					</td>\
				</tr>\
				<tr><td style="font-size:0; line-height:0;"><img src="http://www.citymaps.com/images/email-bg-b.gif" align="left" vspace="0" hspace="0" width="772" height="13"></td></tr>\
				<tr><td style="font-size:0; line-height:0;"><img src="blank.gif" width="1" height="20"></td></tr>\
			</table>\
		</td>\
	</tr>\
</table><br><br>';

return email_template;
}
