	    // Configuration Object for Gigya
        var conf = 
        {
            APIKey: '2_ITS-VEPzIhRJ1xVlcmpFGwFc4LrRTjE9UyXvJW3BTsOjxoZisB5TthhGsM4826yu',
            enabledProviders: "facebook,twitter" // We want to include only providers that support "newsfeed" feature 
        };
		
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

	var ieTester = getInternetExplorerVersion();
if ((ieTester<0)||(ieTester>6)){
       $(document).ready(function() {
	  
            // get user info
			//alert((getInternetExplorerVersion()<0)||(getInternetExplorerVersion()>6));
			$(".socialNetworking").show();
			//$("#btnTwitter").show();
            gigya.services.socialize.getUserInfo(conf,{callback:renderUI});	
					
						
        });
}
		//else document.getElement(".socialNetworking").hide();

function renderUI(res)
{
	document.getElementById('btnFacebook').onclick=function(){
		try {
        var ots = "ProductDetail:Facebook:Submit:" + productID;
        s_omni.tl(true, "o", ots);                    
	} catch(e) { }
	gigya.services.socialize.connect(conf,{callback:loginAndShareFB, provider:'facebook'});
	};
	document.getElementById('btnTwitter').onclick=function(){
		try {
        var ots = "ProductDetail:Twitter:Submit:" + productID;
        s_omni.tl(true, "o", ots);                    
	} catch(e) { }
	gigya.services.socialize.connect(conf,{callback:loginAndShareTW, provider:'twitter'});
	};
}
		
// Create and Publish User's Action
function publishFacebook(productName, productDescription, productImage, productURL) {
		
		    var image1 = {
				src: productImage,
				href: productURL,
				type: 'image'
			}

		    // Constructing a UserAction Object; Constructor receives an Action Template string
		    var act = new gigya.services.socialize.UserAction('');		        
		    // Setting the User Message
		    act.setUserMessage("likes this item from DisneyStore.com!");
		    // Setting the Title
		    act.setTitle(productName, productURL);
		    // Setting Link Back
		    // Setting Description
		    act.setDescription(productDescription + " " + productURL);
            // Adding Action Links
		    act.addActionLink("Buy it here!", productURL);
			act.addMediaItem(image1);
		    // Parameters for the publishUserAction	method, including the UserAction object
			var params = 
			{
			    userAction:act,
			    callback:publishActionFB_callback
			};		
            // Publish the User Action
			gigya.services.socialize.publishUserAction(conf, params);
}
		
// Create and Publish User's Action
function publishTwitter(productName, productDescription, productImage, productURL) {
		    // Constructing a UserAction Object; Constructor receives an Action Template string
		    var actTW = new gigya.services.socialize.UserAction('');  
		    // Setting the User Message
			if (productName.length>80){
			productName=productName.substring(0,77);
			productName +="...";
			}
		    actTW.setUserMessage("From DisneyStore.com:" + " " + productName + " " + productURL );
		    // Parameters for the publishUserAction	method, including the UserAction object
			var paramsTW = 
			{
			    userAction:actTW,
			    callback:publishActionTW_callback
			};			
            // Publish the User Action
			gigya.services.socialize.publishUserAction(conf, paramsTW);
}

 // Display a status message according to the response from publishUserAction.	
function publishActionFB_callback(response)
		{
			switch (response.status)
			{
				case 'OK':
					//document.getElementById('errMsgArea').style.color = "green";
						try {
							var ots = "ProductDetail:Facebook:Success:" + productID;
							s_omni.tl(true, "o", ots);                    
						} catch(e) { }
					document.getElementById('errMsgArea').innerHTML = "<div id='errorMsgBox' style='color:green; border: 2px dashed green;'>Shared on Facebook!</div>";
					document.getElementById('btnFacebook').src = "//aimg.disneystore.com/content/ds/themes/default11/images/detail/icons/facebookDim.png"
					gigya.services.socialize.disconnect(conf);
					document.getElementById('btnFacebook').onclick=function(){document.getElementById('errMsgArea').innerHTML = "<div id='errorMsgBox'>You have already shared this item on Facebook.</div>";};
					break;
				default:
					//document.getElementById('errMsgArea').style.color = "red";
					document.getElementById('errMsgArea').innerHTML = "<div id='errorMsgBox'>Unable to send Facebook item. Status=" 
					        + response.status + "; " + response.statusMessage + "</div>";
			}
}

function publishActionTW_callback(response)
		{
			switch (response.status)
			{
				case 'OK':
					//document.getElementById('errMsgArea').style.color = "green";
							try {
							var ots = "ProductDetail:Twitter:Success:" + productID;
							s_omni.tl(true, "o", ots);                    
						} catch(e) { }
					document.getElementById('errMsgArea').innerHTML = "<div id='errorMsgBox' style='color:green; border: 2px dashed green;'>Shared on Twitter!</div>";
					document.getElementById('btnTwitter').src = "//aimg.disneystore.com/content/ds/themes/default11/images/detail/icons/twitterDim.png"
					gigya.services.socialize.disconnect(conf);
					document.getElementById('btnTwitter').onclick=function(){document.getElementById('errMsgArea').innerHTML = "<div id='errorMsgBox'>You have already shared this item on Twitter.</div>";};
					break;
				default:
					//document.getElementById('errMsgArea').style.color = "red";
					document.getElementById('errMsgArea').innerHTML = "<div id='errorMsgBox'>Unable to send Twitter item. Status=" 
					        + response.status + "; " + response.statusMessage + "</div>";
			}
}
		
function loginAndShareTW(response) {  



    if ( response['status'] == 'OK' ) {   
        publishTwitter(productName, productDescription, productImage, productURL, productID);
		  
		  }
    else {
        //document.getElementById('errMsgArea').style.color = "red";
		document.getElementById('errMsgArea').innerHTML = "<div id='errorMsgBox'>Please log in to Twitter to share this item.</div>";
    }  
}

function loginAndShareFB(response) {

    if ( response['status'] == 'OK' ) {   
        publishFacebook(productName, productDescription, productImage, productURL, productID);
		  
		  }
    else {
        //document.getElementById('errMsgArea').style.color = "red";
		document.getElementById('errMsgArea').innerHTML = "<div id='errorMsgBox'>Please log in to Facebook to share this item.</div>";
    }  
}
