/*\------------------------------------------------------------------------

	>> globalenergy.gr
	>> 05/06/06				
	>> Kostis Sakkas				
		
------------------------------------------------------------------------\*/


window.onload	= function() {setFooter();emailCloak();}
window.onresize	= function() {setFooter();}


/*\------------------------------------------------------------------------
	
	Opens new windows via rel="external"
	url : http://www.brucelawson.co.uk/index.php/2005/opening-links-in-new-windows-in-xhtml-strict/
	
------------------------------------------------------------------------\*/

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors .length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
			anchor.title = (anchor.title != "") ? anchor.title+" (Ανοίγει σε νέο παράθυρο)" : "Ανοίγει σε νέο παράθυρο";
			anchor.className = (anchor.className != '') ? anchor.className+' external' : 'external';
		}
	}
}

/*\------------------------------------------------------------------------
	
	Visibility on/off
	
------------------------------------------------------------------------\*/

function toggle(id){
	el = document.getElementById(id);
	el.style.display = (el.style.display == 'none' || el.style.display == '') ? 'block' : 'none';
}


/*\------------------------------------------------------------------------
	
	Position footer div at the bottom of the page using DOM
	
	Source from the precious AListApart.com
	Article : Exploring Footers
	URL : http://www.alistapart.com/articles/footers/
	[changed the setFooter() a bit]

------------------------------------------------------------------------\*/

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
		
function setFooter() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var headerHeight  = document.getElementById('header').offsetHeight;
			var toolsHeight  = document.getElementById('tools').offsetHeight;
			var contentElement = document.getElementById('content');
			var contentHeight  = contentElement.offsetHeight;
			var footerHeight  = document.getElementById('footer').offsetHeight;
			var newHeight = windowHeight - (headerHeight + toolsHeight + footerHeight + 10);
			if (contentHeight < newHeight)
				contentElement.style.height =newHeight + 'px';
		}
	}
}


/*\------------------------------------------------------------------------
	
	Replaces email addresses with the title attr.
	credits : initial idea from http://www.badboy.ro/articles/2005-01-25/index.php
	
------------------------------------------------------------------------\*/

emailCloak = function() {
	if (document.getElementById) {
		var cloakDiv = document.getElementById("emailCloak");
		if (cloakDiv) {
			var oldText = cloakDiv.firstChild;
			var emailAddress = cloakDiv.firstChild.nodeValue;
			var user = emailAddress.substring(0, emailAddress.indexOf("("));
			var website = emailAddress.substring(emailAddress.indexOf(")")+1, emailAddress.length);
			var newText = cloakDiv.title;
			var emailText = user+"@"+website;
			var a = document.createElement("a");
			a.href = "mailto:"+emailText;
			var address = document.createTextNode(newText);
			a.appendChild(address);
			cloakDiv.replaceChild(a,oldText);
		}
	}
}