var cpdown=false;

function writemail(u,s,tld) {
	var kukucs="@";
	var pont=".";
  document.write("<a href=\"mailto:"+u+kukucs+s+pont+tld+"\" title=\"Levél küldése...\">"+u+kukucs+s+pont+tld+"<\/a>");
}


function pngfix() {
	var opaque=new Array(
		{cl:"overlay", image:"http://csecsemootthonert.hu/images/kepek/gallery-overlay.png"}
	);
	for (var j = 0; j < opaque.length; j++) {
  	var t = document.getElementsByClassName(opaque[j].cl);
  	for (var i = 0; i < t.length; i++) {
  		t[i].style.backgroundImage = "none";
  		t[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+opaque[j].image+"', sizingMethod='crop');";
  	}
  }
}

function pagesize() {
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
		
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
		
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}

function copyshown() {
	cpdown=true;
}


function showcopyright() {
	$$("select","object","embed").each(function(node) {node.style.visibility="hidden"});
	var ps=pagesize();
  $("c-overlay").setStyle({
		width: ps[0]+"px",
		height: ps[1]+"px"
	});
	new Effect.Appear(
		$("c-overlay"),{
			duration: 0.2,
			from: 0.0,
			to: 0.8
	});
  var arrayPageScroll = document.viewport.getScrollOffsets();
  var ctop = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
  var cleft = arrayPageScroll[0]+ (document.viewport.getWidth()/2-250);
  $("c-container").setStyle({
		top: ctop + "px",
		width: "500px",
		left: cleft+"px",
		height: "500px"
	});
	new Effect.Appear(
		$("c-container"),{
			duration: 0.4,
			from: 0.0,
			to: 0.8
	});
	new Effect.Appear(
		$("copyright"),{
			duration: 0.6,
			from: 0.0,
			to: 1.0
	});
	if (!cpdown) 
		var ajax=new Ajax.Updater(
			"copyright",
			"in.copyright.php", {
				method: "get",
				onComplete: copyshown
			}
		);
}

function hidecopyright() {
	new Effect.Fade($("c-container"),{duration: 0.6});
	new Effect.Fade($("c-overlay"),{duration: 0.8});
	$$("select","object","embed").each(function(node) {node.style.visibility="visible"});
}

function copyright_init() {
	var body=$$("body")[0];
	body.appendChild(
		Builder.node("div",{id: "c-overlay"})
	);
	body.appendChild(
		Builder.node("div",{id: "c-container"},[
			Builder.node("div",{id: "copyright"}),
			Builder.node("a",{href: "#", id: "c-closelink"})
		])
	);
	$("c-overlay").hide().observe("click",function() {hidecopyright()});
	$("c-container").hide();
	$("c-closelink").innerHTML="Bezárás";
	$("c-closelink").observe("click",function(e) {
		hidecopyright()
		Event.stop(e);
		return false;
	});
}

function start() {
	
	var version=navigator.appVersion.split("MSIE");
	var brver=parseFloat(version[1]);
	if (brver<7) pngfix();
	
	copyright_init();
	
	Event.observe("copyrightlink","click", function(e) {
		showcopyright();
		Event.stop(e);
		return false;
	});
}

document.observe("dom:loaded",start);

