/**
 * @author g.tonelli 01-09
 * 
 */
var shareSocialWebOpen='';
g_PopupIFrame=null;
var socialWebiFrame=null;
var socialWebiFrameTm=false
var socialWebiFrameCloseOnBody=false;
var socialWebiFrameReadyToC=false;
var soclialWebElemClick=null;
function getPageCoords (element) {
var myElement, coords = {x: 0, y: 0}; 
    myElement = element; 
    while (element) { 
        coords.x -= element.scrollLeft; 
        coords.y -= element.scrollTop; 
        element = element.offsetParent; 
    } 
    element = myElement;
    while (element) { 
        coords.x += element.offsetLeft; 
        coords.y += element.offsetTop; 
        element = element.offsetParent; 
    } 
	coords.y += document.body.scrollTop; 
	coords.x += document.body.scrollLeft; 
    return coords; 
} 

function socialWeb2Share(index,name,icon,url){
	this.index = index;
	this.name = name;
	this.icon = icon;
	this.url = url;
}
function socialWebMakeiframe(){
	swebcount = sharedObjArr.length;
	itemH=(21*parseInt((swebcount/2))+85);
		var iFrame = document.createElement("IFRAME");
		iFrame.setAttribute("src", "");
		iFrame.setAttribute("frameborder", "0");
		iFrame.setAttribute("border", "0");
		iFrame.setAttribute("scrolling", "no");
		iFrame.setAttribute("hspace", "0");
		iFrame.setAttribute("vspace", "0");
		iFrame.style.border="1px solid #9D9D9D";
		iFrame.style.position="absolute";
		iFrame.style.display="none";
		iFrame.style.width ='440px';
		iFrame.style.height =itemH+'px';
		document.body.appendChild(iFrame);
	   if(iFrame.contentDocument)   
	      // Firefox, Opera   
	      g_PopupIFrame = iFrame.contentDocument;   
	   else if(iFrame.contentWindow)   
	      // Internet Explorer   
	      g_PopupIFrame = iFrame.contentWindow.document;   
	   else if(iFrame.document)   
	      // Others?   
	      g_PopupIFrame = iFrame.document; 
			  
		

		HTML='<html style="heigth:100%;"><head><link href="/blog/css/moblog.css" type="text/css" rel="stylesheet">';
		HTML+='</head><body style="background-color:#FFFFFF;border:0px;">';
		HTML+='<div><div class="condividirigatop0109">';
		HTML+='<div class="condiviplssocialweb0109">Social Web</div>';
		HTML+='<div class="condiviplssendmail0109"><a href="#socialWeb" id="socialWebSendMail" onclick="parent.mkzoom2(this,450,240,1); return false;" target="_blank">Invia Mail</a></div>';
		HTML+='</div>';
		HTML+='<div class="hack">&nbsp;</div>';
		HTML+='<div class="condividilabel0109">Clicca sul servizio web nel quale vuoi condividere il tuo post</div>';
		HTML+='<div class="hack">&nbsp;</div>';
		HTML+='<div class="condividibody0109">';
		f='left';
		for(var i=0;i<swebcount;i++){
			HTML+='<div class="condivilinkcont0109" style="float:left;" title="' + sharedObjArr[i].name + '">';
			HTML+='<a href="#socialWeb" class="condivilink0109" id="socialWebLink_' + i + '" target="_blank" onclick="parent.socialWebHidePopupDiv()">';
			HTML+='<div class="socialwebIcon ' + sharedObjArr[i].icon + '" style="float:left;">';
			HTML+='<img src="/blog/pics/space.gif" width="16" height="16" border="0"/>';
			HTML+='</div>';
			HTML+=sharedObjArr[i].name;
			HTML+='</a>';
			HTML+='</div>';
			if(f=='left'){
				f='right';
			}else{
				f='left';
				HTML+='<div class="hack">&nbsp;</div>';
			}
		}
		HTML+='</div>';
		HTML+='<div class="condivichiudiframe0109"><a href="javascript:void(0);" onclick="parent.socialWebHidePopupDiv()">chiudi</a></div>';
		HTML+='</div>';
		HTML+='</body></html>';
		g_PopupIFrame.open();   
	 	g_PopupIFrame.write(HTML);  
		g_PopupIFrame.close();
		socialWebiFrame=iFrame;
}

function socialWebMakeDiv(elemClic,permalink,friendlink,posttitle){
	// NEL CASO IN CUI L'IFRAME NN SIA ANCORA PRONTO DO UN TIMEOUT E RICHIAMO LA FUNZIONE
	// QUESTO PUO' AVVENIRE IN CASO DI CLICK VELOCE AL CARICAMENTO DI PAGINA
	if(!socialWebiFrame && socialWebiFrameTm==false){
		socialWebiFrameTm=true;
		setTimeout("socialWebMakeDiv('"+elemClic+"','"+permalink+"','"+friendlink+"','"+posttitle+"')",1000);
		return
	}
	var container=document.getElementById(elemClic);
	soclialWebElemClick=container;
	if (container) {
		if(shareSocialWebOpen!='' || container==shareSocialWebOpen){
			if(container==shareSocialWebOpen){
				socialWebHidePopupDiv()
				shareSocialWebOpen='';
				return
			}
		}
		socialWebiFrameReadyToC=false;
	    var  coords; 
	    coords = getPageCoords(container); 
		socialWebiFrame.style.left =coords.x + 'px';
		socialWebiFrame.style.top =(coords.y + 20)+ 'px';
			
		socialWebiFrame.style.display ='block';
  		g_PopupIFrame.getElementById('socialWebSendMail').href=friendlink
		if (shareSocialWebOpen != '') {
			shareSocialWebOpen = container;
		}
		swebcount = sharedObjArr.length;
		for (var i = 0; i < swebcount; i++) {
			thisLinkObj=g_PopupIFrame.getElementById('socialWebLink_'+i);
			shareName=sharedObjArr[i].name.toLowerCase();
			if(shareName=='facebook' || shareName=='stambleupon' || shareName=='tecnorati'){
				thisLinkObj.href=sharedObjArr[i].url+permalink;
			}else{
				url=sharedObjArr[i].url.replace('##LINK##',permalink)
				url=url.replace('##TITLE##',posttitle)
				thisLinkObj.href=url;
			}
		}
		shareSocialWebOpen=container
		setTimeout('socialWebiFrameReadyToC=true',1000);	
	}
}
function socialWebHidePopupDiv(){
	if(g_PopupIFrame){
		//document.body.removeChild(g_PopupIFrame);
		//g_PopupIFrame=null;
		socialWebiFrame.style.display ='none';
		shareSocialWebOpen='';
		socialWebiFrameReadyToC=false;
	}
}
function closeOnBodyClick(){
	if(socialWebiFrameReadyToC==true){
		socialWebHidePopupDiv();
	}
}
if (window.addEventListener){
	window.addEventListener("load", socialWebMakeiframe, false);
	window.addEventListener("resize", shareWebResize, false);
}else if (window.attachEvent){
	window.attachEvent("onload", socialWebMakeiframe);
	window.attachEvent("onresize", shareWebResize);
}else if (document.getElementById){
	window.onload=socialWebMakeiframe;
	window.onresize=socialWebMakeiframe
}
function shareWebResize(){
	if(soclialWebElemClick){
	    var  coords; 
	    coords = getPageCoords(soclialWebElemClick); 
		socialWebiFrame.style.left =coords.x + 'px';
		socialWebiFrame.style.top =(coords.y + 20)+ 'px';
	}
}
/*
if (window.addEventListener)
window.addEventListener("load", socialWebMakeiframe, false)
else if (window.attachEvent)
window.attachEvent("onload", socialWebMakeiframe)
else if (document.getElementById)
window.onload=socialWebMakeiframe
*/


if(socialWebiFrameCloseOnBody){
	if(document.layers) document.captureEvents(Event.CLICK);
	document.onclick=closeOnBodyClick;
}





