//Facebook Proxy  - requires prototype
var prototypeIncluded = (typeof Prototype != 'undefined');
if (prototypeIncluded) {
	var FBLikeButtonProxy = Class.create({
		initialize: function(proxyId, settings) {
			this.proxyOn = true;
			this.settings = settings;
			this.containerEle = $('fb_widget_fb_like_btn_proxy'+proxyId);
			this.infoEle = $('fb_widget_fb_like_btn_proxy_info'+proxyId);
			this.dummyEle = this.containerEle.down('div.dummy');
			this.widgetEle = this.containerEle.down('div.widgetOn');
			this.toggleImg = this.containerEle.down('div.toggleImg img');
			var self = this;
			this.containerEle.select('div.toggle').each(function (item) {
				// show info text on mouse over the toggle
				Event.observe(item, 'mouseover', self.showInfo.bindAsEventListener(self));
				Event.observe(item, 'mouseout', self.hideInfo.bindAsEventListener(self));
				// toggle proxy <-> plugin
				Event.observe(item, 'click', self.toggleClicked.bindAsEventListener(self));
			});
		},
		showInfo: function(evt) {
			this.infoEle.show();
		},
		hideInfo: function(evt) {
			this.infoEle.hide();
		},
		toggleClicked: function(evt) {
			if (this.proxyOn) {
				//switch proxy off
				this.toggleImg.src = this.settings.proxy_off_img;
				this.dummyEle.hide();
				var html = "<iframe scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden;\" allowTransparency=\"true\" ";
				html += "src=\"http://www.facebook.com/plugins/like.php?action=like&href="+this.settings.plugin_url;
				if (this.settings.plugin_width) {
					html += "&width="+this.settings.plugin_width;
				}
				if (this.settings.plugin_locale) {
					html += "&locale="+this.settings.plugin_locale;
				}
				if (this.settings.plugin_show_faces) {
					html += "&show_faces="+this.settings.plugin_show_faces;
				}
				if (this.settings.plugin_layout) {
					html += "&layout="+this.settings.plugin_layout;
				}
				html += "\">";
				html += "</iframe>";
				this.widgetEle.update(html);
				this.containerEle.removeClassName('proxy_on');
				this.containerEle.addClassName('proxy_off');
			} else {
				//switch proxy on
				this.toggleImg.src = this.settings.proxy_on_img;
				this.dummyEle.show();
				this.widgetEle.update('');
				this.containerEle.removeClassName('proxy_off');
				this.containerEle.addClassName('proxy_on');
			}
			this.proxyOn = !this.proxyOn;
		}
	});
}

