//global variables
var animTimeout = 0;
var curDiv = "";
var tempDivContent = "";
var curDivContent = new Array();
var loopNum = 0;
var testimonialFlag = 0;

var fadeOutTimeout = 0;
var callTestimonialInterval = 0;
var fadeInTimeout = 0;

var ie5  = (document.all && document.getElementById) ? true : false;
var ns6 = (!document.all && document.getElementById) ? true : false;
var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;
var opac = 0;
var opac2 = 100; 
var dropSpeed = 100;
var upSpeed = 1;
var ifThank;

//testimonial data
var panelNum = Math.floor(Math.random()*27);
var panelArray = new Array();

//each array entry has 3 array entries, content type, text and footer.
panelArray[0] = new Array("testimonial","<br style=\"line-height:5px\" />''Our children have really bonded with Helena.  Since then we have hosted two students each summer!'' ","<br style=\"line-height:5px\" />- Host Dad from Thousand Oaks, CA");
panelArray[1] = new Array("benefit","Develop meaningful and long-lasting relationships with international students.","");
panelArray[2] = new Array("testimonial","''The month went by quickly, and with tears, my family bid farewell to Vanessa and all of our international friends.''","<br style=\"line-height:5px\" />- Host Mom from Mandarin, FL");
panelArray[3] = new Array("testimonial","''Our lasting relationships are irreplaceable.''","<br style=\"line-height:5px\" />- Host Dad from Thousand Oaks, CA");
panelArray[4] = new Array("benefit","Share your culture while experiencing another.","");
panelArray[5] = new Array("testimonial","''We had love, laughter, and fun in these three weeks.  We are like family.''","<br style=\"line-height:5px\" />- EHP Student from Hong Kong");
panelArray[6] = new Array("testimonial","''They brought so much of their culture into our lives.  They will always have a place in our hearts and our homes.''","<br style=\"line-height:5px\" />- Host Family from Southwest FL");
panelArray[7] = new Array("benefit","10% discount on any Go Ahead Vacations program.","");
panelArray[8] = new Array("testimonial","''We got to experience a wide range of events while they were learning about our culture.''","<br style=\"line-height:5px\" />- Host Family from Southwest FL");
panelArray[9] = new Array("testimonial","''Over the last 10 years, we have opened our home to more than 15 EF students and really value not only the time with our students but the knowledge of their culture, language, and history that they share with us.''","<br style=\"line-height:5px\" />- Host Family from Southwest FL");
panelArray[10] = new Array("benefit","$250 discount on EF Au Pair programs.","");
panelArray[11] = new Array("testimonial","''The opportunities that EF has given us truly have changed our lives!''","<br style=\"line-height:5px\" />- Host Family from Southwest FL");
panelArray[12] = new Array("testimonial","''A tearful goodbye was inevitable as he asked if we would be his host family again.  I don't think any story I write could express the rewards we received.''","<br style=\"line-height:5px\" />- Host Family from FL");
panelArray[13] = new Array("benefit","10% discount on program fees for EF Foundation semester or year of study abroad.","");
panelArray[14] = new Array("testimonial","''We found that EHP actually keeps their students very busy without our help and the times we did have with her were very fun.''","<br style=\"line-height:5px\" />- Host Family from CA");
panelArray[15] = new Array("testimonial","''Our first-time experience hosting a foreign exchange student was really great!  EHP was very organized and professional throughout our entire experience.''","<br style=\"line-height:5px\" />- Host Family from CA");
panelArray[17] = new Array("benefit","10% discount on program fees for international and domestic trips with EF Tours or Smithsonian Student Travel.","");
panelArray[16] = new Array("testimonial","''Hello.  I can't speak highly enough about EHP's program.  The coordinators were wonderful to work with.  Every step of the way, they kept all of us host families well informed.''","<br style=\"line-height:5px\" />- Host Family from CA");
panelArray[18] = new Array("testimonial","''EHP is a great program and anyone who has the opportunity to expose our culture to a youngster from another country should never hesitate to do so.''","<br style=\"line-height:5px\" />- Host Dad from Northern California");
panelArray[20] = new Array("benefit","10% discount on EF International Language Schools courses.","");
panelArray[19] = new Array("testimonial","''Thank you for giving me one of the very best experiences of my life!''","<br style=\"line-height:5px\" />- EHP Student from Denmark");
panelArray[21] = new Array("testimonial","''I had the best host family ever!''","<br style=\"line-height:5px\" />- EHP Student from Estonia");
panelArray[23] = new Array("benefit","Points towards travel through EF with EHP’s Passport Rewards Program.","");
panelArray[22] = new Array("testimonial","''You were awesome!''","<br style=\"line-height:5px\" />- EHP Student from Finland");
panelArray[24] = new Array("testimonial","''Thank you for a great month!  My host family was the best possible and I really liked our international leaders too since they always could help us and knew what was going on.  You were all great!''","<br style=\"line-height:5px\" />- EHP Student from Finland");
panelArray[25] = new Array("benefit","Earn $25 for each family that you refer that hosts a student with our program.","");
panelArray[26] = new Array("testimonial","''Program was fantastic!!!''","<br style=\"line-height:5px\" />- EHP Student from Finland");

//grab the next item in the testimonial array and display it on the page.
function changeTestimonial() {
	var TestimonyTextDiv = document.getElementById("TestimonyText");
	var TestimonyDiv = document.getElementById("Benefits");
	TestimonyTextDiv.innerHTML = "";
	var TestimonyFooterDiv = document.getElementById("TestimonyFooter");

	var curPanelType = panelArray[panelNum][0];
	var curPanelText = panelArray[panelNum][1];
	var curPanelFoot = panelArray[panelNum][2];  	

	if (curPanelType == "benefit") {
		document.getElementById('Benefits').style.backgroundImage= 'url(/_imgs/public/benefit_bg.gif)';
	} else {
    		document.getElementById('Benefits').style.backgroundImage= 'url(/_imgs/public/testimonial_bg.gif)';
   	}

	var outStr="";
	outStr += "<p><strong>" + curPanelText + "</strong><br />";
  	TestimonyTextDiv.innerHTML = outStr;
	TestimonyFooterDiv.innerHTML = curPanelFoot;
   
	panelNum += 1; 
	if (panelNum == 27) {
		panelNum = 0;
	}
}

//this function is called when the page is loaded
function testimonialSetup(val) {
    changeTestimonial();
    //then set up the 30 second loop
    callTestimonialInterval = setInterval("callTestimonialLoop()",30000);
}

//This one does what it says on the tin, fade out the current one, change the text
//and fade the new one in again.
function callTestimonialLoop() {
    fadeTestimonialOut();
    testimonialTimeout = setTimeout("changeTestimonial()",2000);
    fadeInTimeout = setTimeout("fadeTestimonialIn()",2500);
}

function fadeTestimonialIn() {
    //increment the opacity and apply it to the div across IE6/7 and Firefox
    if(opac == 100){
        opac = 0;
    } else {
        opac ++;
        if(ie7 ) {
            opac ++;
            document.getElementById('TestimonyText').style.filter = "alpha(opacity=" + opac + ");";
             document.getElementById('TestimonyFooter').style.filter = "alpha(opacity=" + opac + ");";
        } else if(ns6) {
            document.getElementById('TestimonyText').style.MozOpacity = opac/100;
            document.getElementById('TestimonyFooter').style.MozOpacity = opac/100;
        } else {
            document.getElementById('TestimonyText').filters.alpha.opacity = opac;
            document.getElementById('TestimonyFooter').filters.alpha.opacity = opac;
        }
        setTimeout('fadeTestimonialIn()',1);
    }
}
function fadeTestimonialOut() {
    //decrement the opacity and apply it to the div across IE6/7 and Firefox
    if(opac2 == 0){
        opac2 = 100;
    } else {
        opac2 --;
        if(ie7) {
            opac2 --;
            document.getElementById('TestimonyText').style.filter = "alpha(opacity=" + opac2 + ");";
            document.getElementById('TestimonyFooter').style.filter = "alpha(opacity=" + opac2 + ");";
        } else if(ns6) {
            document.getElementById('TestimonyText').style.MozOpacity = opac2/100;
            document.getElementById('TestimonyFooter').style.MozOpacity = opac2/100;
        } else {
            document.getElementById('TestimonyText').filters.alpha.opacity = opac2;
            document.getElementById('TestimonyFooter').filters.alpha.opacity = opac2;
        }
        setTimeout('fadeTestimonialOut()',1);
    }
}
