﻿function GetE(ell){return document.getElementById(ell)}
function linkLoad(link){
	var tipo=""
	if(link.substr(0,1)=="("){
		tipo=link.substr(1,link.indexOf(')')-1)
		link=link.substr(link.indexOf(')')+1)
	}else{return ""}
	//alert("tipo: "+tipo+"\nlink: "+link)
	var strt=""
	if(tipo=="aFoto"){
		if (link==0){ strt = ft.replace("[src]","../public/info"+Pre+"/"+((w>320)?"g":"m")+ "/nd" + idDoc+ ".jpg")}
		else { 	strt = ft.replace("[src]","../public/info"+Pre+"/"+((w>320)?"g":"m")+ "/na" + link+ ".jpg")}
		playF( false )
	}else if(tipo=="dFoto"){
	 	strt = ft.replace("[src]","../public/info"+Pre+"/"+((w>320)?"g":"m")+ "/nd" + link+ ".jpg")
	 	playF( false )
	}else if(tipo=="gFoto"){
		strt = ft.replace("[src]","../public/info"+Pre+"/"+((w>320)?"g":"m")+ "/ng" + link+ ".jpg")
		playF( false )
	}else if(tipo=="YouTube"){
		link='http://www.youtube.com/v/'+link+"&fs=1&rel=0&autoplay=1"
		strt = '<embed  style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;" src="' + link + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" ></embed>'
	}else if(tipo=="msnVideo"){
		alert("Microsoft non si è ancora accorta del web2, peccato.")
	    return ""
	}else if(tipo=="Vimeo"){
		if (link.indexOf('vimeo.com')>-1){ link=link.substr(link.indexOf('vimeo.com/')+10) }
		link='http://player.vimeo.com/video/'+link
		strt='<iframe style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;" frameborder="0" scrolling="no" src="'+link+'">Caricamento in corso...</iframe>'
	}else if(tipo=="blipTv"){
		if(isNaN(link)){
			strt='<div style="position:relative;height:'+h+'px;width:'+w+'px; margin:'+b+'px;"><embed src="http://blip.tv/play/'+link+'" width="'+w+'" height="'+h+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true"></embed></div>'
		} else{
			strt='<div style="position:relative;height:'+h+'px;width:'+w+'px; margin:'+b+'px;"><embed src="http://a.blip.tv/scripts/flash/stratos.swf?file=http%3A//blip.tv/rss/flash/'+link+'%3Fsource%3D3&amp;enablejs=true&amp;showplayerpath=http%3A//a.blip.tv/scripts/flash/stratos.swf&amp;autostart=true&amp;smallPlayerMode=true&amp;playerUrl=http%3A//a.blip.tv/scripts/flash/stratos.swf" type="application/x-shockwave-flash" wmode="opaque" allowscriptaccess="always" allowfullscreen="true" pluginspage="http://www.macromedia.com/go/getflashplayer"  width="'+w+'" height="'+h+'" ></embed></div>'
		}
	}else if(tipo=="BingMap"){
		link=link.replace(",","~")
		strt ='<iframe style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;" scrolling="no" frameborder="0" src="http://www.bing.com/maps/embed/?v=2&amp;cp='+link+'&amp;lvl=16&amp;dir=0&amp;emid=5da74e7f-d6bd-a26e-0779-08e8291328c6&amp;w='+w+'&amp;h='+h+'">Caricamento in corso...</iframe>'
	}else if(tipo=="GoogleMap"){
		strt ='<iframe style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;" frameborder="0" scrolling="no"  src="http://maps.google.it/?ie=UTF8&ll='+link+'&output=embed">Caricamento in corso...</iframe>'
	}else if(tipo=="Scribd"){
		strt ='<iframe style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;" scrolling="no" frameborder="0" src="'+link+'">Caricamento in corso...</iframe>'
	}else if(tipo=="Picasa"){
		if(link.indexOf('{show}')>-1){
			strt='<iframe style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;" src="'+link.substr(6)+'" frameborder="0" scrolling="no"></iframe>'
		}else if(link.indexOf('{jpg}')>-1){
			strt='<img style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;" src="'+link.substr(5)+'" border="0"/>'
		}else{
			strt='<embed style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;" type="application/x-shockwave-flash" src="http://picasaweb.google.com/s/c/bin/slideshow.swf" flashvars="'+link+'" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>'
		}
	}else if(tipo=="photobucket"){
		if(link.indexOf('{|}')>-1){
			strt='<a href="'+link.substr(0,link.indexOf('{|}'))+'" onclick="window.open(this.href);return false"><img src="'+link.substr(link.indexOf('{|}')+3)+'" border="0" alt="" style="position:relative;height:'+h+'px;width:'+w+'px; margin:'+b+'px;"/></a>'
		}else{
			strt='<img src="'+link+'" border="0" alt="" style="position:relative;height:'+h+'px;width:'+w+'px; margin:'+b+'px;"/>'
		}
	}else if(tipo=="flickr"){
		if(link.indexOf('{|}')>-1){
	   		strt ='<iframe style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;" scrolling="no" frameborder="0" src="http://www.flickr.com/photos/'+link.substr(0,link.indexOf('{|}'))+'/'+link.substr(link.indexOf('{|}')+3)+'/in/photostream/lightbox/">Caricamento in corso...</iframe>'
		}else if(link.indexOf('{show}')>-1){
	   		strt ='<iframe style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;" scrolling="no" frameborder="0" src="http://www.flickr.com/photos/'+link.substr(0,link.indexOf('{show}'))+'/show/with/'+link.substr(link.indexOf('{show}')+6)+'">Caricamento in corso...</iframe>'
		}else if(link.indexOf('{jpg}')>-1){
			strt='<img style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;" src="'+link.substr(5)+'" border="0"/>'
		}else{return ""}
	}else if(tipo=="WikipediA"){
	   	strt ='<iframe style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;" frameborder="0" src="http://'+link.substr(0,link.indexOf('.'))+'.wikipedia.org/w/index.php?title='+link.substr(link.indexOf('.')+1)+'&printable=yes">Caricamento in corso...</iframe>'
	}else if(tipo=="slideshare"){
		strt='<object type="application/x-shockwave-flash" wmode="opaque" data="http://static.slideshare.net/swf/ssplayer2.swf?'+link+'" style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;">'
		strt+='<param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?'+link+'"/>'
		strt+='<param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/></object>'
	}else if(tipo=="imageshack"){
		strt='<img style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;" src="'+link+'" border="0"/>'
	}else if(tipo=="googleDocs"){
		var tip=link.substr(0,6)
		link=link.substr(6)
		if(tip=="{gPrs}"){
			strt='<iframe style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;" frameborder="0" scrolling="no" src="https://docs.google.com/present/view?id='+link+'">Caricamento in corso...</iframe>'
		}else if(tip=="{gClc}"){
	        strt='<iframe style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;" frameborder="0" src="https://spreadsheets.google.com/pub?key='+link+'&single=true&gid=0&output=html&widget=true">Caricamento in corso...</iframe>'
		}else if(tip=="{gDoc}"){
	        strt='<iframe style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;" frameborder="0" src="https://docs.google.com/View?docID='+link+'&revision=_latest">Caricamento in corso...</iframe>'
		}else if(tip=="{gDrw}"){
			strt='<img style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;" src="https://docs.google.com/drawings/pub?id='+link+'&w='+w+'&h='+h+'" border="0"/>'
		}else if(tip=="{gFrm}"){
		    strt='<iframe style="position:relative;height:'+h+'px; width:'+w+'px;margin:'+b+'px;" src="https://spreadsheets.google.com/embeddedform?formkey='+link+'" frameborder="0" marginheight="0" marginwidth="0">Caricamento in corso...</iframe>'
		}else{return ""}
    }
	document.getElementById('fotoHC').innerHTML = strt
}

function FotoZoom(id){
	if ( typeof id == "undefined"){ id = 0 }
	var obj1 = GetE('fotoZ')
	if(navigator.appName.indexOf("Microsoft Internet Explorer")>=0){ obj2.filters[0].apply();};
	if (obj1.style.visibility == "visible"){ obj1.style.visibility="hidden";}
	else{ 
		obj1.style.visibility="visible";
		if(id==0){
			GetE('fotoZimg').src=document.getElementById('fotoH').src.replace("/m/","/g/");
		}else{
			GetE('fotoZimg').src='../public/info'+Pre+'/g/'+id+'.jpg'
		}
	};
	if(navigator.appName.indexOf("Microsoft Internet Explorer")>=0){ obj2.filters[0].play();}
}


function playF( plSt ){
	if ( typeof plSt == "undefined"){ plSt = !playSt } 
	try{
		if( plSt ){
			GetE('play').style.background="url('style/Tstop.png') no-repeat center center"
			playSt = true
			playT(0)
		} else{
			GetE('play').style.background="url('style/Tplay.png') no-repeat center center"
			playSt = false
		}
	}catch(err){}
}
function playT(ind2){
	if(playSt){
		if ( ind2 >= (playV.length) ){ ind2 = 0 };
		var obj2
		if (GetE('fotoZ').style.visibility == "visible"){
			 obj2= GetE('fotoZimg')}
		else { 
			obj2 = GetE('fotoH')
		}
		if(navigator.appName.indexOf("Microsoft Internet Explorer")>=0){ obj2.filters[0].apply();};
		if (ind2==0){ obj2.src="../public/info"+Pre+"/g/nd" + playV[ 0 ] + ".jpg";}
		else { 	obj2.src="../public/info"+Pre+"/g/na" + playV[ ind2 ]+ ".jpg";};
		if(navigator.appName.indexOf("Microsoft Internet Explorer")>=0){ obj2.filters[0].play();};
		ind2+=1
		setTimeout("playT("+ ind2  +")",5000);
	} 
}

function DocPre(){
	if(typeof GetE('treeDoc') == "undefined"){ return "" }
	var tree=GetE('treeDoc').innerHTML.replace(/<\/LI>/g,"</li>").split("</li>")
	var str=""
	var strT=""
	//tree=tree.innerHTML.replace(/<\/LI>/g,"</li>")/per colpa di explorer bisona aggiungere questa merda
	//tree=tree.split("</li>")
	for (i in tree){ 
		tree[i]=tree[i].replace(/&amp;/g,";")
		tree[i]=tree[i].substring(tree[i].indexOf("do=")+3,tree[i].indexOf(";wv=")) 
	}
	for (i in tree){
		str=tree[i]
		if(str==idDoc){
			if(i==0){str=tree[tree.length-2]}
			else{str=tree[i-1]}
			break;
		}
		if(i==tree.length){str=""; break;}
	}
	if(str!=""){
		strT=location.href
		strT=strT.substring(0,strT.indexOf("do=")+3) +str+ strT.substring(strT.indexOf("wv=")-1)
		location.href=strT
	}
}
function DocSuc(){
	if(typeof GetE('treeDoc') == "undefined"){ return "" }
	var tree=GetE('treeDoc')
	var str=""
	var strT=""
	tree=tree.innerHTML.replace(/<\/LI>/g,"</li>")//per colpa di IExplorer bisona aggiungere questa merda
	tree=tree.split("</li>")
	for (i in tree){ 
		tree[i]=tree[i].replace(/&amp;/g,";")
		tree[i]=tree[i].substring(tree[i].indexOf("do=")+3,tree[i].indexOf(";wv=")) 
	}
	for (i in tree){
		str=tree[i]
		if(str==idDoc){
			if(i==tree.length-2){ str=tree[0] }
			else{ str=tree[(i*1+1)] }
			break;
		}
		if(i==tree.length){str=""; break;}
	}
	if(str!=""){
		strT=location.href
		strT=strT.substring(0,strT.indexOf("do=")+3) +str+ strT.substring(strT.indexOf("wv=")-1)
		location.href=strT
	}
}


