$(document).ready(function(){
	
	/**
	 * Facebook
	 */
	$("#facebook a, li.facebook a").click(function() {
		var url = encodeURIComponent(String(window.location));
		var title = encodeURIComponent(String(document.title));
		
		$(this).attr('target', '_blank');
		$(this).attr('href', 'http://www.facebook.com/sharer.php?u=' + url + '&t=' + title);  
	});
	$("li.facebook_href a").click(function() {
		if (this.href.lastIndexOf('facebook.com') == -1) {
			var url = encodeURIComponent(this.href);
			var title = encodeURIComponent(this.title);
			
			$(this).attr('target', '_blank');
			$(this).attr('href', 'http://www.facebook.com/sharer.php?u=' + url + '&t=' + title);
		}
	});
	
	
	/**
	 * Twitter
	 */
	$("#twitter a, li.twitter a, .twitterLink a").click(function() {
		var url = String(window.location);
		var status = encodeURIComponent($(this).attr('rel') + " " + url);
		
		$(this).attr('target', '_blank');
		$(this).attr('href', 'http://twitter.com/?status=' + status);  
	});
	$("li.twitter_href a").click(function() {
		if (this.href.lastIndexOf('twitter.com') == -1) {
			var url = this.href;
			var status = encodeURIComponent($(this).attr('rel') + " " + url);
			
			$(this).attr('target', '_blank');
			$(this).attr('href', 'http://twitter.com/?status=' + status);
		}
	});
	
	
	/**
	 * Enviar a un amigo
	 */
	/*
	$("#mail a, li.mail a").click(function() {
		var url = encodeURIComponent(String(window.location));
		
		$(this).attr('href', 'mailto:?subject=Hola, esto te puede interesar&body=' + url);  
	});
	$("li.mail_href a").click(function() {
		var url = encodeURIComponent(this.href);
		
		$(this).attr('href', 'mailto:?subject=Hola, esto te puede interesar&body=' + url);  
	});
	*/
	
	/**
	 * Añadir a favoritos
	 */
	$("#fav a, li.fav a").click(function(event) {
		event.preventDefault(); // prevent the anchor tag from sending the user off to the link
		
		var url = String(window.location);
		var title = String(document.title);
		
		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title);
		} else if(window.opera) { // Opera 7+
			return false; // do nothing - the rel="sidebar" should do the trick
		} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
			alert('Unfortunately, this browser does not support the requested action,'
					+ ' please bookmark this page manually.');
		}  
	});
	$("li.fav_href a").click(function(event) {
		event.preventDefault(); // prevent the anchor tag from sending the user off to the link
		
		var url = this.href;
		var title = this.title;
		
		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title);
		} else if(window.opera) { // Opera 7+
			return false; // do nothing - the rel="sidebar" should do the trick
		} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
			alert('Unfortunately, this browser does not support the requested action,'
					+ ' please bookmark this page manually.');
		}  
	});
});
