var facebookLikeButtonClass = Class.create({
	initialize:function(appId, locale, callback)
	{
		window.fbAsyncInit = function() {
			if (typeof FB == 'undefined') {
				return;
			}
		    FB.init({appId: appId, status: true, cookie: true, xfbml: true});
		    FB.Event.subscribe('edge.create', function(href, widget) {
		    	if (callback != null) {
		    		callback(href, widget);
		    	}
		    });
		};
		
		if ($('fb-root') == null) {
			var fbEl = new Element('div', {id: 'fb-root'});
			$(document.body).appendChild(fbEl);
			var sc = new Element('script', { type:'text/javascript', src:document.location.protocol + '//connect.facebook.net/'+locale+'/all.js', async:true });
			fbEl.appendChild(sc);
			window.fbInitDone = true;
		}
	}
});
// Usage:
/*
Event.observe(window, 'load', function() {
	new facebookLikeButtonClass('YOUR_APP_ID', 'de_DE', function(href, widgetObject) {
		// Put your code here
		alert('You just liked '+href);
	});
});
*/

Event.observe(window, 'load', function() {
        new facebookLikeButtonClass('215056028509801', 'en_US', function(href, widgetObject) {
                // Do something, e.g. track the click on the "Like" button here
                cmCreatePageElementTag('Facebook Like Button', widgetObject.getAttribute('PROD_ID') + ' - ' + widgetObject.getAttribute('CATEGORY_ID'), null);
        });
});

