var Popup = Class.create({
	initialize: function(anchor, name, url, params) {
		this.name = name.capitalize();
		this.url = url;
		this.params = params.join(',');
		anchor.observe('click', this.openPopup.bindAsEventListener(this, this));
	},
	openPopup: function(e, popup) {
		e.stop();
		window.open(popup.url, popup.name, popup.params);
	}
});
var SharePopup = Class.create(Popup, {
	initialize: function($super, anchor, name, url, params) {
		this.url_template = new Template(url);
		this.url = this.url_template.evaluate({
			url: location.href,
			encoded_url: encodeURIComponent(location.href),
			encoded_title: encodeURIComponent(document.title)
		});
		this.params = 'toolbar=no' + params.join(',');
		$super(anchor, name, this.url, params);
	}
});

var SharePopups = {
	facebook: {
		url_template_string: 'http://www.facebook.com/sharer.php?u=#{encoded_url}&t=#{encoded_title}',
		parameters: ['width=626', 'height=436']
	},
	delicious: {
		url_template_string: 'http://delicious.com/save?v=5&noui&jump=close&url=#{encoded_url}&title=#{encoded_title}',
		parameters: ['width=550', 'height=550']
	},
	misterwong: {
		url_template_string: 'http://www.mister-wong.de/index.php?action=addurl&bm_url=#{encoded_url}&bm_description=#{encoded_title}',
		parameters: ['width=800', 'height=750', 'scrollbars=yes']
	},
	linkarena: {
		url_template_string: 'http://linkarena.com/bookmarks/addlink/?url=#{url}',
		parameters: ['width=800', 'height=750', 'scrollbars=yes']
	},
	alltagz: {
		url_template_string: 'http://www.alltagz.de/bookmarks/?action=add&popup=1&address=#{encoded_url}&title=#{encoded_title}&description=#{encoded_title}',
		parameters: ['width=730', 'height=465', 'scrollbars=yes']
	},
	folkd: {
		url_template_string: 'http://www.folkd.com/submit/page/#{url}',
		parameters: ['width=800', 'height=600', 'scrollbars=yes']
	},
	twitter: {
		url_template_string: 'http://twitter.com/home?status=#{encoded_url}',
		parameters: ['width=800', 'height=600', 'scrollbars=yes']
	},
	vznetzwerke: {
		url_template_string: 'http://www.studivz.net/Suggest/Selection/?u=#{encoded_url}&desc=#{encoded_title}&prov=phonostar.de',
		parameters: ['width=800', 'height=600', 'scrollbars=yes']
	}
}

document.observe('dom:loaded', function() {
	$$('.share_link').findAll(function(elem) {
		return SharePopups[$w(elem.className)[1]]; //nur popups, die es auch gibt
	}).each(function(elem) {
		var popup_name = $w(elem.className)[1]; //(key)popup, welches geoeffnet werden soll
		new SharePopup(elem, popup_name, SharePopups[popup_name]['url_template_string'], SharePopups[popup_name]['parameters']);
	});
});