var videoTitleContentGigya = '';
var gigyadescription = '';
var gigyamessage = 'Post your comment here';
var gigyaimagesrc = 'http://i.cdn.turner.com/v5cache/TCM//images/gigya/default_image_80x80.jpg';
var gigyaPageURL = window.location.pathname;
var gigyaPageView = 'share';



  jQuery(document).ready(function () {
		 jQuery("<div id='status'></div>").prependTo("#footer");
  });   


			/* Checked for the Area of the site to set the context */
				var pathArray = window.location.pathname.split( '/' );
				var pageLocation = pathArray[2] ; 
				var pageNameNoBreak = pathArray[5];

if (pageLocation == 'title') {

	switch (pageNameNoBreak){
		case "full-credits.html":
			videoTitleContentGigya = 'Full Credits for';
			gigyadescription = 'These are the full credits for';
		break;
		case "full-synopsis.html":
			videoTitleContentGigya = 'Full Synopsis for';
			gigyadescription = 'This is the Full Synopsis for';
		break;
		case "notes.html":
			videoTitleContentGigya = 'Notes for';
			gigyadescription = 'These are the notes for';
		break;
		case "music.html":
			videoTitleContentGigya = 'Music for';
			gigyadescription = 'These are the music credits for';
		break;
		case "screenplay-info.html":
			videoTitleContentGigya = 'Screenplay Info for';
			gigyadescription = 'This is the screenplay Info for';
		break;
		case "original-print-info.html":
			videoTitleContentGigya = 'Original Print Info for';
			gigyadescription = 'This is the Original Print Info for';
		break;
		case "genre.html":
			videoTitleContentGigya = 'Genre for';
			gigyadescription = 'This is the genre for';
		break;
		case "keywords.html":
			videoTitleContentGigya = 'Keywords for';
			gigyadescription = 'These are the keywords for';
		break;
		case "user-reviews.html":
			videoTitleContentGigya = 'User Reviews for';
			gigyadescription = 'These are the user reviews for';
		break;
		case "other-reviews.html":
			videoTitleContentGigya = 'Other Reviews for';
			gigyadescription = 'These are external reviews for';
		break;
		case "articles.html":
			videoTitleContentGigya = 'Articles for';
			gigyadescription = 'These are the articles for';
		break;
		case "money.html":
			videoTitleContentGigya = 'Money for';
			gigyadescription = 'This is the Money Info for';
		break;
		case "awards.html":
			videoTitleContentGigya = 'Awards for';
			gigyadescription = 'These are the awards for';
		break;
		case "quotes.html":
			videoTitleContentGigya = 'Quotes for';
			gigyadescription = 'These are the quotes for';
		break;
		case "trivia.html":
			videoTitleContentGigya = 'Trivia for';
			gigyadescription = 'This is the trivia for';
		break;
		case "home-video-reviews.html":
			videoTitleContentGigya = 'Home Video Reviews for';
			gigyadescription = 'These are the home video reviews for';
		break;
		case "misc-notes.html":
			videoTitleContentGigya = 'Misc Notes for';
			gigyadescription = 'These are the misc notes for';
		break;
		case "alternate-versions.html":
			videoTitleContentGigya = 'Alternate Versions for';
			gigyadescription = 'These are the alternate versions for';
		break;
		case "theatrical-aspect-ratio.html":
			videoTitleContentGigya = 'Theatrical Aspect Ratio for';
			gigyadescription = 'This is the theatrical aspect ratio for';
		break;
		case "fan-sites.html":
			videoTitleContentGigya = 'Fan Sites for';
			gigyadescription = 'These are the fan sites for';
		break;
	
		default : videoTitleContentGigya = 'Overview for';
				  gigyadescription = 'These is the overview for';
	}

}

if (pageLocation == 'person') {

	switch (pageNameNoBreak){
		case "biography.html":
			videoTitleContentGigya = 'Biography for';
			gigyadescription = 'This is the biography for';
		break;
		case "filmography.html":
			videoTitleContentGigya = 'Filmography for';
			gigyadescription = 'This is the filmography for';
		break;
		case "filmography-with-synopsis.html":
			videoTitleContentGigya = 'Filmography for';
			gigyadescription = 'This is the filmography for';
		break;
		case "milestones.html":
			videoTitleContentGigya = 'Milestones for';
			gigyadescription = 'These are the milestones for';
		break;
		case "education.html":
			videoTitleContentGigya = 'Education for';
			gigyadescription = 'This is Education info for';
		break;
		case "companions.html":
			videoTitleContentGigya = 'Companions for';
			gigyadescription = 'These are the companions for';
		break;
		case "family.html":
			videoTitleContentGigya = 'Family for';
			gigyadescription = 'This is family info for';
		break;
		case "bibliography.html":
			videoTitleContentGigya = 'Bibliography for';
			gigyadescription = 'This is the bibliography for';
		break;
		case "notes.html":
			videoTitleContentGigya = 'Notes for';
			gigyadescription = 'These are notes for';
		break;
		case "fan-comments.html":
			videoTitleContentGigya = 'Fan Comments for';
			gigyadescription = 'These are fan comments for for';
		break;
		case "fan-sites.html":
			videoTitleContentGigya = 'Fan Sites for';
			gigyadescription = 'These are fan sites for';
		break;
		case "videos.html":
			videoTitleContentGigya = 'Videos for';
			gigyadescription = 'These are the videos for';
		break;
		case "archives.html":
			videoTitleContentGigya = 'Archives for';
			gigyadescription = 'These are the archives for';
		break;
		default : videoTitleContentGigya = 'Overview for';
				  gigyadescription = 'These is the overview for';
	}

}




var conf =
{
    APIKey: '2_v-HnA_O9UxHRbMX2Ac_9BDBHXPgSkDMws690A95pS077DhlQkb8AmvDsKbbh1hIx'
};

function onLoad()
{
    // get user info
    gigya.services.socialize.getUserInfo(conf,{callback:renderUI});

    // register for connect status changes
    gigya.services.socialize.addEventHandlers(conf, { onConnect:renderUI, onDisconnect:renderUI}   );

}


// Create and Publish User's Action
// This method is associated with the "btnPublishAction" click

function showShareUI(usermessage, title, description, thumb, url, view) {

 	// cleaning inputs
	var strToReplace = new RegExp( '\&apos;', 'g' );

    // 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(usermessage);


    // Setting the title and description
    // (will be presented in the preview on the Share UI)

		title = title.replace( strToReplace, "'");
	    act.setTitle(title);

		description = description.replace( strToReplace, "'");
		description = description.replace(/(<([^>]+)>)/ig,"");   // Removes the HTML from the string
	    act.setDescription(description);


    // Setting a link back to the publishing source
    act.setLinkBack(url);

    // Adding Action Link
    act.addActionLink("Post your comment here");

    // Adding an image (will be presented in the preview on the Share UI)

	    var image = {
	        src: thumb,
	        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.
	    enabledProviders: "Facebook, Twitter, MySpace, Yahoo, Google, Linkedin, messenger", // for Gigya beta
	    onError: onError,  // onError method will be summoned if an error occurs.
	    onSendDone: onSendDone, // onError method will be summoned after Gigya finishes the publishing process.
	    useHTML: true,  // Use the HTML implementation of the Plugin (rather then Flash implementation)
		showEmailButton: true,
		initialView: view, 
		emailBody: "Greetings from tcm.com<br />Check out this: $URL$<br />$userMsg$<br />"  
	}; 


	// Show the "Share" dialog
	gigya.services.socialize.showShareUI(conf, params);

}

// onError event handler
function onError(event) {
    alert('An error has occured' + ': ' + event.status + '; ' + event.statusMessage);
}


// 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 = "white";
    document.getElementById('status').innerHTML =
                    'The newsfeed has been posted to: '
            + event.providers;
}

