/*
   New Perspectives on JavaScript
   Tutorial 10
   Case Problem 1

   Author: Krystin Scott
   Date:   12/1/09

   Filename: engfr.js


   Function List:
   eventSource(e)
      Returns the source of an event in either event model

   swapFE(phrase, pnum)
      Changes a French phrase to the English version of that phrase.

   swapEF(phrase, pnum)
      Changes an English phrase ot the Frech version of that phrase.

   setUpTranslation()
      Insert the current week's french phrases into document and set up
      event handlers for the phrases.

*/

function eventSource(e) {
   var IE = document.all ? true:false;
   var DOM = document.addEventListener ? true: false;
   if (IE) return event.srcElement;
   else if (DOM) return e.currentTarget;
}

function setUpTranslation () { 
var phrases = document.getElementsByTagName ("p");
for (var i = 0; i < phrases.length; i++) {
phrases[i].number = i; 
phrases[i].childNodes[1].innerHTML = french[i];
phrases[i].childNodes[1].style.fontStyle = "italic";
phrases[i].childNodes[1].style.color = "black";

phrases[i].onmousedown = function() {
this.childNodes[1].innerHTML = english[this.number];
this.childNodes[1].style.fontStyle = "normal";
this.childNodes[1].style.color = "rgb(155, 102, 102)";
}
phrases[i].onmouseup = function() {
this.childNodes[1].innerHTML = french[this.number];
this.childNodes[1].style.fontStyle = "italic";
this.childNodes[1].style.color = "black";
}
}
}


function swapFE(e) {
var phrase = eventSource(e);
if (IE) phrase.attachEvent("on"+ mousedown, swapFE);
else if (DOM) phrase.addEventListener(onmousedown, swapFE, false);
var phrasenum = parseInt (phrase.innerHTML.previousSibling);
phrase.innerHTML.nodeValue = english[phrasenum - 1];
phrase.style.fontStyle = "normal";
phrase.style.color = "rgb(155, 102, 102)";
}


function swapEF(e) {
var phrase = eventSource(e);
if (IE) phrase.attachEvent("on"+ mouseup, swapEF);
else if (DOM) phrase.addEventListener(onmouseup, swapEF, false);
var phrasenum = parseInt (phrase.innerHTML.previousSibling);
phrase.innerHTML.nodeValue = french [phrasenum - 1];
phrase.style.fontStyle = "italic";
phrase.style.color = "black";
}
