﻿	    // Configuration Object
	    var conf = { APIKey: '2_IlgsfCYEN3Vkzg5mu_pdfdeKn535WT-0PUV8NfjDFPdy8402aMqCl6zfjd36eyul' };

        // Create and Publish User's Action
        // This method is associated with the "showShareUI" click
        function showShareUI(url, imageUrl) {
            var desc = "";
            // Constructing a UserAction Object
            var act = new gigya.services.socialize.UserAction();

            // Setting the default user message 
            // (will be presented as default text in the edit box on the Share UI)
            act.setUserMessage("Reading about " + document.title );

            // Setting the title and description 
            // (will be presented in the preview on the Share UI)
            act.setTitle(document.title);
            desc = gigyaGetDesc();

            act.setDescription(desc);
           
            // Setting a link back to the publishing source
            act.setLinkBack(url);

            // Adding Action Link
            act.addActionLink("Check out CruiseNow",
		        "http://www.cruisenow.com/");

            // Adding an image (will be presented in the preview on the Share UI)
            if ( imageUrl != '' ) {
                var image = {
                    src: imageUrl,
                    href: url,
                    type: 'image'
                }
                act.addMediaItem(image);
            }

            // Parameters for the showShareUI method, including the UserAction object
            var params =
			{
			    userAction: act  // The UserAction object enfolding the newsfeed data.			                                  
				, onError: onError  // onError method will be summoned if an error occurs. 
				, onSendDone: onSendDone // onError method will be summoned after 
			    // Gigya finishes the publishing process.

				, showMoreButton: true // Enable the "More" button and screen
				, showEmailButton: true // Enable the "Email" button and screen
	    			, useHTML: true  // Use the HTML implementation of the Plugin (rather then Flash implementation)
				, scope: 'both'  // Display on both internal and external feeds
                                , privacy: 'public'  // Allow users to see shared information
			};

            // Show the "Share" dialog
            gigya.services.socialize.showShareUI(conf, params);

        }


        // Create and Publish User's Action
        // This method is associated with the "showShareUI" click
        function showShareUITitle(url, imageUrl, title) {
            var desc = "";
            // Constructing a UserAction Object
            var act = new gigya.services.socialize.UserAction();

            // Setting the title and description 
            // (will be presented in the preview on the Share UI)
            if ( title == '' ) title = document.title;

            act.setUserMessage("Reading about " + title + " on CruiseNow.com");

            // Setting the title and description 
            // (will be presented in the preview on the Share UI)
            act.setTitle(title);
            act.setDescription("Check out this and other great deals now on CruiseNow.");
           
            // Setting a link back to the publishing source
            act.setLinkBack(url);

            // Adding Action Link
            act.addActionLink("Check out CruiseNow",
		        "http://www.cruisenow.com/");

            // Adding an image (will be presented in the preview on the Share UI)
            if ( imageUrl != '' ) {
                var image = {
                    src: imageUrl,
                    href: url,
                    type: 'image'
                }
                act.addMediaItem(image);
            }

            // Parameters for the showShareUI method, including the UserAction object
            var params =
			{
			    userAction: act  // The UserAction object enfolding the newsfeed data.			                                  
				, onError: onError  // onError method will be summoned if an error occurs. 
				, onSendDone: onSendDone // onError method will be summoned after 
			    // Gigya finishes the publishing process.

				, showMoreButton: true // Enable the "More" button and screen
				, showEmailButton: true // Enable the "Email" button and screen
	    			, useHTML: true  // Use the HTML implementation of the Plugin (rather then Flash implementation)
				, scope: 'both'  // Display on both internal and external feeds
                                , privacy: 'public'  // Allow users to see shared information
			};

            // Show the "Share" dialog
            gigya.services.socialize.showShareUI(conf, params);

        }

        // Create and Publish User's Action
        // This is an automatic call after watching a CruiseNow.com video.
        function showShareUIVideo(url, imageUrl, title) {
            var desc = "";
            // Constructing a UserAction Object
            var act = new gigya.services.socialize.UserAction();

            if ( title == '' ) title = document.title;
            // Setting the default user message 
            // (will be presented as default text in the edit box on the Share UI)
            act.setUserMessage("Just watched a CruiseNow.com video: " + title );

            // Setting the title and description 
            // (will be presented in the preview on the Share UI)
            act.setTitle(title);
            desc = gigyaGetDesc();

            act.setDescription("Just watched a great video on CruiseNow.com");
           
            // Setting a link back to the publishing source
            act.setLinkBack(document.URL);
            // Ignoring the passed in URL since it is a direct link to the flv file.

            // Adding Action Link
            act.addActionLink("Check out CruiseNow",
		        "http://www.cruisenow.com/");

            // Adding an image (will be presented in the preview on the Share UI)
            if ( imageUrl != '' ) {
                var image = {
                    src: imageUrl,
                    href: url,
                    type: 'image'
                }
                act.addMediaItem(image);
            }

            // Parameters for the showShareUI method, including the UserAction object
            var params =
			{
			    userAction: act  // The UserAction object enfolding the newsfeed data.			                                  
				, onError: onError  // onError method will be summoned if an error occurs. 
				, onSendDone: onSendDone // onError method will be summoned after 
			    // Gigya finishes the publishing process.

				, showMoreButton: true // Enable the "More" button and screen
				, showEmailButton: true // Enable the "Email" button and screen
	    			, useHTML: true  // Use the HTML implementation of the Plugin (rather then Flash implementation)
				, scope: 'both'  // Display on both internal and external feeds
                                , privacy: 'public'  // Allow users to see shared information
			};

            // Show the "Share" dialog
            gigya.services.socialize.showShareUI(conf, params);

        }

        // Create and Publish User's Action
        // This method is associated with the "showShareUICruise" click
        function showShareUICruise(dealTitle, dealID, lineID, shipID, imageUrl) {
            var linkbackUrl = 'http://www.cruisenow.com/cruisedealdetail.aspx?tab=itinerary&CruiseDeal=' + dealID + '&CruiseLine=' + lineID + '&CruiseShip=' + shipID;

            // Constructing a UserAction Object
            var act = new gigya.services.socialize.UserAction();

            // Setting the default user message 
            // (will be presented as default text in the edit box on the Share UI)
            act.setUserMessage("Reading about " + dealTitle + " on CruiseNow.com");

            // Setting the title and description 
            // (will be presented in the preview on the Share UI)
            act.setTitle(dealTitle);
            act.setDescription("Check out this and other great deals now on CruiseNow.");
           
            // Setting a link back to the publishing source
            act.setLinkBack(linkbackUrl);

            // Adding Action Link
            act.addActionLink("Check out CruiseNow",
		        "http://www.cruisenow.com/");

            // Adding an image (will be presented in the preview on the Share UI)
            if ( imageUrl != '' ) {
                imageUrl = 'http://www.cruisenow.com/' + imageUrl
                var image = {
                    src: imageUrl,
                    href: linkbackUrl,
                    type: 'image'
                }
                act.addMediaItem(image);
            }

            // Parameters for the showShareUI method, including the UserAction object
            var params = {
                userAction: act  // The UserAction object enfolding the newsfeed data.			                                  
                , onError: onError  // onError method will be summoned if an error occurs. 
                , onSendDone: onSendDone // onError method will be summoned after 
                // Gigya finishes the publishing process.
                , showMoreButton: true // Enable the "More" button and screen
                , showEmailButton: true // Enable the "Email" button and screen
                , useHTML: true  // Use the HTML implementation of the Plugin (rather then Flash implementation)
                , scope: 'both'  // Display on both internal and external feeds
                , privacy: 'public'  // Allow users to see shared information
            };

            // Show the "Share" dialog
            gigya.services.socialize.showShareUI(conf, params);

        }

        // Create and Publish User's Action
        // This method is associated with the "showShareUIReview" click
        function showShareUIReview(lineID, lineName, shipID, shipName, review, firstName, thumbnail) {
            var linkbackUrl = 'http://www.cruisenow.com/CruiseShipReviewList.aspx?CruiseLine=' + lineID + '&CruiseShip=' + shipID;

            // Constructing a UserAction Object
            var act = new gigya.services.socialize.UserAction();

            // Setting the default user message 
            // (will be presented as default text in the edit box on the Share UI)
            act.setUserMessage(review);

            // Setting the title and description 
            // (will be presented in the preview on the Share UI)
            act.setTitle(firstName + " just submitted a review for " + lineName + " " + shipName + " on CruiseNow.Com.");
            act.setDescription(review);
           
            // Setting a link back to the publishing source
            act.setLinkBack(linkbackUrl);

            // Adding Action Link
            act.addActionLink("Check out CruiseNow",
		        "http://www.cruisenow.com/");

            // Adding an image (will be presented in the preview on the Share UI)
            if ( thumbnail != "" ) {
                imageUrl = thumbnail;
            } else {
                imageUrl = 'http://cdn.gigya.com/site/images/bsAPI/Placeholder.gif';
            }

            var image = {
                src: imageUrl,
                href: linkbackUrl,
                type: 'image'
            }
            act.addMediaItem(image);

            // Parameters for the showShareUI method, including the UserAction object
            var params = {
                userAction: act  // The UserAction object enfolding the newsfeed data.			                                  
                , onError: onError  // onError method will be summoned if an error occurs. 
                , onSendDone: onSendDone // onError method will be summoned after 
                // Gigya finishes the publishing process.
                , showMoreButton: true // Enable the "More" button and screen
                , showEmailButton: true // Enable the "Email" button and screen
                , useHTML: true  // Use the HTML implementation of the Plugin (rather then Flash implementation)
                , scope: 'both'  // Display on both internal and external feeds
                , privacy: 'public'  // Allow users to see shared information
            };

            // Show the "Share" dialog
            gigya.services.socialize.showShareUI(conf, params);

        }

        // onError event handler
        function onError(event) {
            alert('An error has occured' + ': ' + event.errorCode + '; ' + event.errorMessage);
        }

        // onSendDone event handler. 
        // Displays in the status field, the list of providers to which the newsfeed has been 
        // successfully published.
        function onSendDone(event) {
/*
            document.getElementById('status').style.color = "green";
            document.getElementById('status').innerHTML =
                            'The newsfeed has been posted to: '
		            + event.providers;
*/
        }

        function gigyaGetDesc(){
            var metas = document.getElementsByTagName('meta');
            for(var i=0;i<metas.length;i++){
                if(metas[i].name.toLowerCase() == 'description'){
                    if ( metas[i].content != "" ) return metas[i].content;
                }
            }
            return null;//or empty string if you prefer
        }

