/*\------------------------------------------------------------------------

	>> 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);
			}
		}
	}
}

popuplive = function(){
	var features = "location=no, scrollbars=no ,status= no ,resizable=yes ,width=700 ,height=500,left=" + (screen.width - 580) / 2 +
   ",top=" + (screen.height - 700) / 2;
	return window.open("/live/", "poplive", features);
}

$(document).ready(function () {




	$('#navigation').accordion({ 
		selectedClass: 'selected', 
		header: '.head', 
		navigation: true, 
		autoHeight: false 
	});
	
	
	$('#gallery a').lightBox(); 
	
	
	Gload	=	function(){
		var __center_x	=	"38.051487";
		var	__center_y	=	"23.835011";
		
			
		var map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
			
		//var point = new GlatLng(__center_x, __center_y);
			
		map.setCenter(new GLatLng(__center_x, __center_y), 15);
			
		var baseIcon = new GIcon();
		baseIcon.shadow = "http://www.qways.gr/_img/icon-shadow.png";
		baseIcon.iconSize = new GSize(20, 34);
		baseIcon.shadowSize = new GSize(37, 34);
		baseIcon.iconAnchor = new GPoint(9, 34);
		baseIcon.infoWindowAnchor = new GPoint(9, 2);
		baseIcon.infoShadowAnchor = new GPoint(18, 25);	
		var homeicon = new GIcon(baseIcon);
		homeicon.image = "http://www.qways.gr/_img/icon.png";
			
		var marker = new GMarker(new GLatLng(__center_x, __center_y), {icon: homeicon});
			
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml("<p>Δημοκρατίας 8 Μελίσσια</p><p>15127</p>");
		});		
			
		map.addOverlay(marker);
	};
	
	//Gload();
	
});