//content objects definitions
function galaxy(id,name,slug,keywords,polygan,people_in,artworks_in,networks_in){

	this.className='galaxy';
	this.id=id;
	this.name=name;
	this.slug=slug;
	this.layer=null;
	this.display="none";

	//enumerables
	this.keywords=keywords;
	this.polygan=polygan;
	this.people=people_in;
	this.artworks=artworks_in;
	this.networks=networks_in;
	this.connectors=new Array();
	this.activeSpots=new Array();

// object methods
	this.mark=mark;
	this.blackhole=blackhole;

	this.loadKeywords=loadKeywords;
	this.displayKeyword=displayKeyword;
	this.hideKeyword=hideKeyword;
	this.unloadKeywords=unloadKeywords;
	//no addConnector since they are added in mark()
	this.removeConnectors=removeConnectors;
	this.removeActivePopups=removeActivePopups;
	this.removeSidePopups=removeSidePopups;
	this.registerSideSpots=registerSideSpots;
	this.registerActiveSpots=registerActiveSpots;
	this.registerSession=registerSession;
	this.unregisterSession=unregisterSession;

	//this.makeAnchoredPopups=makeAnchoredPopups;
//	this.getRelatedPeople=getRelatedPeople;
//	this.getRelatedKeywords=getRelatedKeywords;
}
function city(id,name,lon,lat,people_in,networks_in,artworks_in){
	this.className='city';
	this.id=id;
	this.name=name;
	this.lon=lon;
	this.lat=lat;
	this.people=people_in;
	this.networks=networks_in;
	this.artworks=artworks_in;

}
function keyword(id,name,category,polygan,people,artworks,networks){
	this.className='keyword';
	this.id=id;
	this.name=name;
	this.category=category;
	this.polygan=polygan;
	this.people=people;
	this.artworks=artworks;
	this.networks=networks;
	this.sideSpots=new Array();
	this.flourish=flourish;
	this.retract=retract;
	//	this.drawPopupPeople=drawPopupPeople;

	//	document.write(this.category);
}
function person(id,name,firstname,year_born,year_deceased){
	this.className='person';
	this.pluralClassName='people';
	this.id=id;
	this.name=name;
	this.firstname=firstname;
	this.year_born=year_born;
	this.year_deceased=year_deceased;
	//enumerables
	this.urls=new Array();
	this.artworks=new Array();
	this.popups=new Array();
	this.features=new Array();
	this.cities=new Array();
	this.citiesType=new Array();
	//methods
	this.moreInfo=moreInfo;
	this.displayInfobox=displayInfobox;
	this.getIndexVal=getIndexVal;
	this.getKeywords=getKeywords;
	this.fetchAffinities=fetchAffinities;
}
function network(id,name,year_creation_in,year_end_in){
	this.className='network';
	this.pluralClassName='networks';
	this.id=id;
	this.name=name;
	this.year_creation=year_creation_in;
	this.year_end=year_end_in;
	//enumerables
	this.urls=new Array();
	this.popups=new Array();
	this.features=new Array();
	this.cities=new Array();
	this.citiesType=new Array();
	//methods
	this.moreInfo=moreInfo;
	this.displayInfobox=displayInfobox;
	this.getIndexVal=getIndexVal;
	this.getKeywords=getKeywords;
	this.fetchAffinities=fetchAffinities;
}
function artwork(id,name,image){
	this.className='artwork';
	this.pluralClassName='artworks';
	this.id=id;
	this.name=name;
	this.image=image;
	//enumerables
	this.urls=new Array();
	this.popups=new Array();
	this.features=new Array();
	this.cities=new Array();
	this.citiesType=new Array();
	//methods
	this.moreInfo=moreInfo;
	this.displayInfobox=displayInfobox;
	this.getIndexVal=getIndexVal;
	this.getKeywords=getKeywords;
	this.fetchAffinities=fetchAffinities;

}
function url(title_in,uri_in){
    this.className='url';
    this.title=title_in;
    this.uri=uri_in;
}
function annex(id_in,title_in,image_in,description_in,url_in){
	this.className='annex';
	this.pluralClassName='annexes';
	this.id=id_in;
	this.title=title_in;
	this.image=image_in;
	this.description=description_in;
	this.url=url_in;
	//enumerables
	this.citiesLon=new Array();
	this.citiesLat=new Array();

}
//map objects definitions
function activeSpot(lon_in,lat_in,style_in,icon_in){
	this.className='activeSpot';
	this.lon=lon_in;
	this.lat=lat_in;
	this.style=style_in;
	this.icon=icon_in;
	this.marker=null;
	this.deployed=false;

	//enumerables
	this.anchorPoint=new Array();
	this.connectors=new Array();
	this.popups=new Array();
	this.seeds=new Array();
	//this.methods=new Array();

	//methods
	this.mark=mark;
	this.tearOut=tearOut;

	this.plantPopups=plantPopups;
	this.growPopups=growPopups;
	this.removePopups=removePopups;
	this.removeSeeds=removeSeeds;

	this.registerSession=registerSession;
	this.unregisterSession=unregisterSession;
}
function sideSpot(keyword_in,lon_in,lat_in){
	this.className='sideSpot';
	this.keyword=keyword_in;
	this.lon=lon_in;
	this.lat=lat_in;
	this.deployed=false;
	//enumerables
	this.seeds=new Array();
	this.connectors=new Array();
	this.popups=new Array();
	//methods
	this.tearOut=tearOut;
	this.plantPopups=plantPopups;
	this.growPopups=growPopups;
	this.removePopups=removePopups;
	this.removeSeeds=removeSeeds;
	this.registerSession=registerSession;
	this.unregisterSession=unregisterSession;
}
function popupSeed(lon_in,lat_in,style_in,html_in,kindOf_in,idxFrom_in){
	this.className='popupSeed';
	this.lon=lon_in;
	this.lat=lat_in;
	this.style=style_in;
	this.html=html_in;
	this.kindOf=kindOf_in;
	this.idxFrom=idxFrom_in;
	this.tearOut=tearOut;
}
//interface object definition
function ganDropDownMenu(x_in,y_in,activeKeywords_in,direction_in,layer_id_in,galaxy_in){
	this.className='ganDropDownMenu';
	this.visibility='hidden';
	this.galaxy=galaxy_in;
	this.x=x_in;
	this.y=y_in;
	this.direction=direction_in;
	this.layer_id=layer_id_in;
	this.ta="";
	//enumerables
	this.activeKeywords=activeKeywords_in;
	//methods
	this.preform=preform;
	this.forceMenu=forceMenu;
	this.showHide=showHide;
}

//objects methods
function mark(){
	if(this.className=='galaxy'){
		//alert(this.people.length);
		//var mymarkers=new Array();
		var galaxyPoints=new Array();
		for(var i=0;i<this.polygan.length;i++){

			this.registerActiveSpots(this.polygan[i],gan_style_network,'networks',gan_network_icon,style_connector_networks);
			this.registerActiveSpots(this.polygan[i],gan_style_artwork,'artworks',gan_artwork_icon,style_connector_artworks);
			this.registerActiveSpots(this.polygan[i],gan_style_city,'people',gan_icon,style_connector);
			var theCity=cities[parseInt(this.polygan[i])];
			var galaxyPoint = new OpenLayers.Geometry.Point(theCity.lon,theCity.lat);
			galaxyPoints.push(galaxyPoint);
		}
		var polyganFeature=new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LinearRing(galaxyPoints),null,style_connector_dotted);
		var myFeatures=new Array();
		myFeatures.push(polyganFeature);
		gan_galaxies_layer.addFeatures(myFeatures);
		this.connectors=myFeatures;
	}else if(this.className=='activeSpot'){
		var index_marker=current_markers.length;
		var mymarker=new OpenLayers.Marker(new OpenLayers.LonLat(this.lon,this.lat),this.icon,index_marker);
		mymarker.events.register("mousedown", mymarker, mousedown);
		gan_markers_layer.addMarker(mymarker);
		this.marker=mymarker;
		current_markers.push(index_marker);
		var newPoint = new OpenLayers.Geometry.Point(this.lon,this.lat);
		var myFeature=new OpenLayers.Feature.Vector(newPoint,null,this.style);
// 		if(this.style==gan_style_artwork){
// 			debug_log('here');
// }
		var myFeatures=new Array();
		myFeatures.push(myFeature);
		this.anchorPoint=myFeatures;
		current_features.push(gan_galaxies_layer.features.length);
		gan_galaxies_layer.addFeatures(myFeatures);
}
}
// function makeAnchor(){

// }
function blackhole(){
	//alert('calling blackhole');
	//1. unregister session variables for this object
	//2.nullify all attachment
	//3.nullify the galaxy itself -> no we need it later
	if(this.className=='galaxy'){
		this.unregisterSession();
		for(var i=0;i<this.activeSpots.length;i++){
			//debug_log(this.activeSpots[i]);
			if(this.activeSpots[i]){
				this.activeSpots[i].tearOut();}
		}
	}
	this.activeSpots=new Array();
	this.removeConnectors();
	emptyInfobox();
	this.unloadKeywords();
// 	for(var key in this){
// 		this[key]=null;
// 	}
	
}
function darkNight(){

    if(current_galaxy!=''){
	current_galaxy.blackhole();
}
}
function plantPopups(forAnemone_in, thePeople_in, theStyle_in,kindOf,theIdxs){
	var petals=new Array();

	if((this.className=='activeSpot')|(this.className=='sideSpot')){
		if(forAnemone_in.length>2){
			var petals=anemone(forAnemone_in,this.lon,this.lat,gan_radius);
		}else if((forAnemone_in.length>0)&&(forAnemone_in.length<3)){
			var petals=tige(forAnemone_in,this.lon,this.lat,gan_radius);
			//alert(petals);
		}
		//alert(petals.length);
		if(petals.x){
			for(var i=0;i<petals.x.length;i++){
				this.seeds.push(new popupSeed(petals.x[i],petals.y[i],theStyle_in,thePeople_in[i],kindOf,theIdxs[i]));
				//alert(this.seeds.length);
			}}

	}
// else if(this.className=='sideSpot'){

// 	}
}

function growPopups(){
	//debug_log('Entering growPopup');
	if((this.className=='activeSpot')|(this.className=='sideSpot')){
		//debug_log(this.seeds);
		if(this.seeds.length>0){
		for(var i=0;i<this.seeds.length;i++){
			var pointList = [];
// 			var newdeg_lon_pp=(this.seeds[i].lon+0.2);
// 			var newdeg_lat_pp=(this.seeds[i].lat-0.2);
			var newdeg_lon_pp=(this.seeds[i].lon);
			var newdeg_lat_pp=(this.seeds[i].lat);
			var newPoint = new OpenLayers.Geometry.Point(newdeg_lon_pp,newdeg_lat_pp);
			pointList.push(newPoint);
			var newPoint = new OpenLayers.Geometry.Point(this.lon,this.lat);
			pointList.push(newPoint);
			var lineFeature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LineString(pointList),null,this.seeds[i].style);
			current_features.push(gan_galaxies_layer.features.length);
			this.connectors.push(lineFeature);
			gan_galaxies_layer.addFeatures(lineFeature);
			var locId=this.seeds[i].kindOf+"_"+eval(this.seeds[i].kindOf+"["+this.seeds[i].idxFrom+"].id");
			var highlight_bg='';
			if(locId==gan_inInfobox){
			    //highlight_bg=' background:rgb(73,196,25);';
}
			//debug_log(locId+" "+gan_inInfobox);
			var popup = new OpenLayers.Popup(current_popups.length, new OpenLayers.LonLat(this.seeds[i].lon,this.seeds[i].lat),null, "<div style=\"font-size:10px;margin:0px;padding:0px;text-align:center;font-style:italic;"+highlight_bg+"\" class=\""+locId+"\"><a href=\"#\" style=\"color:white;\" onClick=\""+this.seeds[i].kindOf+"["+this.seeds[i].idxFrom+"].displayInfobox();\">"+this.seeds[i].html+"</a></div>", false);
			popup.setBorder('1px solid '+this.seeds[i].style.strokeColor);
			popup.setBackgroundColor(this.seeds[i].style.strokeColor);
			popup.setSize(new OpenLayers.Size((this.seeds[i].html.length)*7,14));
			this.popups.push(popup);
			current_popups.push(popup);
			map.addPopup(popup,false);
}
		}
			this.deployed=true;

}
}
function removePopups(){
	if((this.className=='activeSpot')|(this.className=='sideSpot')){
		while(this.popups.length>0){
			var mypopup=this.popups.shift();
			mypopup.destroy();
			//array_shift ???
			//map.popups[key].destroy();
			//map.removePopup(map.popups[i]);
}
		current_popups=new Array();
		this.popups=new Array();
		//alert(this.connectors.length);
		//alert(gan_galaxies_layer.features.length);
		for(var i=0;i<this.connectors.length;i++){
			this.connectors[i].destroy();
}
		this.connectors=new Array();
		this.deployed=false;
}
}
function removeSeeds(){
	if((this.className=='activeSpot')|(this.className=='sideSpot')){
		for(var i=0;i<this.seeds.length;i++){
			this.seeds[i].tearOut();
}
	}
}

function giveFocus(){
    //debug_log(gan_inInfobox);
    releaseFocus();
    var docList = document.getElementsByTagName('div');
    var matchArray = new Array();
    //debug_log(docList.length);
    for (var i=0;i<docList.length;i++) {
	if (docList[i].className==gan_inInfobox) {
	    var tst_radical=docList[i].className.substring(0,5);
	    //debug_log(gan_inInfobox+" "+docList[i].style.background);
	    if(tst_radical=='peopl'){
		docList[i].style.color="#c287aa";
		var children=docList[i].childNodes;
		for (var k=0;k<children.length;k++) {
		    if ((children[k].nodeType == 1)&&(children[k].nodeName =='A')) {
			children[k].style.color="#c287aa";
		    }
		}
	    }
	    else if(tst_radical=='netwo'){
		docList[i].style.color="#43aa1d";
		var children=docList[i].childNodes;
		for (var k=0;k<children.length;k++) {
		    if ((children[k].nodeType == 1)&&(children[k].nodeName =='A')) {
			children[k].style.color="#43aa1d";
		    }
		}
	    }
	    else if(tst_radical=='artwo'){
		docList[i].style.color="#ff3f00";
		var children=docList[i].childNodes;
		for (var k=0;k<children.length;k++) {
		    if ((children[k].nodeType == 1)&&(children[k].nodeName =='A')) {
			children[k].style.color="#ff3f00";
		    }
		}
	    }
	    docList[i].style.background="rgb(32,32,29)";
	}
    }
}
function releaseFocus(){
	//debug_log(gan_inInfobox);
// 	var str='people';
// 	debug_log(str.substring(0,5));
   var docList = document.getElementsByTagName('div');
   var matchArray = new Array();
    for (var i=0;i<docList.length;i++) {
		var tst_radical=docList[i].className.substring(0,5);
		//if(i==1){debug_log(tst_radical)}
		if((tst_radical=='peopl')|(tst_radical=='netwo')|(tst_radical=='artwo')){
		    //        if (docList[i].className==gan_inInfobox) {
		    //debug_log(gan_inInfobox+" "+docList[i].style.background);
		    var children=docList[i].childNodes;
		    for (var k=0;k<children.length;k++) {
			if ((children[k].nodeType == 1)&&(children[k].nodeName =='A')) {
			    children[k].style.color="#ffffff";
			}
		    }
		    docList[i].style.background="";
		}
	}
}
function removeConnectors(){
	if(this.className=='galaxy'){
		if((tsr_isArray(this.connectors))&&(this.connectors.length>0)){
			//alert(this.connectors);
			gan_galaxies_layer.removeFeatures(this.connectors);
			this.connectors=new Array();
}
	}else if((this.className=='activeSpot')|(this.className=='sideSpot')){
		if((tsr_isArray(this.connectors))&&(this.connectors.length>0)){
			gan_galaxies_layer.removeFeatures(this.connectors);
}
}
}

function tearOut(){
	if(this.className=='activeSpot'){
		//remove attachments
		this.removeSeeds();
		this.removePopups();
		try{
			gan_markers_layer.removeMarker(this.marker);
			this.marker.destroy();

		}catch(err){
			//@todo logme
			//todo watch if this resurfaces
			//alert(err.description);
		}
		gan_galaxies_layer.removeFeatures(this.anchorPoint);

		//nullify as
		for(var key in this){
			this[key]=null;
		}
	}else if(this.className=='popupSeed'){
		//nullify seed
		for(var key in this){
			this[key]=null;
		}}
     else if(this.className=='sideSpot'){
		//nullify seed
		this.removeSeeds();
		this.removePopups();
		for(var key in this){
			this[key]=null;
		}}
}
function loadKeywords(){
	if(this.className=='galaxy'){
		//alert(this.keywords.length);
		theIm=gan_img_root+this.name+'_on.png';
		//alert(theIm);
		//var str_keywords="<div style=\"background-image:url('"+theIm+"');background-repeat:no-repeat;padding-left:40px;padding-bottom:15px;\">Keywords</div><div class=\"contextMenuHeader\">";
			for(var i=0;i<this.keywords.length;i++){
					for(var j=0;j<this.polygan.length;j++){
						//1.artworks
						this.registerSideSpots(this.polygan[j],this.keywords[i],style_connector_artworks,'artworks');
						//2.networks
						this.registerSideSpots(this.polygan[j],this.keywords[i],style_connector_networks,'networks');
						//3.people
						this.registerSideSpots(this.polygan[j],this.keywords[i],style_connector,'people');

			}
			}
			//str_keywords+="</div>";
			//document.getElementById('gan_infos_keywords').innerHTML=str_keywords;
	}

}
function unloadKeywords(){
	if(this.className=='galaxy'){

		//alert(this.keywords.length);
		var str_keywords='';
		//var str_keywords="<a href=\"#\" onClick=\"javascript:current_galaxy=galaxies[2];gan_msg('Loading new galaxy ...');setTimeout('current_galaxy.mark()',0);\">Load galaxy</a>";
		for(var i=0;i<this.keywords.length;i++){
			for(var j=0;j<keywords[this.keywords[i]].sideSpots.length;j++){
				keywords[this.keywords[i]].sideSpots[j].tearOut();
}
			keywords[this.keywords[i]].sideSpots=new Array();
}
		document.getElementById('gan_infos_keywords').innerHTML=str_keywords;
}

}
function flourish(contextInfobox){
	if(!contextInfobox){
		emptyInfobox();}else{

}
	if(this.className=='keyword'){
		current_galaxy.removeActivePopups();
		current_galaxy.removeSidePopups();
		//debug_log(this.sideSpots.length);
		for(var i=0;i<this.sideSpots.length;i++){
			this.sideSpots[i].growPopups();
}
	for(var i=0;i<keywords.length;i++){

		var kw_id='kwl_'+keywords[i].id;
		var xkw_id='xkwl_'+keywords[i].id;
// 		if(i==0){
// 			alert(kw_id);
// 		}
        if(document.getElementById(kw_id)){
		if(this.id==keywords[i].id){
			document.getElementById(kw_id).style.color="white";
			document.getElementById(kw_id).style.background="#00b3ff";
			//debug_log("the element "+kw_id+" color "+document.getElementById(kw_id).style.color+" bg "+document.getElementById(kw_id).style.background);


			}
		else{
			document.getElementById(kw_id).style.color="#00b3ff";
			document.getElementById(kw_id).style.background="transparent";

		}}
        if(document.getElementById(xkw_id)){
		if(this.id==keywords[i].id){
			document.getElementById(xkw_id).style.color="rgb(29,30,30)";
			document.getElementById(xkw_id).style.background="#00b3ff";

			}
		else{
			document.getElementById(xkw_id).style.color="rgb(29,30,30)";
			document.getElementById(xkw_id).style.background="transparent";

		}}
}


}
}
function retract(){
	if(this.className=='keyword'){
		//debug_log(this.sideSpots.length);
		for(var i=0;i<this.sideSpots.length;i++){
			this.sideSpots[i].removePopups();
}

	for(var i=0;i<keywords.length;i++){

		var kw_id='kwl_'+keywords[i].id;
		var xkw_id='xkwl_'+keywords[i].id;
// 		if(i==0){
// 			alert(kw_id);
// 		}
        if(document.getElementById(kw_id)){

			document.getElementById(kw_id).style.color="#00b3ff";
			document.getElementById(kw_id).style.background="transparent";

		}
        if(document.getElementById(xkw_id)){

			document.getElementById(xkw_id).style.color="rgb(29,30,30)";
			document.getElementById(xkw_id).style.background="transparent";

		}
}
	}

}
function removeSidePopups(){
	if(this.className=='galaxy'){
		for(var i=0;i<this.keywords.length;i++){
			keywords[this.keywords[i]].retract();
}
}
}
function removeActivePopups(){
	if(this.className=='galaxy'){
		for(var i=0;i<this.activeSpots.length;i++){
			this.activeSpots[i].removePopups();
}
	}
}

function displayInfobox(){
    var str_attached='';

    str_info='';
    if(this.className=='person'){
	gan_inInfobox=this.pluralClassName+"_"+this.id;
	giveFocus();
	str_info+="<div class=\"infobox_title\">"+this.firstname+" "+this.name+"</div>";
	str_info+="<div>";
	if(this.year_born!='0'){
	    str_info+=this.year_born;}
	if(this.year_deceased!='0'){
	    str_info+=" - "+this.year_deceased;}
	str_info+="</div>";
	str_info+="<div>";
	var arCities=new Array();
	//debug_log(this.cities+" - "+this.citiesType+" - "+cities.length);
	for(var i=0;i<this.cities.length;i++){
	    if(!arCities[this.citiesType[i]]){
		arCities[this.citiesType[i]]=new Array();
	    }
	    arCities[this.citiesType[i]].push(cities[this.cities[i]].name);
	}
	if(arCities[gan_origin]){
	    str_info+='<div class="infobox_sub">City of origin</div>';
	    for(var j=0;j<arCities[gan_origin].length;j++){
		str_info+=arCities[gan_origin][j];
		if(j<(arCities[gan_origin].length)-1){
		    str_info+=', ';
		}
	    }
	}
	if(arCities[gan_residence]){
	    str_info+='<div class="infobox_sub">City of residence</div>';
	    for(var j=0;j<arCities[gan_residence].length;j++){
		str_info+=arCities[gan_residence][j];
		if(j<(arCities[gan_residence].length)-1){
		    str_info+=', ';
		}
	    }
	}
	if(arCities[gan_creation]){
	    str_info+='<div class="infobox_sub">City of creation</div>';
	    for(var j=0;j<arCities[gan_creation].length;j++){
		str_info+=arCities[gan_creation][j];
		if(j<(arCities[gan_creation].length)-1){
		    str_info+=', ';
		}
	    }
	}
	if(this.urls.length>0){
	    str_info+='<div class="infobox_sub">Urls</div>';
	    str_info+='<div class="infobox_keywords">';

	    for(var j=0;j<this.urls.length;j++){
		str_info+='<a href="'+this.urls[j].uri+'" target="_blank" class="infobox_link">'+this.urls[j].title+'</a>';
		if(j<(this.urls.length)-1){
		    str_info+=', ';
		}
	    }}
	str_info+='</div>';
	var myIndex=this.getIndexVal();
	var myKeywords;
	myKeywords=this.getKeywords();
	var display_media=false;
	var str_media='';
	if(myKeywords[1].length>0){
	    display_media=true;
	    str_media+='<div class="infobox_sub">media</div>';
	    str_media+='<div class="infobox_keywords">';
	    for(var i=0;i<myKeywords[1].length;i++){
		str_media+=keywords[myKeywords[1][i]].name;
		if(i<(myKeywords[1].length-1)){
		    str_media+=', ';
}
}
	    str_media+='</div>';
}
	if(display_media){
	    str_info+=str_media;
}
	var display_tags=false;
	var str_info_tags='';
	str_info_tags+='<div class="infobox_sub">tags</div>';
	str_info_tags+='<div class="infobox_keywords">';
	//debug_log(myKeywords.length);
	for(var i=2;i<myKeywords.length;i++){
	    //debug_log(myKeywords[i].length);
	    if(myKeywords[i].length>0){
		//str_info+='<div class="infobox_keywords"><!--<span>'+galaxies[i].name+'</span>-->';
		for(var j=0;j<myKeywords[i].length;j++){
		    var dd_id=getDropDownIndex(galaxies[i].name);
		    if(!inArray(keywords[myKeywords[i][j]].name,galaxies[i].slug)){
			if(galaxies[i]!=current_galaxy){
			    str_info_tags+=" <a href=\"#\" id=\"xkwl_"+keywords[myKeywords[i][j]].id+"\" onClick=\"javascript:darkNight();current_galaxy=galaxies["+i+"];current_galaxy.mark();toggleImg('"+galaxies[i].name+"');gan_dropdowns["+dd_id+"].forceMenu();current_galaxy.loadKeywords();people["+myIndex+"].displayInfobox();keywords["+myKeywords[i][j]+"].flourish(true);\" class=\"infobox_link\" style=\"font-family:Nimbus,Geneva, Helvetica,Verdana;\">"+keywords[myKeywords[i][j]].name+"</a> - ";}else{
			    str_info_tags+=" <a href=\"#\" id=\"xkwl_"+keywords[myKeywords[i][j]].id+"\" onClick=\"javascript:gan_dropdowns["+dd_id+"].forceMenu();keywords["+myKeywords[i][j]+"].flourish(true);forceImg('"+galaxies[i].name+"');\" class=\"infobox_link\" style=\"font-family:Nimbus,Geneva, Helvetica,Verdana;\">"+keywords[myKeywords[i][j]].name+"</a> - ";
			}
			display_tags=true;

		    }
		}
		//str_info+='</div>';
	    }
	}
	str_info_tags+="</div>";
	str_info_tags+="</div>";
	if(display_tags){
	    str_info+=str_info_tags;
}
	str_info+='<div><a href="#" onClick="javascript:people['+myIndex+'].moreInfo(\'affinities\');" class=\"more_info capitalize\"><img src="'+gan_img_root+'arrow_infobox.png" alt="More info" title="More info"> More info</a></div>';
	if(this.artworks.length>0){
	    str_attached+='<div>';
	    for(var j=0;j<this.artworks.length;j++){
		str_attached+=artworks[this.artworks[j]].name+'<br />';
		if(artworks[this.artworks[j]].image.length>0){
		    str_attached+='<div class="infobox_sub"><img src="'+gan_root+'/images/display/160/*/resize/'+artworks[this.artworks[j]].image+'"></div>';

}
}
	    str_attached+='</div>';
}
    document.getElementById("gan_infos_context").style.borderWidth='2px';
    document.getElementById("gan_infos_context").style.borderColor='#c287aa';
    document.getElementById("gan_infos_context").style.borderStyle='solid';
    }
    if(this.className=='network'){
	str_attached='';
	gan_inInfobox=this.pluralClassName+"_"+this.id;
	giveFocus();
	str_info+="<div class=\"infobox_title\">"+this.name+"</div>";
	str_info+="<div>";
	if(this.year_creation!='0000'){
	    str_info+=this.year_creation;}
	if(this.year_end!='0000'){
	    str_info+=" - "+this.year_end;}
	str_info+="</div>";
	str_info+="<div>";
	var arCities=new Array();
	//debug_log(this.cities+" - "+this.citiesType+" - "+cities.length);
	for(var i=0;i<this.cities.length;i++){
	    if(!arCities[this.citiesType[i]]){
		arCities[this.citiesType[i]]=new Array();
	    }
	    arCities[this.citiesType[i]].push(cities[this.cities[i]].name);
	}
	if(arCities[gan_origin]){
	    str_info+='<div class="infobox_sub">City of origin</div>';
	    for(var j=0;j<arCities[gan_origin].length;j++){
		str_info+=arCities[gan_origin][j];
		if(j<(arCities[gan_origin].length)-1){
		    str_info+=', ';
		}
	    }
	}
	if(arCities[gan_residence]){
	    str_info+='<div class="infobox_sub">City of residence</div>';
	    for(var j=0;j<arCities[gan_residence].length;j++){
		str_info+=arCities[gan_residence][j];
		if(j<(arCities[gan_residence].length)-1){
		    str_info+=', ';
		}
	    }
	}
	if(arCities[gan_creation]){
	    str_info+='<div class="infobox_sub">City of creation</div>';
	    for(var j=0;j<arCities[gan_creation].length;j++){
		str_info+=arCities[gan_creation][j];
		if(j<(arCities[gan_creation].length)-1){
		    str_info+=', ';
		}
	    }
	}
	if(this.urls.length>0){
	    str_info+='<div class="infobox_sub">Urls</div>';
	    str_info+='<div class="infobox_keywords">';

	    for(var j=0;j<this.urls.length;j++){
		str_info+='<a href="'+this.urls[j].uri+'" target="_blank" class="infobox_link">'+this.urls[j].title+'</a>';
		if(j<(this.urls.length)-1){
		    str_info+=', ';
		}
	    }}
	str_info+='</div>';
	var myIndex=this.getIndexVal();
	var myKeywords;
	myKeywords=this.getKeywords();
	var display_media=false;
	var str_media='';
	if(myKeywords[1].length>0){
	    display_media=true;
	    str_media+='<div class="infobox_sub">media</div>';
	    str_media+='<div class="infobox_keywords">';
	    for(var i=0;i<myKeywords[1].length;i++){
		str_media+=keywords[myKeywords[1][i]].name;
		if(i<(myKeywords[1].length-1)){
		    str_media+=', ';
}
}
	    str_media+='</div>';
}
	if(display_media){
	    str_info+=str_media;
	}
	var display_tags=false;
	var str_info_tags='';
	str_info_tags+='<div class="infobox_sub">tags</div>';
	str_info_tags+='<div class="infobox_keywords">';
	//debug_log(myKeywords.length);
	for(var i=2;i<myKeywords.length;i++){
	    //debug_log(myKeywords[i].length);
	    if(myKeywords[i].length>0){
		//str_info+='<div class="infobox_keywords"><!--<span>'+galaxies[i].name+'</span>-->';
		for(var j=0;j<myKeywords[i].length;j++){
		    var dd_id=getDropDownIndex(galaxies[i].name);
		    if(!inArray(keywords[myKeywords[i][j]].name,galaxies[i].slug)){
			if(galaxies[i]!=current_galaxy){
			    str_info_tags+=" <a href=\"#\" id=\"xkwl_"+keywords[myKeywords[i][j]].id+"\" onClick=\"javascript:darkNight();current_galaxy=galaxies["+i+"];current_galaxy.mark();toggleImg('"+galaxies[i].name+"');gan_dropdowns["+dd_id+"].forceMenu();current_galaxy.loadKeywords();networks["+myIndex+"].displayInfobox();keywords["+myKeywords[i][j]+"].flourish(true);\" class=\"infobox_link\" style=\"font-family:Nimbus,Geneva, Helvetica,Verdana;\">"+keywords[myKeywords[i][j]].name+"</a> - ";}else{
			    str_info_tags+=" <a href=\"#\" id=\"xkwl_"+keywords[myKeywords[i][j]].id+"\" onClick=\"javascript:gan_dropdowns["+dd_id+"].forceMenu();keywords["+myKeywords[i][j]+"].flourish(true);forceImg('"+galaxies[i].name+"');\" class=\"infobox_link\" style=\"font-family:Nimbus,Geneva, Helvetica,Verdana;\">"+keywords[myKeywords[i][j]].name+"</a> - ";}
			display_tags=true;		 
   }
		//str_info+='</div>';
		}}
	}
	str_info_tags+="</div>";
	str_info_tags+="</div>";
	if(display_tags){
	    str_info+=str_info_tags;
}
	str_info+='<div><a href="#" onClick="javascript:networks['+myIndex+'].moreInfo(\'affinities\');" class=\"more_info capitalize\"><img src="'+gan_img_root+'arrow_infobox.png" alt="More info" title="More info"> More info</a></div>';
    document.getElementById("gan_infos_context").style.borderWidth='2px';
    document.getElementById("gan_infos_context").style.borderColor='#43aa1d';
    document.getElementById("gan_infos_context").style.borderStyle='solid';
    }
    if(this.className=='artwork'){
	str_attached='';
	gan_inInfobox=this.pluralClassName+"_"+this.id;
	giveFocus();
	str_info+="<div class=\"infobox_title\">"+this.name+"</div>";
	var myIndex=this.getIndexVal();
	var strPeople='<div class="infobox_keywords"> By ';
	var isPeople=false;
	for(var m=0;m<people.length;m++){
	    for(var n=0;n<people[m].artworks.length;n++){
		if(people[m].artworks[n]==myIndex){
		    strPeople+=people[m].firstname+' '+people[m].name+' ';
		    //debug_log(strPeople);
		    isPeople=true;
		}
	    }
	}
	strPeople+='</div>';
	if(isPeople){
	    str_info+=strPeople;
	}
	if(this.image.length>0){
	    str_info+='<div class="infobox_sub"><img src="'+gan_root+'/images/display/160/*/resize/'+this.image+'"></div>';

	}
	str_info+="<div>";
	var arCities=new Array();
	//debug_log(this.cities+" - "+this.citiesType+" - "+cities.length);
	for(var i=0;i<this.cities.length;i++){
	    if(!arCities[this.citiesType[i]]){
		arCities[this.citiesType[i]]=new Array();
	    }
	    arCities[this.citiesType[i]].push(cities[this.cities[i]].name);
	}
	if(arCities[gan_origin]){
	    str_info+='<div class="infobox_sub">City of origin</div>';
	    for(var j=0;j<arCities[gan_origin].length;j++){
		str_info+=arCities[gan_origin][j];
		if(j<(arCities[gan_origin].length)-1){
		    str_info+=', ';
		}
	    }
	}
	if(arCities[gan_residence]){
	    str_info+='<div class="infobox_sub">City of residence</div>';
	    for(var j=0;j<arCities[gan_residence].length;j++){
		str_info+=arCities[gan_residence][j];
		if(j<(arCities[gan_residence].length)-1){
		    str_info+=', ';
		}
	    }
	}
	if(arCities[gan_creation]){
	    str_info+='<div class="infobox_sub">Place(s)</div>';
	    for(var j=0;j<arCities[gan_creation].length;j++){
		str_info+=arCities[gan_creation][j];
		if(j<(arCities[gan_creation].length)-1){
		    str_info+=', ';
		}
	    }
	}

	if(this.urls.length>0){
	    str_info+='<div class="infobox_sub">Urls</div>';
	    str_info+='<div class="infobox_keywords">';

	    for(var j=0;j<this.urls.length;j++){
		str_info+='<a href="'+this.urls[j].uri+'" target="_blank" class="infobox_link">'+this.urls[j].title+'</a>';
		if(j<(this.urls.length)-1){
		    str_info+=', ';
		}
	    }}
	str_info+='</div>';
	var myKeywords;
	myKeywords=this.getKeywords();
	var display_media=false;
	var str_media='';
	if(myKeywords[1].length>0){
	    display_media=true;
	    str_media+='<div class="infobox_sub">media</div>';
	    str_media+='<div class="infobox_keywords">';
	    for(var i=0;i<myKeywords[1].length;i++){
		str_media+=keywords[myKeywords[1][i]].name;
		if(i<(myKeywords[1].length-1)){
		    str_media+=', ';
		}
	    }
	    str_media+='</div>';
	}
	if(display_media){
	    str_info+=str_media;
	}
	var display_tags=false;
	var str_info_tags='';
	str_info_tags+='<div class="infobox_sub">tags</div>';
	str_info_tags+='<div class="infobox_keywords">';
	//debug_log(myKeywords.length);
	for(var i=2;i<myKeywords.length;i++){
	    //debug_log(myKeywords[i].length);
	    if(myKeywords[i].length>0){
		//str_info+='<div class="infobox_keywords"><!--<span>'+galaxies[i].name+'</span>-->';
		for(var j=0;j<myKeywords[i].length;j++){
		    var dd_id=getDropDownIndex(galaxies[i].name);
		    if(!inArray(keywords[myKeywords[i][j]].name,galaxies[i].slug)){

			if(galaxies[i]!=current_galaxy){
			    str_info_tags+=" <a href=\"#\" id=\"xkwl_"+keywords[myKeywords[i][j]].id+"\" onClick=\"javascript:darkNight();current_galaxy=galaxies["+i+"];current_galaxy.mark();toggleImg('"+galaxies[i].name+"');gan_dropdowns["+dd_id+"].forceMenu();current_galaxy.loadKeywords();artworks["+myIndex+"].displayInfobox();keywords["+myKeywords[i][j]+"].flourish(true);\" class=\"infobox_link\" style=\"font-family:Nimbus,Geneva, Helvetica,Verdana;\">"+keywords[myKeywords[i][j]].name+"</a> - ";}else{
			    str_info_tags+=" <a href=\"#\" id=\"xkwl_"+keywords[myKeywords[i][j]].id+"\" onClick=\"javascript:gan_dropdowns["+dd_id+"].forceMenu();keywords["+myKeywords[i][j]+"].flourish(true);forceImg('"+galaxies[i].name+"');\" class=\"infobox_link\" style=\"font-family:Nimbus,Geneva, Helvetica,Verdana;\">"+keywords[myKeywords[i][j]].name+"</a> - ";}
			display_tags=true;		 
	
		    }}
		//str_info+='</div>';
	    }
	}
	str_info_tags+="</div>";
	str_info_tags+="</div>";
	if(display_tags){
	    str_info+=str_info_tags;
	}
	str_info+='<div><a href="#" onClick="javascript:artworks['+myIndex+'].moreInfo(\'affinities\');" class=\"more_info capitalize\"><img src="'+gan_img_root+'arrow_infobox.png" alt="More info" title="More info"> More info</a></div>';
	document.getElementById("gan_infos_context").style.borderWidth='2px';
	document.getElementById("gan_infos_context").style.borderColor='#ff3f00';
	document.getElementById("gan_infos_context").style.borderStyle='solid';



    }
    document.getElementById("gan_infos_context").innerHTML=str_info;
    document.getElementById("gan_infos_context").style.visibility='visible';
    if(str_attached.length>0){
    document.getElementById("gan_infos_context_more").innerHTML=str_attached;
    document.getElementById("gan_infos_context_more").style.visibility='visible';}else{
    document.getElementById("gan_infos_context_more").innerHTML='';
    document.getElementById("gan_infos_context_more").style.visibility='hidden';
}

}
function emptyInfobox(){
	gan_inInfobox='';
	releaseFocus();
	document.getElementById("gan_infos_context").innerHTML='';
	document.getElementById("gan_infos_context").style.visibility='hidden';
	document.getElementById("gan_infos_context_more").innerHTML='';
	document.getElementById("gan_infos_context_more").style.visibility='hidden';
}
function toInfoBox(id, theClass){
    if(theClass=='person'){
	//debug_log(id);
	var id_val=getPersonById(id);
	darkNight();
	people[id_val].displayInfobox();
	offMenu();
	hideDropDowns();
}
    if(theClass=='network'){
	var id_val=getNetworkById(id);
	darkNight();
	try{
	    networks[id_val].displayInfobox();
	    }catch(err){
	    displayDisclaimer();
        }
	offMenu();
	hideDropDowns();
}
    if(theClass=='artwork'){
	var id_val=getArtworkById(id);
	darkNight();
	artworks[id_val].displayInfobox();
	offMenu();
	hideDropDowns();
}

}
function displayKeyword(){
	if(this.className=='galaxy'){

}

}
function hideKeyword(){
	if(this.className=='galaxy'){

}

}
function registerSideSpots(thePolygan,theKeyword,theStyle,theKind){
	if(this.className=='galaxy'){

		if(theKind=="artworks"){
			var city_polygan=cities[thePolygan];
			var city_theKind=city_polygan.artworks;
			var keyword_theKind=keywords[theKeyword].artworks;
			var arKind=artworks;
		}else if(theKind=="networks"){
			var city_polygan=cities[thePolygan];
			var city_theKind=city_polygan.networks;
			var keyword_theKind=keywords[theKeyword].networks;
			var arKind=networks;
        }else if(theKind=="people"){
			var city_polygan=cities[thePolygan];
			var city_theKind=city_polygan.people;
			var keyword_theKind=keywords[theKeyword].people;
			var arKind=people;
        }
		var forAnemone=new Array();
		var theKinds=new Array();
		var theIdxs=new Array();

		if(city_theKind){
			for(k=0;k<city_theKind.length;k++){
				if(keyword_theKind){

					if(inArray(city_theKind[k],keyword_theKind)){
						forAnemone.push(city_theKind[k]);
						theKinds.push(arKind[city_theKind[k]].name);
						theIdxs.push(city_theKind[k]);

					}}
			}}
		if(forAnemone.length>0){

			sS=new sideSpot(theKeyword,city_polygan.lon,city_polygan.lat);
			sS.plantPopups(forAnemone,theKinds,theStyle,theKind,theIdxs);
			keywords[theKeyword].sideSpots.push(sS);
		}
	}
}

function registerActiveSpots(thePolygan,theStyle,theKind,theIcon,theStyleConnector){
	if(this.className=='galaxy'){
		if(theKind=="artworks"){
			var city_polygan=cities[parseInt(thePolygan)];
			var city_theKind=city_polygan.artworks;
			var galaxy_theKind=this.artworks;
			var arKind=artworks;
		}else if(theKind=="networks"){
			var city_polygan=cities[parseInt(thePolygan)];
			var city_theKind=city_polygan.networks;
			var galaxy_theKind=this.networks;
			var arKind=networks;
        }else if(theKind=="people"){
			var city_polygan=cities[parseInt(thePolygan)];
			var city_theKind=city_polygan.people;
			var galaxy_theKind=this.people;
			var arKind=people;
        }
			var forAnemone=new Array();
			var theKinds=new Array();
			var theIdxs=new Array();
			if(galaxy_theKind){
            if(city_theKind){
				var dupesAns=new Array();
			if(city_theKind.length>0){
				
				for(var j=0;j<city_theKind.length;j++){
					if((!inArray(city_theKind[j],dupesAns))&&(inArray(city_theKind[j],galaxy_theKind))){
						theIdxs.push(city_theKind[j]);
						theKinds.push(arKind[city_theKind[j]].name);
						forAnemone.push(city_theKind[j]);
						dupesAns.push(city_theKind[j]);
						//alert(forAnemone);
					}

}
				//alert(aaS);
			if(forAnemone.length>0){
				var anS=new activeSpot(city_polygan.lon,city_polygan.lat,theStyle,theIcon.clone());
				anS.mark();
				anS.plantPopups(forAnemone,theKinds,theStyleConnector,theKind,theIdxs);
				//debug_log(theNetworks);
				this.activeSpots.push(anS);
				//debug_log('Adding anS to activeSpot list total as: '+this.activeSpots.length);
}
			
			}}}
	}
}

function registerSession(){}
function unregisterSession(){
	//not sure what to do with this
	current_features=new Array();
	current_markers=new Array();
	current_popups=new Array();
	current_keywords=new Array();
	current_galaxy='';
}
function getIndexVal(){
	if(this.className=='person'){
		var indexVal;
			for(var i=0;i<people.length;i++){
				if(people[i].id==this.id){
					indexVal=i;
					break;
}
			}
			return indexVal;
	}
	if(this.className=='network'){
		var indexVal;
			for(var i=0;i<networks.length;i++){
				if(networks[i].id==this.id){
					indexVal=i;
					break;
}
			}
			return indexVal;
	}
	if(this.className=='artwork'){
		var indexVal;
			for(var i=0;i<artworks.length;i++){
				if(artworks[i].id==this.id){
					indexVal=i;
					break;
}
			}
			return indexVal;
	}
}
function getKeywords(){
	if(this.className=='person'){
		var ar_out=new Array();
		//debug_log('Entering getKeywords');
		var myIndex=this.getIndexVal();
		//debug_log(myIndex);
		for(var i=0;i<galaxies.length;i++){
			ar_out[i]=new Array();
			if(galaxies[i].polygan){
			if(galaxies[i].people){
				//debug_log(galaxies[i].people.length);
				if(inArray(myIndex,galaxies[i].people)){
					if(galaxies[i].keywords){
						for(var j=0;j<galaxies[i].keywords.length;j++){
							if(keywords[galaxies[i].keywords[j]].people){
							if(inArray(myIndex,keywords[galaxies[i].keywords[j]].people)){
								ar_out[i].push(galaxies[i].keywords[j]);
							}}
						}
					}}
			}}

		}
		return ar_out;
	}
	if(this.className=='network'){
		var ar_out=new Array();
		//debug_log('Entering getKeywords');
		var myIndex=this.getIndexVal();
		//debug_log(myIndex);
		for(var i=0;i<galaxies.length;i++){
			ar_out[i]=new Array();
			if(galaxies[i].polygan){
			if(galaxies[i].networks){
				//debug_log(galaxies[i].people.length);
				if(inArray(myIndex,galaxies[i].networks)){
					if(galaxies[i].keywords){
						for(var j=0;j<galaxies[i].keywords.length;j++){
							if(keywords[galaxies[i].keywords[j]].networks){
							if(inArray(myIndex,keywords[galaxies[i].keywords[j]].networks)){
								ar_out[i].push(galaxies[i].keywords[j]);
							}}
						}
					}}
			}}

		}
		return ar_out;
	}
	if(this.className=='artwork'){
		var ar_out=new Array();
		//debug_log('Entering getKeywords');
		var myIndex=this.getIndexVal();
		//debug_log(myIndex);
		for(var i=0;i<galaxies.length;i++){
			ar_out[i]=new Array();
			if(galaxies[i].polygan){
			if(galaxies[i].artworks){
				//debug_log(galaxies[i].people.length);
				if(inArray(myIndex,galaxies[i].artworks)){
					if(galaxies[i].keywords){
						for(var j=0;j<galaxies[i].keywords.length;j++){
							if(keywords[galaxies[i].keywords[j]].artworks){
							if(inArray(myIndex,keywords[galaxies[i].keywords[j]].artworks)){
								ar_out[i].push(galaxies[i].keywords[j]);
							}}
						}
					}}
			}}

		}
		return ar_out;
	}
}
function connectTheDots(){}
function mousedown(){
	//alert('Mousedown on '+this.id);
	current_galaxy.removeSidePopups();
	emptyInfobox();
	for(var i=0;i<current_galaxy.activeSpots.length;i++){
		if(current_galaxy.activeSpots[i].marker){
		if(current_galaxy.activeSpots[i].marker.id==this.id){
			//alert(current_galaxy.activeSpots[i].marker.icon);
			if(!current_galaxy.activeSpots[i].deployed){
				//debug_log('call to grow popup')
			current_galaxy.activeSpots[i].growPopups();
			break;}else{
			current_galaxy.activeSpots[i].removePopups();

}
		}}
}
}
//interface methods
function preform(){
	if(this.className=='ganDropDownMenu'){
		document.getElementById(this.layer_id).style.width="400px";
		document.getElementById(this.layer_id).style.background="rgb(32,32,29)";

		if(this.direction=='west'){
			//debug_log("west "+this.x+" "+this.y);
			document.getElementById(this.layer_id).style.top=this.x;
			document.getElementById(this.layer_id).style.left=this.y+10;
			document.getElementById(this.layer_id+'_pointer_left').style.top=(this.x)-7+'px';
			document.getElementById(this.layer_id+'_pointer_left').style.left=this.y+10;
			this.ta="left";
		}else{
		    //debug_log("east "+this.x+" "+this.y);
		    document.getElementById(this.layer_id).style.top=this.x;
		    if(the_browser=='msie'){
			document.getElementById(this.layer_id).style.left=this.y-368;

		    }else{
			document.getElementById(this.layer_id).style.left=this.y-410;
		    }
		    document.getElementById(this.layer_id+'_pointer_right').style.top=(this.x)-7;
		    document.getElementById(this.layer_id+'_pointer_right').style.left=this.y-3;
		    this.ta="right";



		}

	}
}

function forceMenu(){
	if(this.className=='ganDropDownMenu'){
		if(this.visibility=='hidden'){
			this.showHide();
}}
}
function showHide(){
	if(this.className=='ganDropDownMenu'){
		if(this.visibility=='hidden'){
			if(current_dropdown!=''){
			    //debug_log(current_dropdown.visibility);
				current_dropdown.showHide();

}
			var str_slug='';
			var str_menu='';
			for(var g=0;g<galaxies[this.galaxy].slug.length;g++){
			    var inside=false;
			    for(gg=0;gg<this.activeKeywords.length;gg++){
				if(galaxies[this.galaxy].slug[g]==keywords[this.activeKeywords[gg]].name){
				    str_slug+="<a href=\"#\" id=\"kwl_"+keywords[this.activeKeywords[gg]].id+"\" onClick=\"javascript:keywords[current_galaxy.keywords["+gg+"]].flourish();\" class=\"menu_cap_link\">"+keywords[this.activeKeywords[gg]].name+"</a>";
				    inside=true;
}
}
			    if(!inside){
				    str_slug+="<a href=\"#\" class=\"menu_cap_link\">"+galaxies[this.galaxy].slug[g]+"</a>";
}

				if(g<((galaxies[this.galaxy].slug.length)-1)){
				    str_slug+=' / ';
					
				}
}
			//debug_log(galaxies[this.galaxy].slug.length+' '+galaxies[this.galaxy].slug);
			for(var i=0;i<this.activeKeywords.length;i++){
			    //fetches the slug array for this category
			    if(inArray(keywords[this.activeKeywords[i]].name,galaxies[this.galaxy].slug)){
			    }else{
				str_menu+="<a href=\"#\" id=\"kwl_"+keywords[this.activeKeywords[i]].id+"\" onClick=\"javascript:keywords[current_galaxy.keywords["+i+"]].flourish();\" class=\"menu_link\">"+keywords[this.activeKeywords[i]].name+"</a>";
				if(i<(this.activeKeywords.length)-1){
				    str_menu+=' - ';
				}
			    }

				

			}
			document.getElementById(this.layer_id).innerHTML=str_slug;
			document.getElementById(this.layer_id).style.visibility="visible";
			document.getElementById('galaxy_thumb').style.display="block";
			fetchGalaxyDisplay(galaxies[this.galaxy].id,'galaxy_thumb');


			this.visibility='visible';
			if(this.ta=='left'){
			    document.getElementById(this.layer_id+'_pointer_left').style.visibility="visible";
			}else if(this.ta=='right'){
			    document.getElementById(this.layer_id+'_pointer_right').style.visibility="visible";

			}
			//debug_log('showing');
			current_dropdown=this;
		}else{
		    //debug_log('hiding');
			document.getElementById(this.layer_id).style.visibility="hidden";
			if(this.ta=='left'){
			    document.getElementById(this.layer_id+'_pointer_left').style.visibility="hidden";
			}else if(this.ta=='right'){
			    document.getElementById(this.layer_id+'_pointer_right').style.visibility="hidden";

			}
			this.visibility='hidden';
			//fetchGalaxyDisplay(0,'galaxy_thumb');
			if(current_dropdown!=''){
				current_dropdown='';
}
}
}
}
function hideGalaxyThumb(){
    document.getElementById('galaxy_thumb').style.display="none";
}
function hideDropDowns(){
   if(current_dropdown!=''){
       current_dropdown='';
			}
   for(var i=0;i<gan_dropdowns.length;i++){
       /*changed 22/10/2009*/
			document.getElementById(gan_dropdowns[i].layer_id).style.visibility="hidden";
			document.getElementById(gan_dropdowns[i].layer_id+'_pointer_right').style.visibility="hidden";
			document.getElementById(gan_dropdowns[i].layer_id+'_pointer_left').style.visibility="hidden";
			gan_dropdowns[i].visibility='hidden';
}
}
function moreInfo(selectedIn){
    var id_to;
    if(this.className=='person'){
	id_to=getPersonById(this.id);
    }else if(this.className=='network'){
	id_to=getNetworkById(this.id);

    }else{
	id_to=getArtworkById(this.id);

    }
    var str_div;
    str_div='<div id="enclose_topbar">';
    var theTabs=moreInfoTabs(this.pluralClassName,id_to,selectedIn);
    str_div+=theTabs;
    str_div+='<div class="topbar"><a href="#" onClick="javascript:document.getElementById(\'more_info\').style.visibility=\'hidden\'"><img src="'+gan_img_root+'close.png" title="close the window"></a></div></div><div style="clear:both"></div>';
    //str_div+='<div class="moreinfo_title" style="clear:all;">Affinities for '+this.firstname+' '+this.name+"</div>";
    //		str_div+='<br />'+this.firstname+' '+this.name+' shares more than one keyword with the following people: ';
    document.getElementById('search_results').style.visibility="hidden";
    str_waiting="Loading information ...";
    document.getElementById('more_info_title').innerHTML=str_div;
    document.getElementById('more_info_content').innerHTML=str_waiting;
    document.getElementById('more_info').style.visibility="visible";
    this.fetchAffinities(selectedIn);
    //}
}

function moreInfoTabs(type_in,id_in,selected_in){
    if(the_browser=='msie'){
	var menuTab='<div id="menu_tab" class="menu_tab_ie">';
    }else{
	var menuTab='<div id="menu_tab" class="menu_tab">';
    }
    var tabElements=new Array();
    var tabClass='';

    //if(type_in=='person'){

    tabElements[0]='affinities';
    tabElements[1]='people';
    tabElements[2]='networks';
    tabElements[3]='artworks';
    var index_sel;
    for(var e=0;e<tabElements.length;e++){
	if(tabElements[e]==selected_in){
	    index_sel=e;
	    break;
	}}
    for(var ee=0;ee<tabElements.length;ee++){

	if(ee==index_sel){
	    tabClass='tab_on';
	}else if(ee==(index_sel-1)){
	    tabClass='tab_off_pre';
	}else{
	    tabClass='tab_off';

	}
	menuTab+='<span class="'+tabClass+'"><a href="javascript:'+type_in+'['+id_in+'].moreInfo(\''+tabElements[ee]+'\');">'+tabElements[ee]+'</a></span>';
    }
	    
	

    //}
    menuTab+='</div>';
    return menuTab;
}

function fetchArticle(id_in,target_in){
	    var url=gan_root+'articles/summaryblock/'+id_in;
            //debug_log('fetching '+url);
	    var responseObj = new OpenLayers.Ajax.Request(url,{method: 'get', onSuccess: function(transport) { insertStatus('Loading article');}, onComplete: function(transport) {insertArticleBlock(transport.responseText,target_in); }});
}

function fetchAffinities(selected_in){
	if(this.className=='person'){
	    var url=gan_root+'people/moreinfo/'+this.id+'/sel:'+selected_in;
	    //debug_log(url);
	    var responseObj = new OpenLayers.Ajax.Request(url,{method: 'get', onSuccess: function(transport) { insertStatus('Loading affinities');}, onComplete: function(transport) {insertMoreInfo(transport.responseText); }});
	}
	if(this.className=='network'){
	    var url=gan_root+'networks/moreinfo/'+this.id+'/sel:'+selected_in;
	    //debug_log(url);
	    var responseObj = new OpenLayers.Ajax.Request(url,{method: 'get', onSuccess: function(transport) { insertStatus('Loading affinities');}, onComplete: function(transport) {insertMoreInfo(transport.responseText); }});
	}
	if(this.className=='artwork'){
	    var url=gan_root+'artworks/moreinfo/'+this.id+'/sel:'+selected_in;
	    //debug_log(url);
	    var responseObj = new OpenLayers.Ajax.Request(url,{method: 'get', onSuccess: function(transport) { insertStatus('Loading affinities');}, onComplete: function(transport) {insertMoreInfo(transport.responseText); }});
	}
}
function fetchGalaxyDisplay(id_in,target_in){
	    var url=gan_root+'maps/displaygalaxy/'+id_in;
	    document.getElementById(target_in).style.visibility='visible';
            //debug_log('fetching '+url);
	    var responseObj = new OpenLayers.Ajax.Request(url,{method: 'get', onSuccess: function(transport) { insertStatus('Loading article');}, onComplete: function(transport) {insertArticleBlock(transport.responseText,target_in); }});
}
function displayDisclaimer(){
    //debug_log('display disclaimer');
    emptyInfobox();
    document.getElementById('gan_infos_context').innerHTML="This network is in orbit. It is not  anchored to a city. We are still looking for a view to display it in the map. A little patience.";
    document.getElementById('galaxy_thumb').style.display="none";
    document.getElementById('gan_infos_context').style.visibility="visible";
    document.getElementById("gan_infos_context").style.borderWidth='2px';
    document.getElementById("gan_infos_context").style.borderColor='#43aa1d';
    document.getElementById("gan_infos_context").style.borderStyle='solid';
}
function searchAll1(){
    debug_log('searchAll');
}
function searchAll(){
    var str_div;
    str_div='<div id="enclose_topbar">';
    str_div+='<div class="topbar" style="clear:all;"><a href="#" onClick="javascript:document.getElementById(\'search_results\').style.visibility=\'hidden\'"><img src="'+gan_img_root+'close.png" title="close the window"></a></div></div><div style="clear:both"></div>';
    //str_div+='<div class="moreinfo_title" style="clear:all;">Affinities for '+this.firstname+' '+this.name+"</div>";
    //		str_div+='<br />'+this.firstname+' '+this.name+' shares more than one keyword with the following people: ';
    document.getElementById('more_info').style.visibility="hidden";
    str_waiting="Loading information ...";
    document.getElementById('search_results_keywords').innerHTML='';
    document.getElementById('search_results_people').innerHTML='';
    document.getElementById('search_results_networks').innerHTML='';
    document.getElementById('search_results_artworks').innerHTML='';
    document.getElementById('search_results_title').innerHTML=str_div;
    document.getElementById('search_results_waiting').innerHTML=str_waiting;
    document.getElementById('search_results').style.visibility="visible";
    if(document.getElementById('search').value.length>3){
	//debug_log('fetching '+url);
	var url=gan_root+'keywords/search/'+encodeURI(document.getElementById('search').value);
	var responseObj_keywords = new OpenLayers.Ajax.Request(url,{method: 'get', onSuccess: function(transport) { insertStatus('Loading article');}, onComplete: function(transport) {insertSearchResults(transport.responseText,'keywords'); }});
	var url=gan_root+'people/search/'+encodeURI(document.getElementById('search').value);
	var responseObj_people = new OpenLayers.Ajax.Request(url,{method: 'get', onSuccess: function(transport) { insertStatus('Loading article');}, onComplete: function(transport) {insertSearchResults(transport.responseText,'people'); }});
	//insertMoreInfo(searchResults);
	var url=gan_root+'networks/search/'+encodeURI(document.getElementById('search').value);
	var responseObj_networks = new OpenLayers.Ajax.Request(url,{method: 'get', onSuccess: function(transport) { insertStatus('Loading article');}, onComplete: function(transport) {insertSearchResults(transport.responseText,'networks'); }}); 
	var url=gan_root+'artworks/search/'+encodeURI(document.getElementById('search').value);   
	var responseObj_artworks = new OpenLayers.Ajax.Request(url,{method: 'get', onSuccess: function(transport) { insertStatus('Loading article');}, onComplete: function(transport) {insertSearchResults(transport.responseText,'artworks'); }});
    }else{
	document.getElementById('search_results_waiting').innerHTML='Please enter a search term longer than three letters.';

    }
}
function insertSearchResults(str_in,target_in){
    //debug_log('called with param '+sr);
    var targetResults='search_results_'+target_in;
    searchResultsContent="<div class=\"alert\">"+str_in+"</div>";
    document.getElementById(targetResults).innerHTML=searchResultsContent;
    if(target_in=='artworks'){
    document.getElementById('search_results_waiting').innerHTML='';

}

}
function insertStatus(str){
    return;
}
function insertMoreInfo(str){
    //debug_log(str);

    //var cnt=document.getElementById('more_info').innerHTML;
    var cnt_augmented="<div class=\"alert\">"+str+"</div>";
    document.getElementById('more_info_content').innerHTML=cnt_augmented;
}
function insertArticleBlock(str_in,target_in){
    //debug_log(str);

    //var cnt=document.getElementById('more_info').innerHTML;
    var str_article_block=str_in;
    document.getElementById(target_in).innerHTML=str_article_block;
}
//enumerations - listings
function getDropDownIndex(name_in){
	var dd_id;
	for(var i=0;i<gan_dropdown_labels.length;i++){

		if(gan_dropdown_labels[i]==name_in){
			dd_id=i;
			break;
}}
	return dd_id;
}
function getPersonById(id_in){
		var indexVal;
			for(var i=0;i<people.length;i++){
				if(people[i].id==id_in){
					indexVal=i;
					break;
				}
			}
			return indexVal;
	
}
function getNetworkById(id_in){
		var indexVal;
			for(var i=0;i<networks.length;i++){
				if(networks[i].id==id_in){
					indexVal=i;
					break;
				}
			}
			return indexVal;
	
}
function getArtworkById(id_in){
		var indexVal;
			for(var i=0;i<artworks.length;i++){
				if(artworks[i].id==id_in){
					indexVal=i;
					break;
				}
			}
			return indexVal;
	
}
function getGalaxyById(id_in){
		var indexVal;
			for(var i=0;i<galaxies.length;i++){
				if(galaxies[i].id==id_in){
					indexVal=i;
					break;
				}
			}
			return indexVal;
	
}
function getKeywordById(id_in){
		var indexVal;
			for(var i=0;i<keywords.length;i++){
				if(keywords[i].id==id_in){
					indexVal=i;
					break;
				}
			}
			return indexVal;
	
}
function getCitiesAnnexes(){
    if(map.zoom>2){
	var theCenter=map.getCenter();
	//debug_log('Zoom event detected. We are now at zoom level '+map.zoom+' the center is at lon '+theCenter.lon+' lat '+theCenter.lat);
	anounceAnnexes();
    }else{
      hideAnnexes();

}
}
function anounceAnnexes(){
    var theCenter=map.getCenter();
    var show='off';
    var str_out='';
    var str_diff='';
    var aPrep=new Array();
    var aSel=new Array();
    var strAnounce='';
    for(var i=0;i<annexes.length;i++){
	for(var j=0;j<annexes[i].citiesLon.length;j++){
	    var difflon=gan_compare(theCenter.lon,annexes[i].citiesLon[j]);
	    var difflat=gan_compare(theCenter.lat,annexes[i].citiesLat[j]);
	    str_diff+=annexes[i].title+' '+difflon+' '+difflat+"\n";

	    if((map.zoom>2)&&(difflon<3)&&(difflat<3)){
		if(!inArray(annexes[i].id,aPrep)){
		    //debug_log(annexes[i].title);
		    aPrep.push(annexes[i].id);
		    aSel.push(annexes[i]);
		}
		show='on';
		//str_out+=annexes[i].title;
	    }
	}


    }
    if(aSel.length>0){
	strAnounce+='<a href="#" onClick="javascript:displayAnnexes();">See the annexes related to this view</a> ('+aSel.length+')';
        document.getElementById('gan_annex').innerHTML=strAnounce;
	document.getElementById('gan_annex').style.visibility='visible';
    }else{
      hideAnnexes();

}}
function displayAnnexes(){
	var theCenter=map.getCenter();
	var show='off';
	var str_out='';
	var str_diff='';
	var aPrep=new Array();
	var aSel=new Array();
    for(var i=0;i<annexes.length;i++){
	for(var j=0;j<annexes[i].citiesLon.length;j++){
	    var difflon=gan_compare(theCenter.lon,annexes[i].citiesLon[j]);
	    var difflat=gan_compare(theCenter.lat,annexes[i].citiesLat[j]);
	    str_diff+=annexes[i].title+' '+difflon+' '+difflat+"\n";

	    if((map.zoom>2)&&(difflon<3)&&(difflat<3)){
		if(!inArray(annexes[i].id,aPrep)){
		    //debug_log(annexes[i].title);
		    aPrep.push(annexes[i].id);
		    aSel.push(annexes[i]);
}
		show='on';
		//str_out+=annexes[i].title;
}
}
    }

   if(aSel.length>0){
    var str_out;
    str_out='<div id="enclose_topbar">';
    str_out+='<div class="topbar" style="clear:all;"><a href="#" onClick="javascript:document.getElementById(\'gan_annexes\').style.visibility=\'hidden\'"><img src="'+gan_img_root+'close.png" title="close the window"></a></div></div><div style="clear:both"></div></div>';
    str_out+='<div class="annexcontent">';
       for(var i=0;i<aSel.length;i++){
	   str_out+="<div class=\"boxannex\">";
	   str_out+='<div>'+aSel[i].title+'</div>';
	   //str_info+='<div class="infobox_sub"><img src="'+gan_root+'/images/display/160/*/resize/'+this.image+'"></div>';
	   str_out+='<div><a href="'+aSel[i].url+'" target="_blank"><img src="'+gan_root+'/images/display/200/*/resize/'+aSel[i].image+'"></a></div>';
	   str_out+="</div>";


}
       str_out+='</div>';
		document.getElementById('gan_annexes').innerHTML=str_out;
		document.getElementById('gan_annexes').style.visibility='visible';}
   else{
      hideAnnexes();
   }
   //debug_log(str_diff);
}
function hideAnnexes(){
    document.getElementById('gan_annex').innerHTML='';
    document.getElementById('gan_annex').style.visibility='hidden';
}
function ajaxTest(){
	var url='micropoint';
	var responseObj = new OpenLayers.Ajax.Request(url,{method: 'get', onSuccess: function(transport) { alert('Successful Connection');}, onComplete: function(transport) {alert(transport.responseText); }});
}