﻿/**
 * Get user anthem place
 * 
 * @return mixed(string|null);
 */
function getUserAnthemPlace() {
	var msg = null;
	if ($('.play.box3:visible').length != 0) {
		msg = $('.play.box3:visible .bgTitle .title').val();
	}
	if ($('.play.box2:visible').length != 0) {
		msg = $('.play.box2:visible .title').children().text();
	}
	return msg;
}

/**
 * Usable object to Facebook Api
 */
window.fbAsyncInit = function() {
	FB.init( {
		appId : '124170387612321',
		status : true,
		cookie : true,
		xfbml : true
	});
};
(function() {
	var e = document.createElement('script');
	e.async = true;
	e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
	document.getElementById('fb-root').appendChild(e);
}());

/**
 * Share on FaceBook
 * 
 * @return void
 */
function shareFB(uid) {
	
	var msg = getUserAnthemPlace() + '\nZagłosuj na mój hymn: ' + 'http://dzienprzytulania.pl/gallery.aspx?uid=' + uid;
	if (msg == null)
		return;
	
	FB.ui( {
		method : "stream.publish",
		message : msg
	});
}

/**
 * Share on Twitter
 * 
 * @return void
 */
function shareTwitter(uid) {

	var msg = 'Na stronie Dnia Przytulania mamy wpis: ' + getUserAnthemPlace() + '. Zobacz więcej na stronie: ' + 'http://dzienprzytulania.pl/gallery.aspx?uid=' + uid;
	if (msg == null)
		return;

	var url = 'http://twitter.com/home?status=' + msg;
	window.open(url, '', 'width=770,height=406,toolbar=0,status=0');
}

/**
 * Share on Sledzik
 * 
 * @return void
 */
function shareSledzik(uid) {

	var msg = 'Na stronie Dnia Przytulania mamy wpis: ' + getUserAnthemPlace() + '. Zobacz więcej na stronie: ' + 'http://dzienprzytulania.pl/gallery.aspx?uid=' + uid;
	if (msg == null)
		return;
	
	var url = 'http://nasza-klasa.pl/sledzik?shout=' + msg;
	window.open(url, '', 'width=770,height=406,toolbar=0,status=0');
}

/**
 * Share to Blip
 * 
 * @return void
 */
function shareBlip(uid) {

	var msg = 'Na stronie Dnia Przytulania mamy wpis: ' + getUserAnthemPlace() + '. Zobacz więcej na stronie: ' + 'http://dzienprzytulania.pl/gallery.aspx?uid=' + uid;
	if (msg == null)
		return;
	
	var url = 'http://blip.pl/dashboard?body=' + msg;
	window.open(url, '', 'width=770,height=406,toolbar=0,status=0');
}
