var gid = function(tag) {
	return document.getElementById(tag);
}

var login = {
	setup: function() {
		var bod = document.getElementsByTagName("body")[0];
		
		var overlay = DOM.create({tag: "div", id: "overlay" });
		var userform = DOM.create({tag: "div", id: "userform" });
		
		var canceler = DOM.create({tag: "span", text: "Cancel"});
		canceler.className = "closer";
		canceler.onclick = login.hide;
		
		gid("logsubmit").appendChild(canceler);
		
		var lform = gid("loginForm");
		lform.className += " overlay";
		//lform.style.display = "none";
		userform.appendChild(lform);
		
		var llink = gid("login").getElementsByTagName("p")[0];
		llink.onclick = login.show;
		
		
		bod.appendChild(overlay);
		bod.appendChild(userform);
	},
	show: function() {
		var arrayPageSize = login.getPageSize();
		
		var bg = gid("overlay");
		bg.style.display = "block";
		bg.style.height = arrayPageSize[1];
		bg.style.width = arrayPageSize[0];
		
		var show = gid("userform");
		show.style.display = "block";
		show.style.height = arrayPageSize[1];
		show.style.width = arrayPageSize[0];
		
		var lform = gid("loginForm");
		lform.style.display = "block";
		
		var inp = lform.getElementsByTagName("input")[0];
		inp.focus();
	},
	hide: function() {
		var bg = gid("overlay");
		bg.style.display = "none";
		var show = gid("userform");
		show.style.display = "none";
		
		var lform = gid("loginForm");
		lform.style.display = "none";
		
		var page = gid("page");
		page.focus();
	},
	getPageSize: function() {
	
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			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
			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 = windowWidth;
		} else {
			pageWidth = xScroll;
		}
	
	
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		return arrayPageSize;
	}
}

window.onload = login.setup;
