/* ===== 
 * @fileoverview Share and vote widgets for common Social Networks
 * @author <a href="mailto:info@pagit.eu">Paolo Geninatti</a>
 * @version 1.1.0
 * =====
 */

stdShare = function(type) {
	if (type == 'facebook') {
		share_url = 'http://www.facebook.com/sharer.php?u=' + SWSettings.url + '&title=' + SWSettings.title;
		window.open(share_url);
	} else if (type == 'twitter') {
		share_url = 'http://twitter.com/home?status=' + SWSettings.url + '&title=' + SWSettings.title;
		window.open(share_url);
	} else if (type == 'linkedin') {
		share_url = 'http://www.linkedin.com/shareArticle?mini=true&url=' + SWSettings.url + '&title=' + SWSettings.title;
		window.open(share_url);
	} else if (type == 'myspace') {
		share_url = 'http://www.myspace.com/Modules/PostTo/Pages/?l=3&u=' + SWSettings.url + '&title=' + SWSettings.title;
		window.open(share_url);
	} else if (type == 'delicious') {
		share_url = 'http://del.icio.us/post?url=' + SWSettings.url + '&title=' + SWSettings.title;
		window.open(share_url);
	} else if (type == 'google') {
		share_url = 'http://www.google.com/bookmarks/mark?op=edit&bkmk=' + SWSettings.url + '&title=' + SWSettings.title;
		window.open(share_url);
	} 
}

fbShare = function(id, style) {
    container = document.getElementById(id);
	try {
	 	container.innerHTML = "<a name='fb_share' type=" + style + " share_url=" + SWSettings.url + " href='http://www.facebook.com/sharer.php'>Share</a>";
	} catch(e) {
//		var s = document.createElement('script');
//		s.setAttribute('type','text/javascript');
//		s.setAttribute('src','http://static.ak.fbcdn.net/connect.php/js/FB.Share');
//		container.appendChild(s);	
		var a = document.createElement('a');
		a.setAttribute('name','fb_share');
		a.setAttribute('type', style );
		a.setAttribute('share_url', SWSettings.url);
		a.setAttribute('href', 'http://www.facebook.com/sharer.php');
		a.appendChild(document.createTextNode('Share'));
		container.appendChild(a);
	}
}

fbLike = function(id, style, width, text, color, height) {
    container = document.getElementById(id);
	try {
	 	container.innerHTML = "<iframe src='http://www.facebook.com/plugins/like.php?href=" + SWSettings.url + "&layout=" + style + "&show_faces=true&width=" + width + "&action=" + text + "&colorscheme=" + color + "&height=" + height + "' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:" + width + "px; height:" + height + "px'></iframe>";
	} catch(e) {
		var i = document.createElement('iframe');
		var src = "http://www.facebook.com/plugins/like.php?href=" + SWSettings.url + "&layout=" + style + "&show_faces=true&width=" + width + "&action=" + text + "&colorscheme=" + color + "&height=" + height + "";
		i.setAttribute('src', src);
		i.setAttribute('scrolling','no');
		i.setAttribute('frameborder', '0');
		var sstyle = 'border:none; overflow:hidden; width:' + width + 'px; height:' + height + 'px';
		i.setAttribute('style', sstyle);
		i.setAttribute('allowTransparency','"true"');
		container.appendChild(i);
	}
}

twTweet = function(id, style, source) {
    container = document.getElementById(id);
	try {
		if (source != '')
			data_via = "data-via="+source;
		else
			data_via = "";
	 	container.innerHTML = "<a href='http://twitter.com/share' class='twitter-share-button' data-text=" + SWSettings.title + " data-url=" + SWSettings.url + " data-count=" + style + data_via + ">Tweet</a>";
	} catch(e) {	
//		var s = document.createElement('script');
//		s.setAttribute('type','text/javascript');
//		s.setAttribute('src','http://platform.twitter.com/widgets.js');
//		container.appendChild(s);	
		var a = document.createElement('a');
		a.setAttribute('href', 'http://twitter.com/share');
		a.setAttribute('class','twitter-share-button');
		a.setAttribute('data-text', SWSettings.title);
		a.setAttribute('data-url', SWSettings.url); 
		a.setAttribute('data-count', style);
		if (source != '')
			a.setAttribute('data-via', source);
		a.appendChild(document.createTextNode('Tweet'));
		container.appendChild(a);
	}
}
