var alpha = 1.0;
var dalpha = 0;
var interval;

var bleed_w;
var bleed_h;

function doOnload() {
	findDimensions ();
//	showBleed("images/touch/schkolne_touch1.jpg", 1000, 647);
}

function findDimensions () {
	var x,y;
	
	if (self.innerHeight) {
		x = self.innerWidth;
		y = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		// Explorer 6 Strict Mode
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	} else if (document.body) { 
		// other Explorers
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}


	// um, here i hide or show the "please enlarge" icon based on size of window
//	if (x < 400 || y < 450) 
//		document.getElementById("divTopLeft").style.visibility = "visible";
//	else 
//		document.getElementById("divTopLeft").style.visibility = "hidden";
	


	var iwidth=1280;
	var iheight=960;
	var modX = x/iwidth;
	var modY = y/iheight;
	var itop = 0;
	var ileft = 0;	
	
	if (modX>modY) {
		iwidth=(iwidth*modX);
		iheight=(iheight*modX);
		itop = -0.5 * (iheight-y);
//		alert("iwidth " + iwidth + " iheight " + iheight + " ileft " + ileft);
	} else {
		iwidth=(iwidth*modY);
		iheight=(iheight*modY);
		ileft = -0.5 * (iwidth-x);
	}
	
	obj = document.getElementById("bgImage");
	obj.style.position = "absolute";

	obj.style.top = itop;
	obj.style.left = ileft;
	obj["width"] = iwidth;
	obj.height = iheight;
	
	if (document.getElementById("bleed").style.visibility == "visible") resizeBleed();
}

function fade() {
	alpha += dalpha;

	if (alpha < 0) {
//		alert("alpha is 0");
		test = document.getElementById("bgImage");
//	    alert("obj is " + test.style.opacity);
		clearInterval(interval);
		alpha = 0;
	}
	if (alpha > 1) {
//		alert("alpha is 1");		
		test = document.getElementById("bgImage");
		document.getElementById("photo_by").style.visibility = "visible";
//	    alert("obj is " + test.style.opacity);
		clearInterval(interval);
		alpha = 1;
	}
	
	obj = document.getElementById("bgImage");
	obj.style.opacity = alpha;
	obj.style.filter = "alpha(opacity: " + alpha * 100 + ")";
	obj.style["-moz-opacity"] = alpha;
	obj.style["-khtml-opacity"] = alpha;
}


function hideBackground() {
	document.getElementById("photo_by").style.visibility = "hidden";
//	alert("navigator.platform " + navigator.platform);
//	alert("navigator.product " + navigator.product);
//	alert("navigator.appCodeName " + navigator.appCodeName);
//	alert("navigator.userAgent " + navigator.userAgent);
//	alert("navigator.appName " + navigator.appName);
//	alert(navigator.userAgent.indexOf("Macintosh"));
//	alert(navigator.userAgent.indexOf("Firefox"));
//	alert(navigator.userAgent.indexOf("Safari"));
//if (navigator.userAgent.contains("Macintosh")  && navigator.userAgent.contains("Firefox")
	if (navigator.userAgent.indexOf("Macintosh") > -1 && navigator.userAgent.indexOf("Firefox") > -1) {
		obj = document.getElementById("bgImage");
		obj.style.visibility = "hidden";
	}
	else if (navigator.userAgent.indexOf("Opera") > -1) {
		obj = document.getElementById("bgImage");
		obj.style.visibility = "hidden";
	}
	else {
		dalpha = -0.1;
		clearInterval(interval);
		interval = setInterval(fade, 30);
	}
}

function showBackground() {
	if (navigator.userAgent.indexOf("Macintosh") > -1 && navigator.userAgent.indexOf("Firefox") > -1) {
		obj = document.getElementById("bgImage");
		obj.style.visibility = "visible";
		document.getElementById("photo_by").style.visibility = "visible";
	}
	else if (navigator.userAgent.indexOf("Opera") > -1) {
		obj = document.getElementById("bgImage");
		obj.style.visibility = "visible";
		document.getElementById("photo_by").style.visibility = "visible";
	}
	else {
		dalpha = +0.1;
		clearInterval(interval);
		interval = setInterval(fade, 30);
	}
}

/*function showBleed(filename, w, h) {
//	alert("showbleed " + filename + " " + w + " " + h);
	document.getElementById("bleedImage").src = "2008/" + filename;
	document.getElementById("bleed").style.visibility = "visible";
	document.getElementById("divTopRight").style.visibility = "visible";	
	
	bleed_w = w;
	bleed_h = h;
	resizeBleed();
}

function resizeBleed() {
	// scale the image
	var x,y;
	
	if (self.innerHeight) {
		x = self.innerWidth;
		y = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		// Explorer 6 Strict Mode
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	} else if (document.body) { 
		// other Explorers
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}

	var iwidth=bleed_w;
	var iheight=bleed_h;
	var modX = x/iwidth;
	var modY = y/iheight;
	var itop = 0;
	var ileft = 0;	
	
//	alert("resizeBleed " + bleed_w + " " + bleed_h);
	if (modX>modY) {
		iwidth=(iwidth*modX);
		iheight=(iheight*modX);
		itop = -0.5 * (iheight-y);
//		alert("iwidth " + iwidth + " iheight " + iheight + " ileft " + ileft);
	} else {
		iwidth=(iwidth*modY);
		iheight=(iheight*modY);
		ileft = -0.5 * (iwidth-x);
	}
	
	obj = document.getElementById("bleedImage");	
	obj.style.position = "absolute";

	obj.style.top = itop;
	obj.style.left = ileft;
	obj["width"] = iwidth;
	obj.height = iheight;
}


function hideBleed() {
	document.getElementById("bleedImage").src = "";
	document.getElementById("bleed").style.visibility = "hidden";	
	document.getElementById("divTopRight").style.visibility = "hidden";	
}
*/


