// JavaScript Document

var fadeInStep = 0;
var fadeOutStep = 0;
var fadeInSteps = 30;//number of step changes in opacity
var fadeOutSteps = 10;//number of step changes in opacity
var fadeDelay = 20;//miliseconds between each opacity level
var msgTime = 4000;//length of time (mili seconds) to show each message for
var fadeElem;

var arrHtml = new Array();
var arrIndex = -1;//so it starts on the index 0 when changeMessage() is called
function fadeHtml(){
	setupHtmlArray();
	changeMessage();
	//fadeIn();
	window.setTimeout("fadeOut()", msgTime);
}


function setupHtmlArray() {
	arrHtml[0] = '<p>Need to settle today?<br />Bad credit?<br />Refused by banks?</p><p class="html_callnow">Call now 1300 792 284 or <span class="fadelink" onclick="window.location=\'appform.php\'">apply now</span>.</p>';
	arrHtml[1] = '<p>We offer hassle free same day funding!</p><p>Urgent caveat loans, 2nd mortgages, refinance!</p><p class="html_callnow">Call now 1300 792 284 or <span class="fadelink" onclick="window.location=\'appform.php\'">apply now</span>.</p>';
	arrHtml[2] = '<p>Get cash against your car, truck, boat, house, etc.</p><p>No inspection or valuation required in most cases!</p><p class="html_callnow">Call now 1300 792 284 or <span class="fadelink" onclick="window.location=\'appform.php\'">apply now</span>.</p>';
	arrHtml[3] = '<p>Cash flow problems? Short of cash? Fixed in 24 hours!</p><p class="html_callnow">Call now 1300 792 284 or <span class="fadelink" onclick="window.location=\'appform.php\'">apply now</span>.</p>';
}

function fadeIn() {
	//executed every time the opacity changes one level (between 0 and 20)
	fadeElem = document.getElementById("fade_html");
	if(fadeInStep == fadeInSteps){
        clearOpacity(fadeElem);
		fadeInStep = 0;//reset
		window.setTimeout("fadeOut()", msgTime);
    } else {
		setOpacity(fadeElem, (fadeInStep/fadeInSteps));
		fadeInStep++;
		window.setTimeout("fadeIn()", fadeDelay);
	}
}
function fadeOut() {
	//executed every time the opacity changes one level (between 0 and 20)
	fadeElem = document.getElementById("fade_html");
	if(fadeOutStep < 0){
		fadeOutStep = fadeOutSteps;//reset
		changeMessage();
		fadeIn();
    } else {
		setOpacity(fadeElem, (fadeOutStep/fadeOutSteps));
		fadeOutStep--;
		window.setTimeout("fadeOut()", fadeDelay);
	}
}

function changeMessage(){
	//update the message with the next one, return to the start after reaching the end
	arrIndex++;
	if(arrIndex == arrHtml.length){
		//return to first index element
		arrIndex = 0;
	}
	document.getElementById("fade_html").innerHTML=arrHtml[arrIndex];
}

function setOpacity( el, opacity){
    if(el.style.opacity != undefined){
        el.style.opacity = opacity;
    }else if( el.style.MozOpacity != undefined){
        el.style.MozOpacity = opacity;
    }else if ( el.style.filter != undefined){
        el.style.filter="alpha(opacity=" + Math.round(opacity * 100) + ")";
    }
}

function clearOpacity(el){
    //fixes problem with IE. No text anti-aliasing when alpha filter is used.
	if ( el.style.filter != undefined){
        el.style.filter="";
    }
}

function checkStyles(){
	fadeElem = document.getElementById("fade_html");
	alert("opacity style = "+fadeElem.style.opacity+"\n"+"MozOpacity style = "+fadeElem.style.MozOpacity+"\n"+"filter style = "+fadeElem.style.filter);
}
