// Giotto.js



//use different css
if (navigator.appName == "Netscape") {
//	document.getElementById("css").href="giomoz.css";	//giottoMoz.css	
}


function leaveSite(whichSite) {
	var winFeatures = "location=yes, menubar=yes, resizable=yes, scrollbars=yes, status=yes ,toolbar=yes";
	var newdoc = document.open(whichSite, "newwind", winFeatures);
	newdoc.focus();
}

/* 
For Microsoft explorer 5:
activate a certain styleSheet name:title and deactivate all other ones 
(name a persistent style sheet with rel="StyleSheet" and no title,
name the preferred style with rel="Styleshhet" title="recommanded",
name the alternate with rel="Alternate stylesheet" title="alternate for Microsoft")
*/
function setActiveStyleSheet(title) {
   var i, styleSh, main;
   for(i=0; (styleSh = document.getElementsByTagName("link")[i]); i++) {
		//for each <LINK found
     	if(styleSh.getAttribute("rel").indexOf("style") != -1) {  //<LINK REL="styleSheet"
			styleSh.disabled = true;
       		if(styleSh.getAttribute("title") == title) styleSh.disabled = false;
     	}
   }
}



/*  pop a block for About: create a block and add/remove it to/from the html
*/
function AboutBlock() {
		this.child = "divNode";
		this.parent = "about";
		this.contact = "img/about.jpg"; 
		this.bgColor = "background-color: #101225; ";
		this.position = "position: absolute; left: 280px; top: -120px; width:200px; height:90px; ";
		this.border = "border: 1px solid olive; margin: 2px; padding: 2px;";				
		this.imgcss = "display: block; position: relative; border: 0px; margin: 0px";				
		this.css = this.position + this.bgColor + this.border; 
		this.about = document.getElementById(this.parent);
				
		this.showIE = function showIE() {			
			this.divNode = document.createElement('div');
			//this.divNode.setAttribute('style', this.css);
			this.divNode.setAttribute('name', this.child);
			this.divNode.setAttribute('id', this.child);		
			this.divNode.style.width=200; //size of img
			this.divNode.style.height=90;
			this.divNode.style.border=1;
			this.divNode.style.borderColor="olive";
			this.divNode.style.borderStyle= "solid";
			var imgNode = document.createElement('img');
			imgNode.setAttribute('style', this.imgcss);
			imgNode.setAttribute('src', this.contact);							
			this.divNode.appendChild(imgNode);
			//add block to existing elt
			this.about.appendChild(this.divNode);			
			//adjust block style
			var leftVal = 280; 
			var topVal = - 100;			
			this.divNode.style.position = "absolute";
			this.divNode.style.left= leftVal;
			this.divNode.style.top= topVal;
		} 
		this.show = function show() {
			this.css = this.position + this.bgColor + this.border;
			this.divNode = document.createElement('div');
			this.divNode.setAttribute('style', this.css);
			this.divNode.setAttribute('name', this.child);
			this.divNode.setAttribute('id', this.child);
			var imgNode = document.createElement('img');
			imgNode.setAttribute('style', this.imgcss);
			imgNode.setAttribute('src', this.contact);				
			
			this.divNode.appendChild(imgNode);							
			this.about.appendChild(this.divNode);	
		}
		
		this.hide = function hide() {			
			var parentNode = document.getElementById(this.parent);
			var childNode = document.getElementById(this.child);			
			parentNode.removeChild(childNode);
		}
}
//AboutBlock.divNode = undefined;//static

function hideAbout() {
	var about = new AboutBlock();
	about.hide();
}

function showAbout() {
	var about = new AboutBlock();
	if (navigator.appName == "Netscape") {
		about.show();
	} else {
		about.showIE();	
	}
} 


// -------------------------------------------------------------
/* get information from server using AJAX */
// -------------------------------------------------------------

function getInformation(subject) {
	//format querystring
	var aPage = "/sc/getInformation.php?subject="+ subject;
	//send ajax request
	ajaxRequest(aPage);
	return;
}


function getImage(subject) {
	var aPage = "/sc/getImage.php?subject="+ subject;
	ajaxImageRequest(aPage);
	return;
}


//After receiving the response
//tell the request what to do by giving the javascript method that willprocess the response
function getServerAjaxResponse() {
/*
#  0 (uninitialized)
# 1 (loading)
# 2 (loaded)
# 3 (interactive)
# 4 (complete)*/

	if (http_request.readyState == 4) {
    		// everything is good, the response is received
		//status code of request
		if (http_request.status == 200) {
			// perfect!
			setServerInformation(http_request.responseText);
			/* 
			- http_request.responseText  will return the server response as a string of text
			- http_request.responseXML  will return the response as an XMLDocument object you can traverse using the JavaScript DOM functions
			*/	
		} else {
			// there was a problem with the request,
			// for example the response may be a 404 (Not Found)
			// or 500 (Internal Server Error) response codes
             		alert('There was a problem retrieving more information for you.');
		}

	} 
	/* else if (http_request.readyState == 3) {
		alert("interactive");
	} else if (http_request.readyState == 2) {
		alert("loaded");
	} else if (http_request.readyState == 1) {
		alert("loading");
	} */
	else if (http_request.readyState == 0) {
		alert("uninitialized");
	}
	return;
}



//pass arg as responseText from ajax
function setServerInformation(data) {
	node = document.getElementById('moreInformation');
	if (node.style.display == "block") return;

	//reset div location
	node.style.top = '170px';
	var aWidth = '340';
	var aHeight = '330';
	if (document.all) {
		node.style.left = '264px';//IE is offset compared to Firefox
		node.style.posHeight = aHeight; 
		node.style.posWidth = aWidth;
	} else {
		node.style.height = aHeight +'px';
		node.style.width = aWidth +'px';
	}
	onclick="getImage('campanile');"
	node.innerHTML = data +"<BR/>";
	node.style.display = "block";
	//add close button
	nodeBtn = document.createElement('img');
	nodeBtn.src = 'img/moreInfoClose.jpg';
	nodeBtn.alt = 'close this window';
	nodeBtn.onclick = closeInfo;
	nodeBtn.title = 'close this window';
	nodeBtn.style.cursor = 'url("img/finger.gif"), pointer';
	node.appendChild(nodeBtn);
	if (document.all) {
		node.style.fontSize = '12px';
		node.style.position = 'inherit';
		var pos = parseInt(node.style.offsetWidth /2);
		nodeBtn.style.posLeft = pos;
		nodeBtn.cssText ='left: 100px; top:100px';
	} else {		
		nodeBtn.setAttribute("name", "closingBtn"); //node.nodeName 
		nodeBtn.setAttribute("id", nodeBtn.getAttribute("name"));
		nodeBtn.style.position = 'inherit';
	
		posX = node.offsetWidth/2 - (nodeBtn.offsetWidth/2);
		posY = node.offsetHeight - nodeBtn.offsetHeight - 10;
		leftPos = posX +'px';
		topPos = posY +'px';
		nodeBtn.style.left = leftPos;
		nodeBtn.style.top = topPos;
	}
	return;
}

//close the pop up created for ajax information
function closeInfo() {
	node = document.getElementById("moreInformation");
	node.style.display = "none";
	if (document.getElementById('closingBtn')) node.removeChild(document.getElementById('closingBtn'));
	return;
}



//After receiving the response
//tell the request what to do by giving the javascript method that willprocess the response
function getServerAjaxImageResponse() {
/*
#  0 (uninitialized)
# 1 (loading)
# 2 (loaded)
# 3 (interactive)
# 4 (complete)*/

	if (http_request.readyState == 4) {
    		// everything is good, the response is received
		if (http_request.status == 200) {
			// perfect!
			setImage(http_request.responseText);
		} else {
			// there was a problem with the request,
			// for example the response may be a 404 (Not Found)
			// or 500 (Internal Server Error) response codes
             		alert('There was a problem retrieving more information for you.');
		}
	} else if (http_request.readyState == 0) {
		alert("uninitialized");
	}
	return;
}


function setImage(anImg) {
	node = document.getElementById('moreInformation');
	if (node.style.display == "block") return;

	//modify div to handle large image
	node.style.top = '20px';
	var w = 'width'; var h = 'height';
	var pos1 = anImg.indexOf(w);
	if (pos1 < 0) return;
	var substr = anImg.substring(pos1 + w.length);
	var end = substr.indexOf(' ');
	if (end < 0) return;
	var aWidth = substr.substring(2, end -1);
	pos1 = anImg.indexOf(h);
	if (pos1 < 0) return;
	substr = anImg.substring(pos1 + h.length);
	var end = substr.indexOf(' ');
	if (end < 0) return;	

	var aHeight = substr.substring(2, end - 1);
	if (document.all) {
		node.style.posHeight = aHeight + 'px';
		node.style.posWidth = aWidth + 'px';
	} else {
		node.style.height = aHeight + 'px';
		node.style.width = aWidth + 'px';
	}

	node.innerHTML = anImg +"<BR/>";
	node.style.display = "block";
	//add close button
	nodeBtn = document.createElement('img');
	nodeBtn.src = 'img/moreInfoClose.jpg';
	nodeBtn.alt = 'close this window';
	nodeBtn.onclick = closeInfo;
	nodeBtn.title = 'close this window';
	nodeBtn.style.cursor = 'url("img/finger.gif"), pointer';
	node.appendChild(nodeBtn);
	if (document.all) {
		node.style.fontSize = '12px';
		var pos = parseInt(node.style.offsetWidth /2);
		nodeBtn.style.posLeft = pos;
		nodeBtn.cssText ='position: inherit; left: 100px; top:100px';
	} else {		
		nodeBtn.setAttribute("name", "closingBtn"); //node.nodeName 
		nodeBtn.setAttribute("id", nodeBtn.getAttribute("name"));
		nodeBtn.style.position = 'inherit';
	
		posX = node.offsetWidth/2 - (nodeBtn.offsetWidth/2);
		posY = node.offsetHeight - nodeBtn.offsetHeight - 10;
		leftPos = posX +'px';
		topPos = posY +'px';
		nodeBtn.style.left = leftPos;
		nodeBtn.style.top = topPos;
	}
	return;
}


