var ImgReserveNames;
var ImgBayNames;
var ImgMarinaNames;
var ImgEsentepeNames;
var ImgCourr = 0;
var ImgBayCourr = 0;
var ImgMarinaCourr = 0;
var ImgEsentepeCourr = 0;
var Delay = 5001;
var FadeSpid = 2000;
var TimerID;

function initFade()
{
	var iSpid = FadeSpid;
	var oImgs = "http://www.cyprus-seaterra.com/images/reserve_1.jpg;http://www.cyprus-seaterra.com/images/reserve_2.jpg;http://www.cyprus-seaterra.com/images/reserve_3.jpg";
	ImgReserveNames = oImgs.split(';');
	var oImgs = "http://www.cyprus-seaterra.com/images/bay_1.jpg;http://www.cyprus-seaterra.com/images/bay_2.jpg;http://www.cyprus-seaterra.com/images/bay_3.jpg";
	ImgBayNames = oImgs.split(';');
	var oImgs = "http://www.cyprus-seaterra.com/images/marina_1.jpg;http://www.cyprus-seaterra.com/images/marina_2.jpg;http://www.cyprus-seaterra.com/images/marina_3.jpg";
	ImgMarinaNames = oImgs.split(';');
	var oImgs = "http://www.cyprus-seaterra.com/images/esentepe_1.jpg;http://www.cyprus-seaterra.com/images/esentepe_2.jpg;http://www.cyprus-seaterra.com/images/esentepe_3.jpg";
	ImgEsentepeNames = oImgs.split(';');
	FadeSpid = 0;
	fadeImgs();
	FadeSpid = iSpid;
	
}

function fadeImgs()
{
	if(ImgEsentepeNames[ImgEsentepeCourr] != null)
	{
		blendimage('blenddivesentepe','blendimageesentepe',ImgEsentepeNames[ImgEsentepeCourr],FadeSpid);
		//document.getElementById('blendimage').onclick=gotoCourse;
		//document.getElementById('MainPImgText').innerHTML = ImgTexts[ImgCourr];
		//LinkCourr = ImgCourr;
		ImgEsentepeCourr += 1; 
		if(ImgEsentepeNames[ImgEsentepeCourr] == null) ImgEsentepeCourr = 0;
	}else
	{
		ImgEsentepeCourr = 0;
	}
	TimerID = setTimeout("fadeImgs()", Delay);
	
}
/*
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
} */

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	//make new image
	document.getElementById(imageid).src = imagefile;
    //fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
	
}
