﻿// 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/Bannerlink/";

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];
	link = gLinks[gCounter];
	//document['hometopper1'].src = imageURL;
	image.innerHTML = '<a href="' + link + '" onclick="window.open(this.href); return false;"><img src="' + imageURL + '" border="0" /></a>';
	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);
		
		obj.style.display = 'block';
		
		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
			document.getElementById('hometopper2').innerHTML = document.getElementById('hometopper1').innerHTML;
			window.setTimeout("nextImage('"+objId+"')", 500); //wait before updating - stupid IE6!
		}
	}
}

function nextImage(objId) {
	obj = document.getElementById(objId);
	setOpacity(obj, 0);
	window.setTimeout("gonext('"+objId+"')",3500);
}
function gonext(objId) {
	gCounter = gCounter + 1;
	if (gCounter>=gMaxPhotos) {gCounter = 0;}
	imageURL = gPath + gImages[gCounter];
	link = gLinks[gCounter];
	//document['hometopper1'].src = imageURL;
	document.getElementById('hometopper1').innerHTML = '<a href="' + link + '" onclick="window.open(this.href); return false;"><img src="' + imageURL + '" border="0" /></a>';
	document.getElementById('hometopper1').style.display = 'none';
		
	window.setTimeout("fadeIn('"+imageId+"',0)", 500); //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;
}




