/*\------------------------------------------------------------------------

	>> talkingcure.gr
	>> 10/11/06				
	>> Kostis Sakkas				
		
------------------------------------------------------------------------\*/


window.onload	= function() {setFooter();externalLinks();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 sidebarElement  = document.getElementById('sidebar');
			var sidebarHeight  = sidebarElement.offsetHeight;
			
			var postElement = document.getElementById('post');
			var postHeight  = postElement.offsetHeight;
			
			if (postHeight>sidebarHeight) {
				sidebarElement.style.height= postHeight + 120 + 'px';
			}
			else if (postHeight<sidebarHeight) postElement.style.height=sidebarHeight - 160 + 'px';
			//alert("WINDOWHEIGHT : " + windowHeight + "\r\nSIDEBAR : " + sidebarHeight + "\r\nPOST : " + postHeight);
		}
	}
}


/*\------------------------------------------------------------------------
	
	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);
			}
		}
	}
}

