/*\------------------------------------------------------------------------

	>> pdd.co.uk
	>> 05/09/07				
	>> Kostis Sakkas				
		
------------------------------------------------------------------------\*/


window.onload	= function() {/*setFooter();*/emailCloak();externalLinks();}
//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+" (opens in new window)" : "opens in new window";
			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]

------------------------------------------------------------------------\*/

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() {
	var add = (arguments[0]) ? arguments[0] : 0;
	
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var headerHeight  	= document.getElementById('header').offsetHeight;
			var footerHeight  	= document.getElementById('footer').offsetHeight;
			
			var containerEl		= document.getElementById('container');
			var containerHeight = containerEl.offsetHeight + add;
			
			var sbElement		= document.getElementById('sidebar');
			var sbHeight  		= sbElement.offsetHeight;
			
			var mainElement		= document.getElementById('main');
			var mainHeight  	= mainElement.offsetHeight;
			
		
			//alert("window: " + windowHeight + ",\r\nheader: " +headerHeight + ",\r\ncontainer: " +containerHeight+ ",\r\nsidebar: " +sbHeight + ",\r\nmain: " +mainHeight + ",\r\nfooter:" + footerHeight);
			
			if (headerHeight + containerHeight + footerHeight < windowHeight) {				
				var h = windowHeight - (headerHeight + footerHeight)  + 'px';
				containerEl.style.height = sbElement.style.height = mainElement.style.height =  h;
			}
			else
				sbElement.style.height = mainElement.style.height = containerHeight +  'px';
		}
	}
}

function setEqual() {
	if (document.getElementById) {
		var sbMain  = document.getElementById('main');
		var sbElement  = document.getElementById('sidebar');
		
		if(sbMain.offsetHeight>sbElement.offsetHeight)
			sbElement.style.height = sbMain.offsetHeight + 'px';
		else
			sbMain.style.height = sbElement.offsetHeight + '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);
			}
		}
	}
}


jobs	=	function(el){
	dl = document.getElementById(el);
	
	for (var i=0; i<dl.childNodes.length; i++){
		if ("DT" == dl.childNodes[i].nodeName){
			var dt = dl.childNodes[i];
			dt.className = 'on';
			for (var k=0; k<dt.childNodes.length; k++){
				if ("A" == dt.childNodes[k].nodeName){
					var a = dt.childNodes[k];
					a.className = 'on';
				}
			}
		}
		if ("DD" == dl.childNodes[i].nodeName){
			var dd = dl.childNodes[i];
			dd.className = 'on';
		}
	}
	if(dl.className == 'on'){
		//setFooter(-dl.offsetHeight);
		dl.className = dt.className = a.className = dd.className = '';
	}
	else{
		//setFooter(dl.offsetHeight);
		dl.className = 'on';
	}
}


toggle	=	function(el){
	div = document.getElementById(el);
	div.className = (div.className=='hidden') ? 'on' : 'hidden';
}


flash	=	function(swf){
	var swf_path = "http://pdd.sync.gr/assets/uploads/bnr";
	var swf_width = 825;
	var swf_height = 430;
	var MM_contentVersion = 8;
	
	var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
	if ( plugin ) {
			var words = navigator.plugins["Shockwave Flash"].description.split(" ");
			for (var i = 0; i < words.length; ++i)
			{
			if (isNaN(parseInt(words[i])))
			continue;
			var MM_PluginVersion = words[i]; 
			}
		var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
	}
	else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
	   && (navigator.appVersion.indexOf("Win") != -1)) {
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
		document.write('on error resume next \n');
		document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
		document.write('</SCR' + 'IPT\> \n');
	}
	if ( MM_FlashCanPlay ) {
			document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
		document.write('  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" ');
		document.write(' ID="sponsors" WIDTH="' + swf_width + '" HEIGHT="' + swf_height + '" ALIGN="">');
		document.write(' <PARAM NAME=movie VALUE="' + swf_path + '/' + swf + '"> <PARAM NAME=quality VALUE=high> '); 
		document.write(' <EMBED src="' + swf_path + '/' + swf + '" quality=high ');
		document.write(' swLiveConnect=FALSE WIDTH="' + swf_width + '" HEIGHT="' + swf_height + '" NAME="sponsors" ALIGN=""');
		document.write(' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">');
		document.write(' </EMBED>');
		document.write(' </OBJECT>');
	} else{
		document.write('<a href="http://www.macromedia.com/go/getflashplayer" target="_blank"><img src="/_img/no_flash825.gif" alt="You need the latest Flash Player to view this content. Download it here." width="825" height="400" border="0" /></a>');
	}
	
	
}

