var facebookStatus = getCookie('facebook-status');
var facebookStatusStoreLength = 7 * 24 * 60 * 60 * 1000;

switch (facebookStatus) {
	case 'on':
		Event.observe(window, 'load', showFacebookButton);
		break;
	case 'off':
		break;
	default:
		Event.observe(window, 'load', showFacebookChoiceButton);
}

function showFacebookButton() {
	var header = $('header');
	if (!header) return;
	
	var facebookWidth = 400;
	var facebookHeight = 80;
	
	var button = document.createElement('iframe');
	button.setAttribute('src', 'http://www.facebook.com/plugins/like.php?href=' +
		encodeURIComponent(document.URL) + '&layout=standard&show_faces=true&' +
		'width=' + facebookWidth + '&action=like&font=verdana&' +
		'colorscheme=light&height=' + facebookHeight);
	button.id = 'facebook-box';
	header.appendChild(button);
}

function showFacebookChoiceButton() {
	var header = $('header');
	if (!header) return;
	
	var button = document.createElement('div');
	button.id = 'facebook-choice';
	header.appendChild(button);
	
	var span = document.createElement('span');
	span.appendChild(document.createTextNode('Facebook-Button einblenden?'))
	button.appendChild(span);
	
	var showButton = document.createElement('button');
	showButton.id = 'facebook-choice-show';
	showButton.onclick = function() {
		setCookie('facebook-status', 'on', facebookStatusStoreLength);
		hideFacebookChoiceButton();
		showFacebookButton();
	}
	showButton.appendChild(document.createTextNode('Ja'));
	showButton.setAttribute('title', 'Blendet den Gefällt-mir-Button von Facebook ein. Dabei werden Daten an Facebook übermittelt.');
	button.appendChild(showButton);
	
	var hideButton = document.createElement('button');
	hideButton.id = 'facebook-choice-hide';
	hideButton.onclick = function() {
		setCookie('facebook-status', 'off', facebookStatusStoreLength);
		hideFacebookChoiceButton();
	}
	hideButton.appendChild(document.createTextNode('Nein'));
	hideButton.setAttribute('title', 'Blendet diese Mitteilung für eine Woche aus.');
	button.appendChild(hideButton);
}

function hideFacebookChoiceButton() {
	var button = $('facebook-choice');
	if (button)
		button.parentNode.removeChild(button);
}

