var shw=false;
var inf=true;
var run=0;
var lastid=0;
var defaultUpState = "/grafics/share/share.png";
var defaultOverState = "/grafics/share/share.png";
var defaultPadding = "20px!important";
var defaultColor = "CCCCCC";
var urlList=new Array;
var titleList=new Array;
var shareName = new Array ("La Tafanera",
						   "Facebook",
						   "Myspace",
						   "Twitter",
						   "Delicious",
						   "Men&eacute;ame",
						   "Fresqui",
						   "MyYahoo",
						   "Technorati",
						   "Digg");
var shareURL = new Array ("'http://www.latafanera.net/submit.php?url='+urlLink",
						  "'http://www.facebook.com/share.php?u='+urlLink",
						  "'http://www.myspace.com/Modules/PostTo/Pages/?l=3&u='+urlLink+'&t='+titleLink",
						  "'http://twitter.com/home/?status='+titleLink+escape(' ')+urlLink",
						  "'http://del.icio.us/post?title='+titleLink+'&url='+urlLink",
						  "'http://meneame.net/submit.php?url='+urlLink",
						  "'http://ocio.fresqui.com/post?url='+urlLink",
						  "'http://myweb2.search.yahoo.com/myresults/bookmarklet?u='+urlLink+'&t='+titleLink",
						  "'http://www.technorati.com/search/'+urlLink+'?sub=postcosm'",
						  "'http://www.digg.com/submit?url='+urlLink");
var shareImg = new Array ("latafanera.gif",
						  "facebook.gif",
						  "myspace.gif",
						  "twitter.gif",
						  "delicious.gif",
						  "meneame.gif",
						  "fresqui.gif",
						  "myyahoo.gif",
						  "technorati.gif",
						  "digg.gif");

function findPos(obj){
	var curleft = curtop = 0;
	if(obj.offsetParent){
		do{
			curleft +=obj.offsetLeft;
			curtop +=obj.offsetTop;
			} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}
						  
function shareshow(id){
	urlLink=urlList[id];
	titleLink=titleList[id];
	if(id!=-1&id!=lastid&shw==true){
		posicio=findPos(document.getElementById("sharelink"+id));
		document.getElementById("sharemodule").style.left=posicio[0]+"px";
		document.getElementById("sharemodule").style.top=posicio[1]+15+"px";
	}else{
		if(shw==false){
			posicio=findPos(document.getElementById("sharelink"+id));
			document.getElementById("sharemodule").style.left=posicio[0]+"px";
			document.getElementById("sharemodule").style.top=posicio[1]+15+"px";
			document.getElementById("sharemodule").className="";
			shw=true;
		}
		else{
			if(inf==true){
				document.getElementById("sharelist").className="";
				document.getElementById("sharetext").className="sharemodulehide";
				document.getElementById("sharewhat").innerHTML="Qu&egrave; &eacute;s aix&ograve;?";
				inf=false;
			}
			document.getElementById("sharemodule").className="sharemodulehide";
			shw=false;
		}
	}
	lastid=id;
}

function shareinfo(){
	if(inf==false){
		document.getElementById("sharelist").className="sharemodulehide";
		document.getElementById("sharetext").className="";
		document.getElementById("sharewhat").innerHTML="< Tornar";
		inf=true;
	}else{
		document.getElementById("sharelist").className="";
		document.getElementById("sharetext").className="sharemodulehide";
		document.getElementById("sharewhat").innerHTML="Qu&egrave; &eacute;s aix&ograve;?";
		inf=false;
	}
}

function guardaArray(urlLink,titleLink){
	if(urlLink!=undefined&titleLink!=undefined){
		urlList[run]=escape(urlLink);
		titleList[run]=escape(titleLink);
	}else{
		urlList[run]=escape(document.location);
		titleList[run]=escape(document.title);
	}
}
function pintashare(color,upState,overState,urlLink,titleLink){
if(run==0){
	if(upState!=undefined){
		defaultUpState=upState;
	}
	if(overState!=undefined){
		defaultOverState=overState;
	}
	if(overState==""||upState==""||overState==false||upState==false){
		defaultPadding = "0px";
	}
	if(color!=undefined){
		defaultColor=color;
	}
	
	document.write("<style>#sharemodule{width: 240px;position: absolute; background: #F3F3F3;border: 8px solid #"+defaultColor+";z-index: 1000!important;font-family: Arial, Helvetica, sans-serif;color: #000; margin-top: 5px;} #sharemodule *{padding: 0; margin: 0; border: none;} .sharemodulehide{visibility: hidden; display: none;} #sharemodule h2{float: left; font-size: 14px; padding: 5px;} #sharemodule .sharemodulequees{float: right; font-size: 11px; padding: 5px;} #sharemodule ul{list-style-type: none; font-size: 12px; overflow: auto;height: 192px;} #sharemodule ul li{border-top: 1px solid #FFF;	border-bottom: 1px solid #e6e6e6; padding: 3px 5px; height: 19px; list-style-type: none; background: none; text-align: left;} #sharemodule a,#sharemodule a:link,#sharemodule a:visited{text-decoration: none; color: #00395B;} #sharemodule a:hover{text-decoration: underline;} .sharebutton{padding-left: "+defaultPadding+"; display: inline; padding-top: 2px; padding-bottom: 2px; width: 70px; background: url(\""+defaultUpState+"\") no-repeat;} .sharebutton:hover{background: url(\""+defaultOverState+"\") no-repeat;} #sharemodule .shareinfo{font-size: 10px; padding: 3px; height: 14px; background: #FFF; font-family: Verdana, Arial, Helvetica, sans-serif;} #sharemodule .shareclose{float: right;} #sharemodule #sharewhat{float: left;} #sharemodule #sharetext{height: 192px;} #sharemodule #sharetext p{font-size: 13px; padding: 5px; line-height: 18px; text-align: left;}</style>");
	
	var html ="<div id=\"sharemodule\" class=\"sharemodulehide\"><div class=\"shareinfo\"><a href=\"javascript:shareinfo();\" id=\"sharewhat\">Qu&egrave; &eacute;s aix&ograve;?</a><a href=\"javascript:shareshow(-1);\" class=\"shareclose\">Tanca [X]</a></div><div id=\"sharetext\" class=\"sharemodulehide\"><p>Aquest &eacute;s un servei que et permet compartir el web on et trobes en aquests moments a un seguit de xarxes socials, com \"La tafanera\", \"Facebook\" o \"Myspace\". &Eacute;s tan f&agrave;cil com clicar el bot&oacute; de la xarxa social on el vols compartir. Evidentment, despr&eacute;s caldr&agrave; que siguis usuari de la xarxa en q&uuml;esti&oacute; (i t'hi connectis) per poder-lo afegir.</p></div><ul id=\"sharelist\">";
	
	for(i=0;i<shareName.length;i++){
		html +="<li><a href=\"#\" onclick=\"javascript:window.open("+shareURL[i]+");return false;\"><img src=\"/grafics/share/"+shareImg[i]+"\" alt=\""+shareName[i]+"\" /></a> <a href=\"#\" onclick=\"javascript:window.open("+shareURL[i]+");return false;\">"+shareName[i]+"</a></li>";
	}
	
	html +="</ul> </div>";

	document.write("<a href=\"javascript:shareshow("+run+")\" class=\"sharemodulehide\" id=\"sharelink"+run+"\">&nbsp;&nbsp;Comparteix</a>");
	
	window.onload = function(){
		var shareDiv = document.createElement("div");
		shareDiv.id = "shareDiv";
		document.body.appendChild(shareDiv);
		document.getElementById("shareDiv").innerHTML=html;
		for(i=0;i<run;i++){
			document.getElementById("sharelink"+i).className="sharebutton";
		}
	}
	window.onresize = function (){
		if(shw==true){
			posicio=findPos(document.getElementById("sharelink"+lastid));
			document.getElementById("sharemodule").style.left=posicio[0]+"px";
			document.getElementById("sharemodule").style.top=posicio[1]+15+"px";
		}
	}
	guardaArray(urlLink,titleLink);
	run=1;
	}else{
		document.write("<a href=\"javascript:shareshow("+run+")\" class=\"sharemodulehide\" id=\"sharelink"+run+"\"><font size=-2>&nbsp;&nbsp;Comparteix</font></a>");
		guardaArray(urlLink,titleLink);
		run++;
	}
}