

/* Gigya Global Implementation
 *  Global configurations, global handlers, helper functions and customizations
 *
 *	Make-A-Wish Foundation of America
 *  Gene Brumblay
*/   

/*** GLOBAL CONFIGURATION ***/

// kluge for bug in Gigya dynamic markup
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
var gigya_width = 177;
var gigya_height = BrowserDetect.browser == 'Explorer'?121:141;

/*
if(BrowserDetect.browser == 'Explorer' && BrowserDetect.version == '6'){
	//alert(BrowserDetect.version); //debug
	gigya_height = 115;
	gigya_width =  170;
}
*/

// Omniture Site Catalyst Report Suite
//var gigya_report_suite = gigya_report_suite; // to do: make this active for production
var gigya_report_suite = 'mawwishorg';
var gigya_user = {};  // Gigya user object populated onLoad

// global Gigya configuration object
var conf = {
	// API Key
	//APIKey:'2_Y82PzwJ_chSFImHXaIDJClnLyJzmk-VFOavSsaNTzl6m901s_NNxRAS0xJ3bd3_N', // debug: development on localhost only
	//APIKey:'2_DCqy2Ew00QTtCMhids-DYASIqY3_8-OxcxE8ldihhF379nj-B0cQkE24U7XkP2Ve', // debug: development on dev.wish.org only
	APIKey:'2_j4f7OkUiHpBK4qK8IrWBJ28J8P0Ly87Zytpy1uuG3PbzRFU8IT3tYgXoIH5S5Txi', // production
	
	//disabledProviders:'facebook, twitter, yahoo, messenger, google, linkedin, myspace, aol, orkut, blogger, wordpress, typepad, livejournal, hyves, verisign, openid, netlog, bloglines, signon, orangefrance, mixi, livedoor', // A comma delimited list of provider names to disable in the Gigya service
	
	hideGigyaLink:true,	
	//shortURLs:'whenRequired'
	shortURLs:'always'
	
};


/*** GLOBAL EVENT HANDLERS ***/
// global events handler (there are four global events: onLogin, onLogout, onConnectionAdded, onConnectionRemoved

// the parameter object paramLoginHandler must be declared in GIGYA LOCAL code block  
function gigya_add_global_handlers(){  // to do: Ryan ezPublish CMS add pagename
	var paramGlobalEventsHandler = {	
		context:gigyaContext
		,cid: gigyaContext.page
		,onLogin:gigya_onLogin_eventHandler_curtain
		,onLogout:gigya_onLogout_eventHandler
		,onConnectionAdded:gigya_onAddConnection_eventHandler
		,onConnectionRemoved:gigya_onRemoveConnection_eventHandler		
	}
	 
	// add handlers
	gigya.services.socialize.addEventHandlers(conf, paramGlobalEventsHandler);
}


/*** LOGIN & LOGOUT ***/
// http://wiki.gigya.com/030_API_reference/010_Client_API/020_Methods/socialize.login
// http://wiki.gigya.com/030_API_reference/010_Client_API/020_Methods/socialize.logout
// http://wiki.gigya.com/030_API_reference/010_Client_API/020_Methods/z_socialize.disconnect


// Gigya login screen parameters (see wizard: http://www.gigya.com/site/partners/widgets.aspx#&&userstate=LoginPageAPI)
var paramsCurtainLogin=
{
	//useHTML:true
	hideGigyaLink:true
	,showTermsLink:false
	,showWhatsThis:true
	,whatsThisText: 'Sign in to share and participate with your friends.'
	,UIConfig: '<config><body><captions color="#ffffff"></captions><texts color="#616266"></texts><controls><snbuttons buttonsize="35"></snbuttons></controls><background background-color="#FFFFFF" frame-color="#005EAE"></background></body></config>'

	,context:gigyaContext // for Omniture context tracking
	,shortURLs:'whenRequired'
	,lastLoginIndication:'star'  //'border, welcome, none, star
	,cid:gigyaContext.page  // for Gigya context reporting (to do: dynamic on sub-pages)

	// custom parameters for div instead of native (not used)
	//,showCaption:true
	//,captionText:'Click on an icon to login to your favorite social network and begin sharing.'
	//,headerText: 'Click on an icon to login to your favorite social network and begin sharing.'
	//,height: 147
	//,width: 314
	//,containerID: 'componentDiv_login'	
	//,invite:gigyaInvite
	//,invite: objInvite // to do: If this parameter is specified then the "Invite" dialog will be displayed when a user logs-in to Facebook. You may find more information about the subject in Inviting Friends section in the Developer's Guide
	//,onLoad: gigya_homepageLogin_onLoadHandler  // to do: create function for skinning
	//,facebookExtraPermissions: string // to do: do we want to ask for any extended facebook permissions?  See http://developers.facebook.com/docs/authentication/permissions
};		


// presents the Gigya login widget on the homepage when the sign-in button is clicked
function gigya_login_onSignIn_click_curtain(eventObj) {
	
	//document.getElementById('HomepageRoundedBox3').innerHTML = '<div id="GigyaHomepageLoginHeader" style="height:50px; width:314px; background-color:#FFFFFF;">Click on an icon to login to your favorite social network and begin sharing.</div><div id="componentDiv" style="background-color:#FFFFFF;"></div><div id="GigyaHomepageLoginFooter" style="height:50px; width:314px; background-color:#FFFFFF;"><a href="javascript:gigya_homepage_login_closeSignIn();">(Close)</a></div>';  // to do: Ryan adjust styling and replace close with button that matches video, move to static div?
	gigya.services.socialize.showLoginUI(conf,paramsCurtainLogin);
	
	// to do: add email opt-in
	//alert("Event name: " + eventObj.eventName + "\nContext: " + eventObj['context']['page']  ); // debug
	
	// Omniture
	var s=s_gi(gigya_report_suite);
	s.linkTrackVars='prop20,prop21';
	s.prop20=eventObj.context.page;  // Gigya: Activity Location
	s.prop21=eventObj.eventName;  // Gigya: Activity
	s.tl(true,'o','Gigya Activity');
}



// onLogin handler
function gigya_onLogin_eventHandler_curtain(eventObj){
	//gigya.debug();  //debug

	gigya_buttons_state('visible');
	//gigya.services.socialize.showFeedUI(conf, paramsCurtainLogin);
	gigya.services.socialize.showFeedUI(conf, paramsFeed);
	
	//alert("Event name: " + eventObj.eventName + "\nContext: " + eventObj['context']['page']  ); // debug
	
	// email opt-in
	if(eventObj.user.email){
		//alert(eventObj.user.email);  //debug
		subscribe(eventObj.user.email);
	}
	
	// Omniture
	var s=s_gi(gigya_report_suite);
	s.linkTrackVars='evar3,prop19,prop20,prop21,events';
	s.evar1='Login: ' + eventObj.context.page; // Gigya: Login
	s.linkTrackEvents='event19';  // Gigya: Login
	s.prop20=eventObj.context.page;  // Gigya: Activity Location
	s.prop21=eventObj.eventName;  // Gigya: Activity
	s.prop19=eventObj.provider; // Gigya: Network Provider
	s.events='event19';  // login
	s.tl(true,'o','Gigya Activity');

}


// logs user out of Gigya
// triggers gigya_onLogout_eventHandler
function gigya_logout_curtain(){
	
	var tempParams = {
		cid: gigyaContext.page
		,context: gigyaContext
	};
	
	gigya.services.socialize.removeConnection(conf,{callback:gigya_onDisconnect_response});  // disconnect all networks on logout
	gigya.services.socialize.logout(conf,tempParams);  // logout from Gigya
	gigya_buttons_state('hidden');		
	
	// Omniture
	var s=s_gi(gigya_report_suite);
	s.linkTrackVars='prop20,prop21,events';
	s.linkTrackEvents='event25';  // Gigya: Logout
	s.prop20=gigyaContext.page;  // Gigya: Activity Location
	s.prop21='logout';  // Gigya: Activity
	s.events='event25';  // login
	s.tl(true,'o','Gigya Activity');
}


// onConnectionAdded handler
function gigya_onAddConnection_eventHandler(eventObj){
	
	//alert("Event name: " + eventObj.eventName + "\nContext: " + eventObj['context']['page']  ); // debug
	gigya.services.socialize.showFeedUI(conf, paramsFeed);
	
	// Omniture
	var s=s_gi(gigya_report_suite);
	s.linkTrackVars='prop19,prop20,prop21';
	s.prop20=eventObj.context.page;  // Gigya: Activity Location
	s.prop21=eventObj.eventName;  // Gigya: Activity
	s.prop19=eventObj.provider; // Gigya: Network Provider
	s.tl(true,'o','Gigya Activity');	
}

// NOT USED onConnectionRemoved handler
function gigya_onRemoveConnection_eventHandler(eventObj){
	
	//alert("Event name: " + eventObj.eventName + "\nContext: " + eventObj['context']['page']  ); // debug
	gigya.services.socialize.showFeedUI(conf, paramsFeed);
	
	/*/ Omniture
	var s=s_gi(gigya_report_suite);
	s.linkTrackVars='evar3,prop20,prop21,events';
	s.evar1='Login: ' + eventObj.context.page; // Gigya: Login
	s.linkTrackEvents='event25';  // Gigya: Logout
	s.prop20=eventObj.context.page;  // Gigya: Activity Location
	s.prop21=eventObj.eventName;  // Gigya: Activity
	s.events='event25';  // Gigya: Logout
	s.tl(true,'o','Gigya Activity');
	*/
}

// onLogout handler
function gigya_onLogout_eventHandler(eventObj){
	
	gigya_buttons_state('hidden');
	
	// reload feed, since it doesn't reload itself on logout (only on login)
	gigya.services.socialize.showFeedUI(conf, paramsFeed);
	
	//alert("Event name: " + eventObj.eventName + "\nContext: " + eventObj['context']['page']  ); // debug
	
	// Omniture
	var s=s_gi(gigya_report_suite);
	s.linkTrackVars='prop20,prop21';
	s.prop20=eventObj.context.page;  // Gigya: Activity Location
	s.prop21=eventObj.eventName;  // Gigya: Activity
	s.tl(true,'o','Gigya Activity');	
}

function gigya_onDisconnect_response(eventObj){
	
	//if(eventObj.errorCode == 0){ alert('Successfully Disconnected'); }
	
		// reload feed, since it doesn't reload itself on logout (only on login)
	gigya.services.socialize.showFeedUI(conf, paramsFeed);
}




/***  CURTAIN LOGIN & LOGOUT ***/
// http://wiki.gigya.com/030_API_reference/010_Client_API/020_Methods/socialize.login
// http://wiki.gigya.com/030_API_reference/010_Client_API/020_Methods/socialize.logout
// http://wiki.gigya.com/030_API_reference/010_Client_API/020_Methods/z_socialize.disconnect


// presents the Gigya login widget when the sign-in button is clicked
function gigya_curtain_login_onSignIn_click(eventObj) {

	gigya.services.socialize.showLoginUI(conf,paramsCurtainLogin);
	
	// to do: add email opt-in
	//alert("Event name: " + eventObj.eventName + "\nContext: " + eventObj['context']['page']  ); // debug
	
	// Omniture
	var s=s_gi(gigya_report_suite);
	s.linkTrackVars='prop20,prop21';
	s.prop20=eventObj.context.page;  // Gigya: Activity Location
	s.prop21=eventObj.eventName;  // Gigya: Activity
	s.tl(true,'o','Gigya Activity');
}


/***  CURTAIN FEED (showFeedUI) ***/
// http://wiki.gigya.com/030_API_reference/010_Client_API/020_Methods/socialize.showNewsfeedUI

function gigyaHandler_curtain_feed_onLoad(eventObj){
	gigya_checkLoginState();
}

var paramsFeed = {
	// GENERAL PARAMETERS
	containerID:'CurtainActivityFeed',  // Feed div container ID

	cid:gigyaContext.page,  // for Gigya reporting
	context: gigyaContext,  // for MAW tracking
	
	/*** design customization ***/
	width:gigya_width,
	height:gigya_height,
	siteName:'wish.org',
	borderColor:'#fff',
	separatorColor:'#3073BA',
	defaultColor:'#616266',
	activeTabColor:'#616266',
	inactiveTabColor:'#616266',		
	inactiveTabBackgroundColor:'#DFE0E0',	
	messageFontSize:'0.8em',		
	
	defaultBackgroundColor:'#FFFFFF',
				
	//everyoneHeader:'Recent community activity on wish.org',
	everyoneHeader:'Now being read and shared:',
	friendsHeaderLoggedOut:"Sign in to your favorite social network to see your friends' activity and share your experience on $siteName",
	friendsHeaderWithItems:"Your friends's activity:",
	meHeaderLoggedOut:'Sign in to your favorite social network to see your activity on wish.org',
	meHeaderWithItems:'Your activity on wish.org:',
	
	// INNER PLUGIN CONFIGURATION
	loginUI:'custom',
	
	// XML wizard: http://www.gigya.com/site/partners/widgets.aspx#&&userstate=LoginPageAPI
	//loginUIConfig:  // XML setting
	
	// replace register button, in effect hiding it.
	registerCustomLoginUIButtonImageURL:'http://www.wish.org/design/wish/images/gigya/spacer.gif',
	
	// to do: replace sign-in button
	//signinCustomLoginUIButtonImageURL:'http://www.wish.org/design/wish/images/gigya/SOMEBUTTON.gif',
				
	// register the widget onload activity
	onLoad: gigyaHandler_curtain_feed_onLoad,
	
	 // register to the "Sign In" button click
	onSigninClick: gigya_login_onSignIn_click_curtain,

	// NOT USED register to the "Register" button click
	onRegisterClick: function(eventObj) {
			//alert("Register button has been clicked");	
	}

};



/***  CURTAIN INVITE (showFriendsSelector) ***/
// http://wiki.gigya.com/030_API_reference/010_Client_API/020_Methods/socialize.showFriendSelectorUI
// http://wiki.gigya.com/030_API_reference/010_Client_API/020_Methods/socialize.showFriendSelectorUI 

var paramsInvite = {  // to do: change for subpages
	//height: 197
	//,width: 314
	//,containerID: 'componentDiv_invite'
	context:gigyaContext // for context tracking
	,captionText:'Invite Facebook and Twitter friends to wish.org. Don\'t see any friends?  Click Edit to sign in to Facebook or Twitter.'
	//,UIConfig: '<config><body><controls><snbuttons buttonsize="35"></snbuttons></controls><background background-color="#CACACA" frame-color="Transparent"></background></body></config>'  // XML setting
	,showEditLink:true  //Clicking the "Edit" link opens a popup dialog that enables the user to edit his connection status to each of the social networks.
	,showTermsLink:false
	,hideGigyaLink:true
	,cid:gigyaContext.page
	//,enabledProviders:"linkedin,twitter"
	,onLoad:gigya_invite_onLoad_eventHandler
	,onSelectionDone:gigya_invite_onSelection_eventHandler_curtain
	,onClose:gigya_invite_onClose_eventHandler
	
};

// triggers friends invite widget
function gigya_invite_curtain(){
	
	//gigya.debug() // debug
	
	gigya.services.socialize.showFriendSelectorUI(conf, paramsInvite);	// paramsInvite is set in GIGYAL LOCAL code block
	
	// Omniture
	var s=s_gi(gigya_report_suite);
	s.linkTrackVars='prop20,prop21';
	s.prop20=gigyaContext.page;  // Gigya: Activity Location
	s.prop21='Invite click';  // Gigya: Activity
	s.tl(true,'o','Gigya Activity');
	
}

// showFriendSelectorUI onLoad handler
function gigya_invite_onLoad_eventHandler(eventObj){

	//gigya_buttons_state('visible');
	//gigya.services.socialize.showFriendSelectorUI(conf, paramsInvite);
	
	// Omniture
	var s=s_gi(gigya_report_suite);
	s.linkTrackVars='prop20,prop21';
	s.prop20=eventObj.context.page;  // Gigya: Activity Location
	s.prop21='Invite ' + eventObj.eventName;  // Gigya: Activity
	s.tl(true,'o','Gigya Activity');

}

// showFriendSelectorUI onClose handler
function gigya_invite_onClose_eventHandler(eventObj){
	
	show_original();  // to do: Ryan: make sure show_* functions check for context, so they will work on both homepage and outlyer
	//gigya_buttons_state('visible');
	//gigya.services.socialize.showFriendSelectorUI(conf, paramsInvite);
	
	// reload feed, since it doesn't reload itself on logout (only on login)
	gigya.services.socialize.showFeedUI(conf, paramsFeed);
	
	// Omniture
	var s=s_gi(gigya_report_suite);
	s.linkTrackVars='prop20,prop21';
	s.prop20=eventObj.context.page;  // Gigya: Activity Location
	s.prop21='Invite ' + eventObj.eventName;  // Gigya: Activity
	s.tl(true,'o','Gigya Activity');

}

function gigya_invite_onSelection_eventHandler_curtain(eventObj){
	
	//show_original();  // to do: Ryan: make sure show_* functions check for context, so they will work on both homepage and outlyer
	//gigya_buttons_state('visible');	
	//gigya.debug();  //debug
	
	var paramsSendNotification = {
		recipients:eventObj.friends,
		body: 'Hi, I am visiting ' + eventObj.context.pageURL + ' and thought you would find it interesting and inspiring.  Please join me.',
		subject:"A message from " + gigya_user.nickname,
		callback:gigya_sendNotification_eventHandler_curtain,
		cid:eventObj.context.page
	};
	
	gigya.services.socialize.sendNotification(conf,paramsSendNotification);
	
	//alert(eventObj.friends.getSize());  //debug
	
	// Omniture
	var s=s_gi(gigya_report_suite);
	s.linkTrackVars='prop20,prop21,prop22';
	s.prop20=eventObj.context.page;  // Gigya: Activity Location
	s.prop21=eventObj.eventName;  // Gigya: Activity
	s.prop22=eventObj.friends.getSize();  // Gigya: Activity
	s.tl(true,'o','Gigya Activity');

}

// sendNotification event handler
function gigya_sendNotification_eventHandler_curtain(eventObj){
	
		document.getElementById('GigyaHomepageLoginSubHeader').innerHTML = "Invitations sent.";
	document.getElementById('GigyaHomepageLoginSubHeader').style.color = "#2E8C39";
	
	/*
	if ( eventObj.errorCode == 0 ) {                       
		//alert('Notification has been sent');   
	}   
	else {   
		//alert('Error :' + eventObj.errorMessage);    
	}
	*/
}



/***  CURTAIN SHARE (showShareUI) ***/
// http://wiki.gigya.com/030_API_reference/010_Client_API/020_Methods/socialize.showShareUI


// renders share widget
// http://wiki.gigya.com/020_Developer_Guide/60_Publishing_User_Actions/010_The_Share_Widget/Advanced_Report#Including_Media_Item.2fs
// http://wiki.gigya.com/030_Gigya_Socialize_API_2.0/030_API_reference/Objects/UserAction_object
function gigya_share_curtain(_custom){
	
	var _initialView = '';
	var _disabledProviders = '';
	
	// check for custom message
	var _message = 'I just visited the Make-A-Wish Foundation of America website. Join me and find out how you can help grant wishes!';
	// removed to honor Facebook standard of use issue:
	//var _message = '';
	if( typeof(gigya_share_message) != 'undefined'){
		if(gigya_share_message.all_others.length){
			  _message = gigya_share_message.all_others;
		} 
	}
	
	var action = new gigya.services.socialize.UserAction();   
	action.setTitle(gigyaContext.pageTitle);

	// gigya_share_image object set in LOCAL code block
	action.addMediaItem(gigya_share_image);

  // first see if this is a callback from an add-connection event	
  if(typeof _custom == 'object' && _custom.errorCode == 0){	  
	switch(_custom.context.connection ){
	 case 'twitter':
	  _initialView = 'share';
	  _disabledProviders = 'facebook,linkedin,google,yahoo,myspace,messenger,orkut';
	  
	  // check for custom message
	  if(gigya_share_message.twitter.length){
		  _message = gigya_share_message.twitter;
		  action.setTitle('');
	  }
	  break;
	 
	 default:	  
	  _initialView = 'share';
	  _disabledProviders = '';
	  break;
		
	} // end switch	  
  }
  
  // otherwise proceed with presenting the share or login UI
  else{
	switch(_custom)
	{
	 case 'email':
	  _initialView = 'email';
	  _disabledProviders = 'google,yahoo,myspace,messenger,orkut';
	  break;
	case 'facebook':
	  _initialView = 'share';
	  _disabledProviders = 'twitter,linkedin,google,yahoo,myspace,messenger,orkut';
	  _message = "";
	  break;
	case 'twitter':
	  //_initialView = 'share';
	  //_disabledProviders = 'facebook,linkedin,google,yahoo,myspace,messenger,orkut';
	  gigya.services.socialize.addConnection(conf,{callback:gigya_share_curtain, provider:'twitter', context:{connection:'twitter'}});  
	  return;
	  break;
	case 'more':
	  _initialView = 'share';
	  _disabledProviders = '';
	  break;
	default:	  
	  _initialView = 'share';
	  _disabledProviders = '';
	  break;
	} 
  }// end else
	

	action.addActionLink('Visit www.wish.org', 'http://www.wish.org');
	action.setUserMessage(_message);
	action.setDescription(gigyaContext.pageDescription);
	action.setLinkBack(gigyaContext.pageURL);

	var paramsShare ={
		userAction:action
		,successMessage:true
		,grayedOutScreenOpacity:80
		,context:gigyaContext
		,cid:gigyaContext.page
		,shortURLs:'whenRequired' 
		,sessionExpiration:0  // 0 ends the session when the browser closes
		//,useHTML:true  // false = use Flash version of share UI
		//,scope:'both'  //the feed item will be published internally to the site's feed stream and externally to social networks
		,scope:'external'  // do not publish to feed
		,privacy:'friends'	// public|friends|private  Public items appear in all tabs with the publisher's identity (user name and image)
		,showEmailButton:true
		,onLoad:gigya_share_onLoad_eventHandler
		,onSend:gigya_share_onSend_eventHandler
		,onClose:gigya_share_onClose_eventHandler
		,initialView:_initialView
		//,defaultProviders:_defaultProviders
		,disabledProviders:_disabledProviders
		
	}
	
	//alert(paramsShare.initialView); //debug
	
	gigya.services.socialize.showShareUI(conf,paramsShare); 
	
}

function gigya_share_onLoad_eventHandler(eventObj){
	
		// Omniture
	var s=s_gi(gigya_report_suite);
	s.linkTrackVars='prop20,prop21';
	s.prop20=eventObj.context.page;  // Gigya: Activity Location
	s.prop21='Share ' + eventObj.eventName;  // Gigya: Activity
	s.tl(true,'o','Gigya Activity');	
}


function gigya_share_onSend_eventHandler(eventObj){
	
		// Omniture
	var s=s_gi(gigya_report_suite);
	s.linkTrackVars='prop20,prop21,prop23';
	s.prop20=eventObj.context.page;  // Gigya: Activity Location
	if(eventObj.recipients){
		s.prop23 = eventObj.recipients.length;  // Gigya email shares
		s.prop21='Share (email) ' + eventObj.eventName;  // Gigya: Activity
	}else{
		s.prop23 = 1;  // Gigya posts
		s.prop21='Share (posts) ' + eventObj.eventName;  // Gigya: Activity
	}
	s.tl(true,'o','Gigya Activity');

	publish_to_feed_after_post();
	
	
}

function gigya_share_onClose_eventHandler(eventObj){
		gigya.services.socialize.showFeedUI(conf, paramsFeed);
		gigya_checkLoginState();
}



/*** CURTAIN PUBLISH ACTION ***/
// http://wiki.gigya.com/030_API_reference/010_Client_API/020_Methods/socialize.publishUserAction

// NOT USED Display a status message according to the response from publishUserAction.
function publishAction_callback(response)
{
	/*
	switch (response.errorCode )
	{
		case 0:
			document.getElementById('status').style.color = "green";
			document.getElementById('status').innerHTML = 
					"Activity Feed item published, and will be presented shortly on the Activity Feed Plugin.";
			break;
		default:
			document.getElementById('status').style.color = "red";
			document.getElementById('status').innerHTML = 
					"Unable to send Feed item. status=" 
					+ response.errorCode + "; " + response.errorMessage + ";<br />" 
					+ "Please make sure you are logged in to Gigya. You may log in using the Login Plugin inside the 'Me' tab above" ;
	}
	*/
}



// Publish an Activity Feed internally (only to site scope)
// This method is associated with the "btnPublishAction" click
function publish_to_feed() {
	
	// if the user is not logged in or the page should not be auto-published, then do nothing
	if(!gigya_user.isLoggedIn || !gigya_auto_publish){
		return;
	}
	// Construct the UserAction Object
	var action = new gigya.services.socialize.UserAction();	 
	action.addMediaItem(gigya_share_image);
	action.addActionLink('Visit www.wish.org', 'http://www.wish.org');
	action.setUserMessage('I just visited the Make-A-Wish Foundation of America website. Join me and find out how you can help grant wishes!'); // Setting the User Message
	action.setLinkBack(gigyaContext.pageURL); // Adding a Link Back		
	//action.setTitle(gigyaContext.pageTitle); // Setting the Title			
	//action.setDescription(gigyaContext.pageDescription); // Setting the Description
	action.setTitle(gigyaContext.pageDescription); // Setting the Title			
	action.setDescription(''); // Setting the Description
	 
	// Parameters for the publishUserAction method, 
	var paramsPublish = 
	{
		userAction:action, // including the UserAction object
		scope: 'both', // for production (published to both internal and social networks)
		//scope: 'internal', // debug: for development (published internally only)
		//privacy: 'public',  // the user action will appear in all tabs with the publisher's identity (user name and image).
		//privacy: 'private',  // (default) the user action will appear in the 'Me' tab, and anonymously in the 'Friends' and 'Everyone' tabs.
		privacy: 'friends' // the user action will appear in the 'Friends' and 'Me' tabs with identity and anonymously in the 'Everyone' tab of the site's Activity Feed Plugin
		//,callback:publishAction_callback // debug
	};
	
	// Publish the User Action
	gigya.services.socialize.publishUserAction(conf, paramsPublish);

}		



function publish_to_feed_after_post() {
	

	// Construct the UserAction Object
	var action = new gigya.services.socialize.UserAction();	 
	action.addMediaItem(gigya_share_image);
	action.addActionLink('Visit www.wish.org', 'http://www.wish.org');
	action.setUserMessage('I just visited the Make-A-Wish Foundation of America website. Join me and find out how you can help grant wishes!'); // Setting the User Message
	action.setLinkBack(gigyaContext.pageURL); // Adding a Link Back		
	//action.setTitle(gigyaContext.pageTitle); // Setting the Title			
	//action.setDescription(gigyaContext.pageDescription); // Setting the Description
	action.setTitle(gigyaContext.pageDescription); // Setting the Title			
	action.setDescription(''); // Setting the Description
	 
	// Parameters for the publishUserAction method, 
	var paramsPublish = 
	{
		userAction:action, // including the UserAction object
		//scope: 'both', // for production (published to both internal and social networks)
		scope: 'internal', // publish to feed only
		//privacy: 'public',  // the user action will appear in all tabs with the publisher's identity (user name and image).
		//privacy: 'private',  // (default) the user action will appear in the 'Me' tab, and anonymously in the 'Friends' and 'Everyone' tabs.
		privacy: 'friends' // the user action will appear in the 'Friends' and 'Me' tabs with identity and anonymously in the 'Everyone' tab of the site's Activity Feed Plugin
		//,callback:publishAction_callback // debug
	};
	
	// Publish the User Action
	gigya.services.socialize.publishUserAction(conf, paramsPublish);

}	



// hides the Gigya login widget on the homepage when the sign-in button is clicked
function gigya_homepage_login_closeSignIn() {
	show_original();

}


/*** GLOBAL HELPER FUNCTIONS ***/

function gigya_show(objID){
	document.getElementById(objID).style.display = "block";
}

function gigya_hide(objID){
	document.getElementById(objID).style.display = "none";
}

function load_activity_feed(eventObj){

	// show the Activity Feed Plugin inside the 'ActivityFeed' <div>:   
	gigya.services.socialize.showFeedUI(conf, paramsFeed);	
	gigya_user = eventObj.user;

	// automatically publish action to feed after gigya_user object is set
	publish_to_feed();
	
	//alert(gigya_user.nickname); // debug
	
}


// hide or show close button based on login state
function gigya_checkLoginState(){
	gigya.services.socialize.getUserInfo(conf,{callback:gigya_checkLoginState_action});  
}

function gigya_checkLoginState_action(responseObj){
	if ( responseObj.errorCode == 0 ) {
		if( responseObj.user.isLoggedIn){
			gigya_buttons_state('visible');
		}
		else{
			gigya_buttons_state('hidden');
		}
	}
}


// change logout button state: action = hidden or visible
function gigya_buttons_state(_state){
	
	var altState = _state == 'visible'?'none':'block';
	var state = _state == 'visible'?'block':'none';
	
	if(document.getElementById('gigyaCurtainFooterButtons')){
		document.getElementById('gigyaCurtainFooterButtons').style.display = state;	
	}
	
	
	if(document.getElementById('CurtainActivityFeedFooter')){
		document.getElementById('CurtainActivityFeedFooter').style.display = altState;	
	}
}


function gigya_onLoad() {
	
	// get user info
	gigya.services.socialize.getUserInfo(conf, { callback: load_activity_feed});
	//gigya.debug(); // debug
	//alert(gigyaContext.pageURL);
} 

function show_original(){
	
}

/***** REACTION BUTTON IMPLEMENTATION *****/

// array of reaction objects
var iconWishReactions=[
	{
        ID: 'hopeful',
        iconImgUp:'/design/wish/images/btn.reaction.hopeful.gif',
		iconImgOver:'/design/wish/images/btn.reaction.hopeful.gif',
        tooltip:'This makes me feel hopeful',
        feedMessage: 'I found this hopeful!',    
		showCounts:'right',    
		noButtonBorders:'true',
		headerText:'This makes you feel hopeful,'
	}
	,{
        ID: 'reflective',
        iconImgUp:'/design/wish/images/btn.reaction.reflective.gif',
		iconImgOver:'/design/wish/images/btn.reaction.reflective.gif',
        tooltip:'This makes me feel reflective',
        feedMessage: 'I found this reflective!',
		showCounts:'right',
		noButtonBorders:'true',
		headerText:'This makes you feel reflective,'
	}
	,{
        ID: 'inspirational',
        iconImgUp:'/design/wish/images/btn.reaction.inspired.gif',
		iconImgOver:'/design/wish/images/btn.reaction.inspired.gif',
        tooltip:'This inspired me',
        feedMessage: 'I found this inspirational!',
		showCounts:'right',
		noButtonBorders:'true',
		headerText:'This inspired you,'
	}
]; 	

// track reaction activity in Omniture -- not used
function gigya_track_reaction_click(eventObj){
	
	// Omniture
	var s=s_gi(gigya_report_suite);
	s.linkTrackVars='prop31';
	s.prop31=eventObj.context.page + ' - ' + eventObj.reaction.ID;  // Gigya: Reaction Location + Reaction
	s.tl(true,'o','Gigya Activity');
}

function gigya_track_reaction_share(eventObj){
	
	// Omniture
	var s=s_gi(gigya_report_suite);
	s.linkTrackVars='prop32';
	s.prop32=eventObj.context.page + ' - ' + eventObj.providers;  // Gigya: Reaction Location + comma-seprated list of providers posted to
	s.tl(true,'o','Gigya Activity');
}

// remaining code in GIGYA STORY LOCAL code block



/*** CUSTOMIZATIONS: JS functions used to manipulate the Gigya DOM after loading to customize the look and feel ***/



/***** UTILITY FUNCTIONS *****/



// add a function to the page onLoad event
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


// JSON subscribe 
function subscribe(_email){
	
	// send json request
	var JSONrequest = "http://www.wish.org/extra/gigya/email_optin_json.php?email=" + _email;
    //var JSONrequest = "http://www.wish.org/extra/gigya/email_optin_json.php?email=" + _email + '&callback=json_debug';  // debug
    var head = document.getElementsByTagName("head").item(0);
    var script = document.createElement("script");
    script.setAttribute("type", "text/javascript");
    script.setAttribute("src", JSONrequest);
    head.appendChild(script);
	
 	return true; 
}

function json_debug(_msg){
	alert(_msg);
}

		
		
// add global event handlers
gigya_add_global_handlers();

// kluge for bug in Gigya dynamic markup
//var gigya_height = BrowserDetect.browser == 'Explorer'?117:137
		
// add Gigya page onLoad function
addLoadEvent(gigya_onLoad);


