// JavaScript Document
var idRecordToShare = -1;
var idSectionToShare = -1;
var idRecordToShare = -1;
var idSectionToShare = -1;  // 1: Home, 2: Sport couture, 3: Bikkembergs, 4: Football Is Me, 5: DB World, 6: Press Area
var zoomType = 1; // 1: collection, 2: gallery
var isHtml = 1;
var collectionType = 1; // 1: bikkembergs, 2: sport_couture 3:football_is_me

var lastPath = window.location.pathname;
if (window.location.pathname.charAt(window.location.pathname.length - 1) != '/')
	lastPath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/") + 1);
	
var url_site = "http://" + window.location.host + lastPath;
var hashString = "";
var ipadPage="";


function setIDRecord(idrecord, idsectiontoshare, zoomtype, colorType, ishtml, collectiontype)
{
	//alert(idrecord+" | "+ idsectiontoshare+" | "+ zoomtype+" | "+ colorType+" | "+ ishtml+" | "+ collectiontype+" | "+ page)
 	idRecordToShare = idrecord;
	idSectionToShare = idsectiontoshare;
	zoomType = zoomtype;
	isHtml = ishtml;
	collectionType = collectiontype; 
	
	if (idRecordToShare == -1 && idSectionToShare == 8 /* Newsletter */)
	{
		$("#share_btn_cnt").animate({bottom: "0px"}, 500, function(){});
		$("#share_btn").animate({top: $("#share_btn").height() + "px"}, 500, function(){});
		$("#share").animate({height: "0px"}, 500);
	}else
	{
		$("#share_btn_cnt").animate({bottom: "0px"},  500, function(){});
		$("#share_btn").animate({top: "0px"}, 500);
		$("#share").animate({height: "0px"}, 500);
	}
}

function condividiNewsSuFB()
{
	hashString = window.location.hash;
	hashString = hashString.substring(1, hashString.length);
	var data = new Date();
	var date = data.getHours() + ":" + data.getMinutes() + ":" + data.getSeconds() + ":" + data.getMilliseconds() + ":";
	//window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url_site+"scripts/share_to_facebook.php?idsec="+idSectionToShare+"idrec="+idRecordToShare+"&date="+date)+'&d='+date,'sharer','toolbar=0,status=0,width=626,height=436');
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url_site+"scripts/share_to_facebook.php?idsec="+idSectionToShare+"&idrec="+idRecordToShare+"&zt="+zoomType+"&ish="+isHtml+"&hash="+hashString+"&ct="+collectionType+"&pg="+ipadPage+"&date="+date)+'&d='+date,'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function condividiNewsSuTwitter()
{            
	hashString = window.location.hash;
	hashString = hashString.substring(1, hashString.length);
	//chiamata ajax per prelevare testo e url del record corrente	
	$.ajax({
		url: url_site+'scripts/get_record_info.php',
		type: "GET",
		cache: false,
		data: "idsec="+idSectionToShare+"&idrec="+idRecordToShare+"&zt="+zoomType+"&ish="+isHtml+"&ct="+collectionType+"&hash="+hashString+"&pg="+ipadPage,
		success: function(xml)
		{
			if(parseInt($(xml).find("error").text()) == 1)
			{
				alert("Errore di connessione al database");
			}else
			{
				var u = encodeURIComponent($(xml).find("url").text());
				var t = encodeURIComponent($(xml).find("testo").text());
				var urlTweet='http://twitter.com/share?url='+u+'&text='+t;				
				window.open(urlTweet,'mywindow','width=640,height=200');
				return false;
			}
		}, error: function(xml)
		{
			alert(xml);	
		}
	});
}

function condividiNewsSuGoogleBuzz()
{            
	hashString = window.location.hash;
	hashString = hashString.substring(1, hashString.length);
	//chiamata ajax per prelevare testo e url del record corrente	
	$.ajax({
		url: url_site+'scripts/get_record_info.php',
		type: "GET",
		cache: false,
		data: "idsec="+idSectionToShare+"&idrec="+idRecordToShare+"&zt="+zoomType+"&ish="+isHtml+"&ct="+collectionType+"&hash="+hashString+"&pg="+ipadPage,
		success: function(xml)
		{
			if(parseInt($(xml).find("error").text()) == 1)
			{
				alert("Errore di connessione al database");
			}else
			{
				var u = encodeURIComponent($(xml).find("url").text());
				var t = encodeURIComponent($(xml).find("testo").text());
				var urlGoogleBuzz='http://www.google.com/buzz/post?url='+u+'&message='+t;		 		   	
				window.open(urlGoogleBuzz,'mywindow','resizable=0,scrollbars=0,width=690,height=415');
				return false;
			}
		}, error: function(xml)
		{
			alert(xml);	
		}
	});
}                            
               

function condividiNewsSuTumblr()
{            
	hashString = window.location.hash;
	hashString = hashString.substring(1, hashString.length);
	//chiamata ajax per prelevare testo e url del record corrente	
	$.ajax({
		url: url_site+'scripts/get_record_info.php',
		type: "GET",
		cache: false,
		data: "idsec="+idSectionToShare+"&idrec="+idRecordToShare+"&zt="+zoomType+"&ish="+isHtml+"&ct="+collectionType+"&hash="+hashString+"&pg="+ipadPage,
		success: function(xml)
		{
			if(parseInt($(xml).find("error").text()) == 1)
			{
				alert("Errore di connessione al database");
			}else
			{
				var u = encodeURIComponent($(xml).find("url").text());
				var t = encodeURIComponent($(xml).find("testo").text());
				var urlTumblr='http://www.tumblr.com/share?v=3&u='+u+'&t='+t;		 		   	
				window.open(urlTumblr,'mywindow','resizable=0,scrollbars=0,width=900,height=400');
				return false;
			}
		}, error: function(xml)
		{
			alert(xml);	
		}
	});
}
                     
function condividiNewsSuBlogger()
{            
	hashString = window.location.hash;
	hashString = hashString.substring(1, hashString.length);
	//chiamata ajax per prelevare testo e url del record corrente	
	$.ajax({
		url: url_site+'scripts/get_record_info.php',
		type: "GET",
		cache: false,
		data: "idsec="+idSectionToShare+"&idrec="+idRecordToShare+"&zt="+zoomType+"&ish="+isHtml+"&ct="+collectionType+"&hash="+hashString+"&pg="+ipadPage,
		success: function(xml)
		{
			if(parseInt($(xml).find("error").text()) == 1)
			{
				alert("Errore di connessione al database");
			}else
			{
				var u = encodeURIComponent($(xml).find("url").text());
				var t = encodeURIComponent($(xml).find("testo").text());
				var urlTumblr='http://wd.sharethis.com/api/sharer.php?destination=blogger&url='+u+'&title='+t;		 		   	
				window.open(urlTumblr,'mywindow','resizable=0,scrollbars=0,width=900,height=690');
				return false;
			}
		}, error: function(xml)
		{
			alert(xml);	
		}
	});
}

/*
<a class="blogger ckimg" href="http://wd.sharethis.com/api/sharer.php?destination=blogger&amp;url=http%3A%2F%2Fsharethis.com%2Fpublishers%2Fget-button-code%3Fstyle%3D4&amp;title=Sharing%20Widget%2C%20Sharing%20Button%2C%20Sharing%20Plugin%20-%20ShareThis%20Button%20Code&amp;publisher=d63868ac-f89b-46dd-9e81-3388e18dd437&amp;fpc=8f891fa-12c7d06d741-4206f98b-34&amp;sessionID=1297787553303.83645&amp;source=chicklet" title="Blogger" id="post_blogger_link" target="_blank" stservice="blogger" onclick="serviceClicked(this);">Blogger</a>
  */
