﻿// JavaScript Document
window.onload = function() {
	initImage();
}
window.onresize = function() {
	//setFooter();
}

var imageId = 0 //'hometopper1';
var image = 0 //document.getElementById(imageId);
var gCounter = 0;
var gPath = "data/uploads/picture/";

function initImage() {
    var ran_unrounded=Math.random()*(gMaxPhotos-1);
    gCounter=Math.round(ran_unrounded); //Start with a random picture

	checkhotspots();
	imageId = 'hometopper1';
	image = document.getElementById(imageId);
	setOpacity(image, 0);
	imageURL = gPath + gImages[gCounter];
	//document['hometopper1'].src = imageURL;
	image.src = imageURL;
	window.setTimeout("fadeIn('"+imageId+"',0)", 150); //go and start fading
}

function checkhotspots() {
	try {
		if (document.getElementById) {
			var ss1Height = document.getElementById('homehotspot1').offsetHeight;
			var ss2Height = document.getElementById('homehotspot2').offsetHeight;
			
			if (ss1Height>ss2Height) {
				document.getElementById('homehotspot2').style.paddingBottom = ss1Height - ss2Height + 3 + 'px';
			} else {
				document.getElementById('homehotspot1').style.paddingBottom = ss2Height - ss1Height + 3 + 'px';
			}
			
		}
	}
	catch(e) { }
}

function fadeIn(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			opa = (2-(opacity/100))*opacity; //Fading out
			if (opacity<40) {opa = opacity * opacity / 25;} //Fading in
			setOpacity(obj,opa);
			opacity +=2; //fade speed
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 33);
		} else {
			//Fading is done
			setOpacity(obj, 100);
			// Set background the same url  as foreground
			imageURL = gPath + gImages[gCounter];
			newImg = new Image();
			newImg.src = imageURL;
			document.getElementById('hometopper2').src = newImg.src;
			window.setTimeout("nextImage('"+objId+"')",1000); //wait before updating - stupid IE6!
		}
	}
}

function nextImage(objId) {
	obj = document.getElementById(objId);
	setOpacity(obj, 0);
	window.setTimeout("gonext('"+objId+"')",1000);
}
function gonext(objId) {
	gCounter = gCounter + 1;
	if (gCounter>=gMaxPhotos) {gCounter = 0;}
	imageURL = gPath + gImages[gCounter];
	newImg = new Image();
	newImg.src = imageURL;
	image.src = newImg.src;		
		
	window.setTimeout("fadeIn('"+imageId+"',0)", 5000); //wait 5 seconds before fading
}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}



