/*\------------------------------------------------------------------------

	>> talkingcure.gr
	>> 10/11/06				
	>> Kostis Sakkas				
		
------------------------------------------------------------------------\*/


window.onload	= function() {externalLinks();emailCloak();setFooter();}
window.onresize	= function() {}


/*\------------------------------------------------------------------------
	
	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) {
			if(document.getElementById('intro-container')){
				var introElement = document.getElementById('intro-container');
				var intorHeight  = introElement.offsetHeight;
				if (intorHeight < windowHeight)		
					introElement.style.height= windowHeight + 'px';
			}
			else{
				var containerElement  = document.getElementById('container');
				var containerHeight  = containerElement.offsetHeight;
			
				var footerElement = document.getElementById('footer');
				var footerHeight  = footerElement.offsetHeight;
				
				if (containerElement + footerHeight < windowHeight)			
					containerElement.style.height= windowHeight - (footerHeight - 10)  + '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 alltags = document.all? document.all : document.getElementsByTagName("*");
		for (i=0; i < alltags.length; i++) {
			if (alltags[i].className == "emailCloak") {
				var oldText = alltags[i].firstChild;
				var emailAddress = alltags[i].firstChild.nodeValue;
				var user = emailAddress.substring(0, emailAddress.indexOf("("));
				var website = emailAddress.substring(emailAddress.indexOf(")")+1, emailAddress.length);
				var newText = user+"@"+website;
			  	var a = document.createElement("a");
			  	a.href = "mailto:"+newText;
				var address = document.createTextNode(newText);
				a.appendChild(address);
				alltags[i].replaceChild(a,oldText);
			}
		}
	}
}

