/*\------------------------------------------------------------------------

	>> blogs.sync.gr
	>> 24/01/07				
	>> Kostis Sakkas				
		
------------------------------------------------------------------------\*/


window.onload	= function() {externalLinks(); setFooter();}
window.onresize = function() {setFooter(); }
		


/*\------------------------------------------------------------------------
	
	CALL THE TOOLTIPS
	
------------------------------------------------------------------------\*/


allthetooltips	=	function(){
	if($('tip-pop-blogs'))	var popularBlogsTooltip = new Tooltip('tip-pop-blogs', 'tip-pop-blogs-data');
	if($('tip-pop-searches'))	var popSearchesTooltip = new Tooltip('tip-pop-searches', 'tip-pop-searches-data');
	if($('tip-podcasts'))	var podcastsTooltip = new Tooltip('tip-podcasts', 'tip-podcasts-data');
	if($('tip-favs'))	var favoritesTooltip = new Tooltip('tip-favs', 'tip-favs-data');
}



/*\------------------------------------------------------------------------
	
	Opens new windows via rel="external"
	url : http://www.brucelawson.co.uk/index.php/2005/opening-links-in-new-windows-in-xhtml-strict/
	
------------------------------------------------------------------------\*/

externalLinks = function() {
	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';
		}
	}
}


/*\------------------------------------------------------------------------
	
	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]

------------------------------------------------------------------------\*/

getWindowHeight = function() {
	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;
}
		
setFooter = function() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			
			var headerElement  = document.getElementById('header');
			var headerHeight  = headerElement.offsetHeight;
			
			var contentElement = document.getElementById('main');
			if (!contentElement) contentElement = document.getElementById('account');
			var contentHeight  = contentElement.offsetHeight;
			
			var footerElement = document.getElementById('footer-wrapper');
			var footerHeight  = footerElement.offsetHeight;
			
			if (headerHeight + contentHeight + footerHeight < windowHeight) {				
				contentElement.style.height= windowHeight - (headerHeight + footerHeight + 31)  + 'px';
				//alert("CONTENT : " + contentElement.style.height);

			}
			//alert("WINDOWHEIGHT : " + windowHeight + "\r\nHEADER : " + headerHeight + "\r\nCONTENT : " + contentHeight+ "\r\n FOOTER : " + footerHeight);
		}
	}
}



/*\------------------------------------------------------------------------
	
	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);
			}
		}
	}
}

	
termsofuse = function(){
	newwindow=window.open('http://www.sync.gr/terms.php', 'terms', 'resizable=1,toolbar=0,location=0,status=0,menubar=0,scrollbars=yes,width=700,height=450');
	newwindow.focus();
};
	
privacypolicy = function(){
	newwindow=window.open('http://www.sync.gr/privacy.php', 'privacy', 'resizable=1,toolbar=0,location=0,status=0,menubar=0,scrollbars=yes,width=700,height=450');
	newwindow.focus();
};

