var lights=1;
var browser;
var detect = navigator.userAgent.toLowerCase();

function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

function setOpacity(id, opac) {
	if(opac<0){opac=0;} if(opac>100){opac=100;}
	var c=opac/100;
	var d=document.getElementById(id);
	if(typeof(d.style.filter)=='string'){d.style.filter='alpha(opacity:'+opac+')';}
	if(typeof(d.style.KHTMLOpacity)=='string'){d.style.KHTMLOpacity=c;}
	if(typeof(d.style.MozOpacity)=='string'){d.style.MozOpacity=c;}
	if(typeof(d.style.opacity)=='string'){d.style.opacity=c;}
	//if(typeof(d.style.oOpacity)=='string'){d.style.oOpacity=c;}
}


function prepareIE(height, overflow) {
//	alert("prepare");
	bod = document.getElementsByTagName('body')[0];
	bod.style.height = height;
	bod.style.overflow = overflow;

	htm = document.getElementsByTagName('html')[0];
	htm.style.height = height;
	htm.style.overflow = overflow; 
}

function setScroll(x, y) {
	window.scrollTo(x, y); 
}

function switchlights() {
	if (lights==1) {
		lights=0;
		/*
		if (browser == "Internet Explorer") {
			prepareIE('100%', 'hidden');
			setScroll(0,0);
		}
		*/

		document.getElementById("darkness").style.display="block";
		//document.getElementById("darkness2").style.display="block";
		document.getElementById("lightbutton").style.backgroundPosition="bottom left";
		document.getElementById("lightbutton").href="#turniton";
	} else {
		lights=1;
//		fadeOut(80,20);
//		fadeOut(80,20);
		document.getElementById("darkness").style.display="none";
		//document.getElementById("darkness2").style.display="none";
		document.getElementById("lightbutton").style.backgroundPosition="top left";
		document.getElementById("lightbutton").href="#turnitoff";
		//if (browser == "Internet Explorer") prepareIE("auto", "auto");
	}	
}

function init() {
	var ob;
	
	if (checkIt('msie')) browser = "Internet Explorer";
	
	if (ob=document.getElementById("postcommentbutton")) {
		
		ob.onmouseover=function() {
			ob.style.backgroundPosition="bottom left";
		}
		ob.onmouseout=function() {
			ob.style.backgroundPosition="top left";
		}
		
		inputauthor=document.getElementById('author');
		inputemail=document.getElementById('email');
		inputurl=document.getElementById('url');
		inputcomment=document.getElementById('comment');
		
		if (inputauthor) {
			inputauthor.onfocus=function() { inputauthor.className="focus"; }
			inputauthor.onblur=function() { if (inputauthor.value=="") inputauthor.className=""; else inputauthor.className="filled"; }
			
			inputemail.onfocus=function() { inputemail.className="focus"; }
			inputemail.onblur=function() { if (inputemail.value=="") inputemail.className=""; else inputemail.className="filled"; }
			
			inputurl.onfocus=function() { inputurl.className="focus"; }
			inputurl.onblur=function() { if (inputurl.value=="") inputurl.className=""; else inputurl.className="filled"; }
		}
		
		inputcomment.onfocus=function() { inputcomment.className="focus"; }
		inputcomment.onblur=function() { if (inputcomment.value=="") inputcomment.className=""; else inputcomment.className="filled"; }
		
	}
}

window.onload=init;