﻿//Set divs at first to hidden
document.write("<style type='text/css'>#f_Div1 {visibility:hidden;}</style>");
document.write("<style type='text/css'>#f_Div2 {visibility:hidden;}</style>");
document.write("<style type='text/css'>#f_Div3 {visibility:hidden;}</style>");

// Function for brining div into visibility slowly then hiding it again.
// Accepts the name of the Div, and a time in milliseconds when the outer loop begins
function fadeDiv(divId,m_time) {

	flashDiv = document.getElementById(divId);
	setOpacity(flashDiv, 0);
	window.setTimeout("visibleOn('"+divId+"')",m_time);  //toggle on visibility
	window.setTimeout("fadeIn('"+divId+"',0)",m_time);      // fade in div
	window.setTimeout("fadeOut('"+divId+"',100)", m_time+7000); //begin fade out at time interval
	window.setTimeout("visibleOff('"+divId+"')",m_time+8200);  //toggle off visibility
}

//Switches the visibility to visible
function visibleOn(divId){
    fDiv = document.getElementById(divId);
    fDiv.style.visibility = "visible";
}
//Switches the visibility to hidden
function visibleOff(divId){
    fDiv = document.getElementById(divId);
    fDiv.style.visibility = "hidden";
}

//function for fading in a Div, accepts the Divname and an opacity
function fadeIn(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 10;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);  //fade in takes 1000 miliseconds or 1 second
		}
		
	}
}

//function for fading out a Div, accepts the Divname and an opacity
function fadeOut(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity >= 0) {
			setOpacity(obj, opacity);
			opacity -= 10;
			window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 100);  //fade out takes 1000 miliseconds or 1 second
		}
		
	}
}

//function for setting opacity of an image across differnt browsers, it will flicker if 100%, so never gets there.
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;
}


//Begin the process of fading in and fading out 3 images
function TimedFading(){

    //At this point, a fade in and out takes 7 seconds
    var divtime = 0;

        //process of fading in and out 3 divs
        window.setTimeout("fadeDiv('f_Div1',1000)",divtime);
        divtime = divtime + 8000;  
        window.setTimeout("fadeDiv('f_Div2',1000)",divtime);
        divtime = divtime + 8000;
        window.setTimeout("fadeDiv('f_Div3',1000)",divtime);
        divtime = divtime + 8000;

}

//function to loop through fading div calls every 18 seconds
function BeginFading(){
    TimedFading();
    setInterval("TimedFading()",24000);
}
