var shw=0;
var inf=0;
var defaultUpState = "/img/share-icon-16x16.png";
var defaultOverState = "/img/share-icon-16x16.png";
var defaultPadding = "20px";
var defaultColor = "CCCCCC";
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='+document.location",
						  "'http://www.facebook.com/share.php?u='+document.location",
						  "'http://www.myspace.com/Modules/PostTo/Pages/?l=3&u='+document.location+'&t='+document.title",
						  "'http://twitter.com/home/?status='+document.location",
						  "'http://del.icio.us/post?title='+escape(document.title)+'&url='+document.location",
						  "'http://meneame.net/submit.php?url='+document.location",
						  "'http://ocio.fresqui.com/post?url='+document.location",
						  "'http://myweb2.search.yahoo.com/myresults/bookmarklet?u='+document.location+'&t='+escape(document.title)",
						  "'http://www.technorati.com/search/'+document.location+'?sub=postcosm'",
						  "'http://www.digg.com/submit?url='+document.location");
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(){
	if(shw==0){
		posicio=findPos(document.getElementById("sharelink"));
		document.getElementById("sharemodule").style.left=posicio[0]+"px";
		document.getElementById("sharemodule").style.top=posicio[1]+15+"px";
		document.getElementById("sharemodule").className="";
		shw=1;
	}
	else{
		if(inf==1){
			document.getElementById("sharelist").className="";
			document.getElementById("sharetext").className="sharemodulehide";
			document.getElementById("sharewhat").innerHTML="Què és això?";
			inf=0;
		}
		document.getElementById("sharemodule").className="sharemodulehide";
		shw=0;
	}
}

function shareinfo(){
	if(inf==0){
		document.getElementById("sharelist").className="sharemodulehide";
		document.getElementById("sharetext").className="";
		document.getElementById("sharewhat").innerHTML="< Tornar";
		inf=1;
	}else{
		document.getElementById("sharelist").className="";
		document.getElementById("sharetext").className="sharemodulehide";
		document.getElementById("sharewhat").innerHTML="Què és això?";
		inf=0;
	}
}

function pintashare(color,upState,overState){
	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;} #sharemodule a,#sharemodule a:link,#sharemodule a:visited{text-decoration: none; color: #000;} #sharemodule a:hover{color: #CC0000; text-decoration: underline;} .sharebutton{padding-left: "+defaultPadding+"; height: 20px; display: block; 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;}</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();\" 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=\"/img/"+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()\" class=\"sharemodulehide\" id=\"sharelink\"> Comparteix</a>");
	
	window.onload = function(){
		var shareDiv = document.createElement("div");
		shareDiv.id = "shareDiv";
		document.body.appendChild(shareDiv);
		document.getElementById("shareDiv").innerHTML=html;
		document.getElementById("sharelink").className="sharebutton";
	}
	window.onresize = function (){
		if(shw==1){
			posicio=findPos(document.getElementById("sharelink"));
			document.getElementById("sharemodule").style.left=posicio[0]+"px";
			document.getElementById("sharemodule").style.top=posicio[1]+15+"px";
		}
	}
}
