var preloadImages = [];

if (window.addEventListener) {
	window.addEventListener('load', initialize, false);
}
else if (window.attachEvent) {
	window.attachEvent('onload', initialize);
}
else {
	window.onload = initialize;
}

function initialize() {
	imagePreloader();
}

function preload(images) {
    if (document.images) {
        var imageArray = new Array();
        imageArray = images.split(',');
        var imageObj = new Image();
        for(i = 0; i <= imageArray.length-1; i++) {
            //document.write('<img src="' + imageArray[i] + '" />');// Write to page (uncomment to check images)
            imageObj.src = imageArray[i];
        }
    }
}

function imagePreloader() {
	var preloaded = [];
	if (preloadImages.length > 0) {
		for (i=0;i<preloadImages.length;++i) {
			if (preloadImages[i] != "") {
				preloaded[i] = new Image();
				preloaded[i].src = preloadImages[i];
			}
		}
	}
}

function fadeOut() {
	$div = document.getElementById('bigimage');
		$div.style.opacity = 1.0;
		$div.style.filter = 'alpha(opacity=100)';
	

	$div.fade = function(fOut) {
		$fadeStep = 2;
		
		$opacity = this.style.opacity * 100;
		$opacity -= $fadeStep;
		if ($opacity < 0) {
			$opacity = 0;
			clearTimeout(this.timer);
		}
		this.style.filter = 'alpha(opacity=' + $opacity + ')';
		this.style.opacity = $opacity / 100;
		
		setFadeTimer(this,fOut);
	}

	$div.onload = function() {
		clearTimeout(this.timer);
		this.fade(1);
	}
}

function fadeIn() {
	$div = document.getElementById('bigimage');
		$div.style.opacity = .0;
		$div.style.filter = 'alpha(opacity=0)';

	$div.fade = function(fIn) {
		$fadeStep = 2;
		
		$opacity = this.style.opacity * 100;
		$opacity += $fadeStep;
		if ($opacity > 100) {
			$opacity = 100;
			clearTimeout(this.timer);
		}
		this.style.filter = 'alpha(opacity=' + $opacity + ')';
		this.style.opacity = $opacity / 100;
		
		setFadeTimer(this,fIn);
	}

	$div.onload = function() {
		clearTimeout(this.timer);
		this.fade(1);
	}
}

function setFadeTimer($caller,inOrOut) {
	$caller.timer = setTimeout(function () { $caller.fade(inOrOut); },10);
}

function swap_image(img_id,src) {
	if(document.getElementById(img_id)) {
		document.getElementById(img_id).src = src;
	}
}

function menu_change ( menuid, imgurl ) { 
	document.getElementById( menuid ).style.backgroundImage = "url(" + imgurl + ")"; 
}

function createMarker(point,html) {
	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
	});
	
	GEvent.addListener(marker,"mouseover", function() {
		marker.openInfoWindowHtml(html);
	});
	
	return marker;
}

