/* Create NetR namespace */
if(typeof NetR == "undefined"){ var NetR = {}; }

NetR.initShareAndPrint = function (el) {

	var strings = ({
		sv: {
			print: 'Skriv ut sidan',
			addFavourite: 'Spara som favorit',
			tellAFriend: 'Tipsa en vän via e-post'
		},
		en: {
			print: 'Print page',
			addFavourite: 'Save as favourite',
			tellAFriend: 'Tell a friend by email'
		}
	})[$('html').attr('lang')];

	var ul = $('<ul class="share-and-print">').insertAfter(el);

	// Add print link
	el.before($('<a>', {
		className: 'print',
		href: '#',
		click: function (e) {
			e.preventDefault();
			window.print();
		}
	}).append('<span>' + strings.print + '</span>'));

	// Append add favourite link
	this.favouritesLink = $('<li><a href="' + document.URL + '" class="add-favourite"><img src="/i/add-favourite.png" alt="" /><span>' + strings.addFavourite + '</span></a></li>').appendTo(ul);
	try {
		if (window.sidebar && window.sidebar.addPanel) {
			// Firefox
			this.favouritesLink.click(function (e) {
				e.preventDefault();
				window.sidebar.addPanel(document.title, document.URL, "");
			});
		} else if (document.all) {
			// Internet Explorer
			this.favouritesLink.click(function (e) {
				try {
					e.preventDefault();
					window.external.AddFavorite(document.URL, document.title);
				} catch (e) {}
			});
		} else if ($.browser.opera) {
			// Opera
			this.favouritesLink.find('a').attr({
				'rel': 'sidebar',
				'title': document.title
			});
		} else {
			// Other browsers get nothing :(
			this.favouritesLink.remove();
		}
	} catch (e) {
		// To prevent non working link, remove it if something breaks
		this.favouritesLink.remove();
	}
	
	// Add "tell a friend"
	var tell = $('#tell-a-friend');
	if (tell.length) {
		if (window.location.hash != ('#' + tell.attr('id')).replace('##', '#')) {
			tell.addClass('hidden');
		}
		ul.append($('<li>').append($('<a>', {
			href: "#",
			className: "tell-a-friend",
			html: '<img src="/i/email_16.png" alt="" /><span>' + strings.tellAFriend + '</span>',
			click: function(e) {
				e.preventDefault();
				tell.toggle();
				window.location.hash = '#tell-a-friend';
			}
		})));
	}
};
