

function docSize() {
	if (document.getElementById) {
		if (document.documentElement && document.documentElement.clientHeight) {
			docWidth=document.documentElement.clientWidth;
			docHeight=document.documentElement.clientHeight;
		} else {
			docWidth = (document.all)?document.body.clientWidth:window.innerWidth;
			docHeight = (document.all)?document.body.clientHeight:window.innerHeight;
		}
	} else if (document.layers) {
 		docWidth=window.innerWidth;
 		docHeight=window.innerHeight;
	}
	//alert("X: "+docWidth+", Y: "+docHeight);
	return(docWidth+","+docHeight);
}


function adjustWindow(setW,setH) {
	borders = 12;
	bars = 120;
	ar = 1.25; // recomended aspect ratio
	setW += borders;
	setH += bars
	wh = docSize();
	w = parseInt(wh.split(",")[0])+borders;
	h = parseInt(wh.split(",")[1])+bars;
	maxW = screen.availWidth;
	maxH = screen.availHeight;
	setW = Math.min(setW, maxW);
	setH = Math.max(setH, parseInt(setW/ar));
	setH = Math.min(setH, maxH);
	x = parseInt((maxW-setW)/2);
	y = parseInt((maxH-setH)/2);
	//alert("W: "+w+", H: "+w+"\n"+"setW: "+setW+", setH: "+setH);
	if (w < setW || h < setH) {
		moveTo(x,y);
		resizeTo(setW,setH);
	};
}


function resizeWindow() {
	window.moveTo(0,0);
	resizeTo(screen.availWidth,screen.availHeight);
	resizeTo(screen.availWidth,screen.availHeight);
	//alert(window.outerHeight)
	if (document.layers||document.getElementById) {
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
		};
	};
}


function fader(io,a,img) {

	document.io = io;
	document.a = a;
	document.a_min = 20;
	document.a_max = 100;
	document.img = document.getElementById(img);

	if (window.fading){
		clearInterval(fading);
	}
	fading = setInterval("fade()",30);
}


function fade() {

	io = document.io;
	a = document.a;
	a_max = document.a_max;
	a_min = document.a_min;
	img = document.img;

	if (io == 1) {
		if (img.filters.alpha.opacity >=a || img.style.opacity >= (a/100)) {
			clearInterval(fading);
		} else {
			fade_in(img);
		};
	} else if (io == 0) {
		if (img.filters.alpha.opacity <=a || img.style.opacity <= (a/100)) {
			clearInterval(fading);
		} else {
			fade_out(img);
		};
	} else if (io == 2) {
		if (img.filters.alpha.opacity < document.a_max || img.style.opacity < (a_max/100)) {
			fade_in(img);
		} else if (img.filters.alpha.opacity >= 100 || img.style.opacity >= (a_max/100)) {
			document.a_max = 20;
			document.a_min = 20;
			fade_out(img);
		} else if (img.filters.alpha.opacity > document.a_min || img.style.opacity > (a_min/100)) {
			fade_out(img);
		} else if (img.filters.alpha.opacity <= 20 || img.style.opacity <= (a_min/100)) {
			document.a_max = 100;
			document.a_min = 100;
			fade_in(img);
		};
	};
}


function fade_in(img) {
	img.filters.alpha.opacity+=5; img.style.opacity+=0.5;
	}


function fade_out(img){
	img.filters.alpha.opacity-=1; img.style.opacity-=0.1;
}
