var shw=false;
var inf=false;
var run=0;
var lastid=0;
//var defaultUpState = "http://www.tv3.cat/img/share-icon-16x16.png";
//var defaultOverState = "http://www.tv3.cat/img/share-icon-16x16.png";
var defaultUpState = "http://www.llull.tv/media/img/mes.gif";
var defaultOverState = "http://www.llull.tv/media/img/mes.gif";
var defaultPadding = "20px!important";
var defaultColor = "CCCCCC";
var defaultLang = "ca";
var urlList=new Array;
var titleList=new Array;
var lang_ca = new Array ("Compartiu",
						 "", //"Qu&egrave; &eacute;s aix&ograve;?",
						 "Tanca [X]",
						 "< Tornar",
						 "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.");
var lang_es = new Array ("Comparte",
						 "", //"&iquest;Qu&eacute; es esto?",
						 "Cierra [X]",
						 "< Volver",
						 "&Eacute;ste es un servicio que te permite compartir el  web donde te encuentras en estos momentos en una serie de redes sociales, como  &ldquo;La tafanera&rdquo;, &ldquo;Facebook&rdquo; o &ldquo;Myspace&rdquo;. Es tan f&aacute;cil como hacer clic en el bot&oacute;n  de la red social donde lo quieres compartir. Evidentemente, despu&eacute;s ser&aacute;  necesario que seas usuario de la red en cuesti&oacute;n (y que te conectes) para  poderlo a&ntilde;adir.");
var lang_en = new Array ("Share",
						 "", //"What is this?",
						 "Close [X]",
						 "< Back",
						 "This is a service  which enables you to share the website were you are now on a series of social  networks such as &quot;La tafanera&quot;, &quot;Facebook&quot; and  &quot;Myspace&quot;. It is as easy as clicking on the button of the social  network where you wish to share it. Needles to say, you will have to be a user  of the network in question (and connect to it) in order to add it.");

var lang_fr = new Array ("Partager",
						 "", //"What is this?",
						 "Fermer [X]",
						 "< Retour",
						 "This is a service  which enables you to share the website were you are now on a series of social  networks such as &quot;La tafanera&quot;, &quot;Facebook&quot; and  &quot;Myspace&quot;. It is as easy as clicking on the button of the social  network where you wish to share it. Needles to say, you will have to be a user  of the network in question (and connect to it) in order to add it.");

var lang_it = new Array ("Condividere",
						 "", //"What is this?",
						 "Chiudere [X]",
						 "< Ritorno",
						 "This is a service  which enables you to share the website were you are now on a series of social  networks such as &quot;La tafanera&quot;, &quot;Facebook&quot; and  &quot;Myspace&quot;. It is as easy as clicking on the button of the social  network where you wish to share it. Needles to say, you will have to be a user  of the network in question (and connect to it) in order to add it.");

var shareName = new Array ("La Tafanera",
						   "Facebook",
						   "Myspace",
						   "Twitter",
						   "Delicious",
						   "Yahoo Bookmarks",
						   "Google Bookmarks");
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://www.myspace.com/Modules/PostTo/Pages/?l=3&u='+urlLink",
						  //"'http://twitter.com/home/?status='+titleLink+escape(' ')+urlLink",
						  "'http://twitter.com/share?url='+urlLink",
						  "'http://del.icio.us/post?title='+titleLink+'&url='+urlLink",
						  "'http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&u='+urlLink+'&t='+titleLink",
						  "'http://www.google.com/bookmarks/mark?op=edit&bkmk='+urlLink+'&title='+titleLink");
var shareImg = new Array ("latafanera.gif",
						  "facebook.gif",
						  "myspace.gif",
						  "twitter.gif",
						  "delicious.gif",
						  "yahoo.png",
						  "google.png");



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];
	*/
	
	urlLink = document.location;
	titleLink = document.title;
	
	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=eval("lang_"+defaultLang+"[1]");
				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=eval("lang_"+defaultLang+"[3]");
		inf=true;
	}else{
		document.getElementById("sharelist").className="";
		document.getElementById("sharetext").className="sharemodulehide";
		document.getElementById("sharewhat").innerHTML=eval("lang_"+defaultLang+"[1]");
		inf=false;
	}
}

function guardaArray(urlLink,titleLink,lang){
	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,lang){
	
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;
	}
	if(lang!=undefined){
		defaultLang=lang;
	}
	
	document.write("<style>#sharemodule{width: 200px;position: absolute; background: #FFFFFF;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: #000;} #sharemodule a:hover{color: #CC0000; text-decoration: underline;} .sharebutton{padding-left: "+defaultPadding+"; display: inline; 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\">"+eval("lang_"+defaultLang+"[1]")+"</a><a href=\"javascript:shareshow(-1);\" class=\"shareclose\">"+eval("lang_"+defaultLang+"[2]")+"</a></div><div id=\"sharetext\" class=\"sharemodulehide\"><p>"+eval("lang_"+defaultLang+"[4]")+"</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=\"http://www.llull.tv/media/img_compartir/"+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+"\"> "+eval("lang_"+defaultLang+"[0]")+"</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,defaultLang);
	run=1;
	}else{
		document.write("<a href=\"javascript:shareshow("+run+")\" class=\"sharemodulehide\" id=\"sharelink"+run+"\"> "+eval("lang_"+defaultLang+"[0]")+"</a>");
		guardaArray(urlLink,titleLink);
		run++;
	}
}
