//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;

//testimonial data
var testimonialNum = 0;
var testimonialArray = new Array();

//each array entry has 2 array entries, the leaders details and the testimonial itself.
testimonialArray[0] = new Array(new Array(),"EF is a great way to spend the summer. You get to work with great people from all over the UK, Europe and indeed the world. It is a fantastic opportunity to enhance your skills in organisation, management and communication. My favourite thing about working for EF is the great feeling of working as part of a team and the instant feedback you get from the students when you have organised something they really enjoy!");

//the leaders details [i][0] is again an array which contains a record for each line.
testimonialArray[0][0][0] = "Anthony 'Sarge' Sargent";
testimonialArray[0][0][1] = "Activity Leader, Torbay Global Village 2002";
testimonialArray[0][0][2] = "Activity Organiser, Torbay Global Village &amp; Torquay 2003";
testimonialArray[0][0][3] = "Course Director, Oxford, 2005";
testimonialArray[0][0][4] = "Central Support Team, 2006 & 2007";


testimonialArray[1] = new Array(new Array(),"The best thing about EF is meeting people from all over the world. We work hard and have lots of fun and I now have friends from all over Europe thanks to EF. There are constant challenges but most can be overcome with good organisation from the outset. My general level of organisation in having a million things to think about at once has made me highly efficient and good at solving problems on the spot. If you're outgoing, hard working, happy to commit yourself to the school and the students and ready to throw yourself into EF for the summer, you'll fit in well! EF is hard work but very rewarding.");
testimonialArray[1][0][0] = "Jon McAlone";
testimonialArray[1][0][1] = "Local Leader, Eastbourne, 2004";
testimonialArray[1][0][2] = "Local Leader/Course Director, Eastbourne, 2005";
testimonialArray[1][0][3] = "Course Director, Eastbourne 2006 & 2007";


testimonialArray[2] = new Array(new Array(),"I enjoy working with people from all over the world; the friendships that develop during a summer are unique, I have made many great friends over the years. The satisfaction when the students return home and have had the time of their life is spectacular, and to be a part of that is great! One of the biggest challenges is that you never really know what to expect and need to be prepared for every eventuality. But that is also one of the best parts of the job! I have gained so much experience; in running a team, in planning and organisation and learning to work under pressure. The experience you gain during one summer is unique and I would find it hard to believe that you could achieve so much in any other job. Go for it! You'll work hard, and you'll be surprised about how much you can do! And you will also have the time of your life while you're doing it!");
testimonialArray[2][0][0] = "Jenny Weidstam";
testimonialArray[2][0][1] = "Course Leader 2001, 2002, 2003";
testimonialArray[2][0][2] = "Centre Manager Somerset 2004, 2005";
testimonialArray[2][0][3] = "Centre Manager Oxford 2006 & 2007";


testimonialArray[3] = new Array(new Array(),"I started working for EF in my third year of University after seeing an EF poster at the University Careers Office advertising for TEFL teachers. I had spent my Gap Year as a TEFL teacher in Central America and I found working with foreign students really rewarding, so applied for the position. Working for EF over the summer was fantastic; it enabled me to meet loads of new people and I really enjoyed the work I did. Initially teaching can be daunting but once you have established a bond with your group, it is amazing to see the daily improvements in the students' English. Working for EF has really helped me get a true understanding of teaching and I am now preparing to go back to university to do a PGCE!");
testimonialArray[3][0][0] = "Kelly Myatt";
testimonialArray[3][0][1] = "Local Teacher, Brighton, 2005 &amp; 2006";
testimonialArray[3][0][2] = "Assistant Course Director, Oxford, 2007";

testimonialArray[4] = new Array(new Array(),"My EF career has been a whirlwind of challenges, rewarding experiences and meeting fantastic new people.  Working as a Local Leader was the most additively enjoyable job I had ever done and playing a hands on role in the running of the school as Course Director was even better!  I’m now working with the Central Operations Team in London and everyday brings an exciting new challenge.  Working with EF is fun, satisfying and enriching – it teaches you things that other jobs don’t even come close to.");
testimonialArray[4][0][0] = "Kim Price";
testimonialArray[4][0][1] = "Local Leader, Torquay 2006";
testimonialArray[4][0][2] = "Course Director, Torquay 2007";
testimonialArray[4][0][3] = "Central Operations Team, London 2007";


//Controls the display and hide of each of the jobs on the opportunities page
function showJob(which) {
    //set the global variable with the div reference
    curDiv = document.getElementById(which);

    //grab the job detail content.
    if(curDiv.style.display == "none") {
        //set as visible and clear the content.
        curDiv.style.display = "inline";
    } else {
        //grab the total number of lines of code
        curDiv.style.display = "none";
    }
}

//grab the next item in the testimonial array and display it on the page.
function changeTestimonial() {
    var leaderDetailsDiv = document.getElementById("leaderDetails");
    var leaderTestimonialDiv = document.getElementById("leaderTestimonial");
    leaderDetailsDiv.innerHTML = "";
      testimonialNum=Math.floor(Math.random()*5);
    
    var curTestimonial = testimonialArray[testimonialNum];
    
    var curLeaderDetails = curTestimonial[0];
    
    var outStr = "";
    for(i = 0; i <= curLeaderDetails.length - 1; i ++) {
        if(i == 0) {
            outStr += "<p><strong>" + curLeaderDetails[i] + "</strong></p>";
        } else {
            outStr += "<p>" + curLeaderDetails[i] + "</p>";
        }
    }
    leaderDetailsDiv.innerHTML = outStr;
    leaderTestimonialDiv.innerHTML = "";
    leaderTestimonialDiv.innerHTML = "<p>" + curTestimonial[1] + "</p>";
   
    
}
//this function is called when the page is loaded
function testimonialSetup() {
    // setting the testimonialNum as a Random Number
    
     //we set the first testimonial
    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('testimonials').style.filter = "alpha(opacity=" + opac + ");";
        } else if(ns6) {
            document.getElementById('testimonials').style.MozOpacity = opac/100;
        } else {
            document.getElementById('testimonials').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('testimonials').style.filter = "alpha(opacity=" + opac2 + ");";
        } else if(ns6) {
            document.getElementById('testimonials').style.MozOpacity = opac2/100;
        } else {
            document.getElementById('testimonials').filters.alpha.opacity = opac2;
        }
        setTimeout('fadeTestimonialOut()',1);
    }
}
 
    function showApplicationForm(cur,next)
    {
        window.location = "step1.asp"
        //window.location='nextstep.asp?curstep='+ cur +'&nextstep=' + next + '';
    }

function appSlideDown () {
    var theForm = document.getElementById("appForm");
    var windowWidth = getWindowWidth();
    var leftPos = (windowWidth - 700) / 2;
    theForm.style.left = leftPos + "px";
    var curTop = parseInt(theForm.style.top.substr(0,(theForm.style.top.length - 2)));
    if(curTop < 10) {
        if(dropSpeed > 1) {
            dropSpeed --;
        }
        newTop = parseInt(theForm.style.top.substr(0,(theForm.style.top.length - 2))) + dropSpeed;
        theForm.style.top = newTop + "px";
        setTimeout('appSlideDown()',1);
    } else {
        dropSpeed = 80;
        theForm.style.top = "10px";
    }    
}

 function hideApplicationForm() {
    window.location='index.asp';
}

function appSlideUp () {
    var theForm = document.getElementById("appForm");
    var windowWidth = getWindowWidth();
    var leftPos = (windowWidth - 700) / 2;
    theForm.style.left = leftPos + "px";
    var curTop = parseInt(theForm.style.top.substr(0,(theForm.style.top.length - 2)));
    if(curTop > -1000) {
        if(upSpeed < 100) {
            upSpeed += 5;
        }
        newTop = parseInt(theForm.style.top.substr(0,(theForm.style.top.length - 2))) - upSpeed;
        theForm.style.top = newTop + "px";
        setTimeout('appSlideUp()',1);
    } else {
        upSpeed = 1;
        theForm.style.top = "-1500px";
    }    
}

function setAppX() {
    var theForm = document.getElementById("appForm");
    var windowWidth = getWindowWidth();
    var leftPos = (windowWidth ) / 2;
    //theForm.style.left = leftPos + "px";
}

function getWindowWidth() {
    var myWidth = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
    }
    return myWidth;
}