// Java<script> for g.tec intendiX by www.grafikrausz.at 
// v01 2009-10-01
 
  // KEYBOARD MATRIX MAPPING
  itX_keys = new Array();
  itX_keys[0] = new Array("1","2","3","4","5","6","7","8","9","0");
  itX_keys[1] = new Array("q","w","e","r","t","y","u","i","o","p");
  itX_keys[2] = new Array("a","s","d","f","g","h","j","k","l","enter");
  itX_keys[3] = new Array("z","x","c","v","b","n","m","comma","dot","back");
  itX_keys[4] = new Array("clear","alarm","mail","doc","space","speak","print","colon","exclamation","question");
  
  itX_keyRows = new Array();
  itX_keyRows[0] = "1234567890";
  itX_keyRows[1] = "qwertyuiop";
  itX_keyRows[2] = "asdfghjkl/";
  itX_keyRows[3] = "zxcvbnm,.<";
  itX_keyRows[4] = "×$@+ §#:!?";
 
  itX_keyCols = new Array();
  itX_keyCols[0] = "1qaz×";
  itX_keyCols[1] = "2wsx$";
  itX_keyCols[2] = "3edc@";
  itX_keyCols[3] = "4rfv+";
  itX_keyCols[4] = "5tgb§";
  itX_keyCols[5] = "6yhn ";
  itX_keyCols[6] = "7ujm#";
  itX_keyCols[7] = "8ik,:";
  itX_keyCols[8] = "9ol.!";
  itX_keyCols[9] = "0p/<?";    

  itX_KM_ihtml = "";  
  itX_imgLoaded = 0;
  
  window.onload = itX_hideLoadingMsg;
    
  function itX_startSpellerDemo() { 
  // SEQUENCE  
  itX_seq_Row = new Array(0,1,2,3,4);
  itX_seq_Col = new Array(0,1,2,3,4,5,6,7,8,9);
  itX_ct = 0;  
  itX_ct_Row = 0;
  itX_ct_Col = 0;
  itX_cr = 0;
  itX_cc = 0;
  itX_stopDemo = false;
    

  // SPELLSTRING  
  itX_spellString = "watch your brain typing!".toLowerCase(); 
  itX_spellcounter = 0;
  itX_hit = 0;
  document.itX_textCase.txt.value = "";   
  document.itX_textCase.txt.value='starting Speller Demo';
  window.setTimeout("document.itX_textCase.txt.value='starting Speller Demo .'",1000);
  window.setTimeout("itX_hlAll()",1200);
  window.setTimeout("document.itX_textCase.txt.value='starting Speller Demo ..'",2000);
  window.setTimeout("document.itX_textCase.txt.value='starting Speller Demo ...'",3000);
  window.setTimeout("document.itX_textCase.txt.value='starting Speller Demo  ..'",4000);
  window.setTimeout("document.itX_textCase.txt.value='starting Speller Demo   .'",5000);
  window.setTimeout("document.itX_textCase.txt.value='starting Speller Demo'",6000);
  window.setTimeout("document.itX_textCase.txt.value=''",7000);   
  window.setTimeout("itX_runSequence_rowcol()",8000);  
  }
  
  /* function itX_createMatrix() {
    itX_preloadImg = new Array();
    for (mRow=0; mRow<5; mRow++) {
       for (mCol=0; mCol<10; mCol++) {
	   itX_preloadImg[mRow*mCol] = new Image();
	   itX_preloadImg[mRow*mCol].onLoad = itX_hideLoadMessage(); 
	   itX_preloadImg[mRow*mCol].src = ".\/keys\/key_" + itX_keys[mRow][mCol] + "_off.png";
	   itX_preloadImg[mRow*mCol+50] = new Image(); 
	   itX_preloadImg[mRow*mCol+50].onLoad = itX_hideLoadMessage();
	   itX_preloadImg[mRow*mCol+50].src = ".\/keys\/key_" + itX_keys[mRow][mCol] + "_on.png";
	   }    
    }
  } 
  
  function itX_hideLoadMessage() {
  itX_imgLoaded++;
  document.getElementById("itX_loader").innerHTML = "please wait, loading " + (".......".substr(1,itX_imgLoaded % 3));  
  if (itX_imgLoaded > 99) { 
      for (hRow=0; hRow<5; hRow++) {
       for (hCol=0; hCol<10; hCol++) {
	   itX_KM_ihtml += "<img class='itX_key' alt='' id='itX_key_"+ hRow + "_" + hCol +"' src='.\/keys\/key_" + itX_keys[hRow][hCol] + "_off.png'>";
       }      
	  itX_KM_ihtml += "<br>";  
     }
    document.getElementById("itX_keyMatrix").innerHTML = itX_KM_ihtml;
    document.getElementById("itX_loader").style.display="none"; 
   }
  }
  */
  
  function itX_hideLoadingMsg() {
  document.getElementById("itX_loader").style.display="none"; 
  // alert("Loaded!");
  }  
  
   function itX_resetMatrix() {
    for (mRow=0; mRow<=4; mRow++) {
       for (mCol=0; mCol<=9; mCol++) {
	   document.getElementById("itX_key_"+ mRow + "_" + mCol).style.borderColor="#0A161C";
       }
     }
  }
  
  function itX_runSequence_rowcol() {
  itX_seq_Col = itX_scramble(itX_seq_Col.join(",").split(","));
  itX_seq_Row = itX_scramble(itX_seq_Row.join(",").split(","));
  
  for (fr=0; fr<5; fr++) {
    for (fc=0; fc<10; fc++) {
	  currentkey = itX_keys[fr][fc];
	  currentkey = (currentkey=="space") ? " " : currentkey;
	  currentkey = (currentkey=="dot") ? "." : currentkey;
	  currentkey = (currentkey=="comma") ? "," : currentkey;
	  currentkey = (currentkey=="exclamation") ? "!" : currentkey;
	  currentkey = (currentkey=="question") ? "?" : currentkey;
	  currentkey = (currentkey=="enter") ? "/" : currentkey;
	  currentkey = (currentkey=="back") ? "<" : currentkey;
	  currentkey = (currentkey=="clear") ? "×" : currentkey;
	  currentkey = (currentkey=="alarm") ? "$" : currentkey;
	  currentkey = (currentkey=="mail") ? "@" : currentkey;
	  currentkey = (currentkey=="doc") ? "+" : currentkey;
	  currentkey = (currentkey=="speak") ? "§" : currentkey;
	  currentkey = (currentkey=="print") ? "#" : currentkey;
	  if (currentkey == itX_spellString.substr(itX_spellcounter,1)) { itX_cr = fr; itX_cc = fc; break; }
	  }
	 } 
  
  // alert(cr + " | " + cc);  
  itX_colorKey(itX_cr,itX_cc,"#ff3705");
  window.setTimeout("itX_flicker_rowcol(0)",150);  
  }
  
 function itX_flicker_rowcol() {
 if (itX_spellString == document.itX_textCase.txt.value || itX_stopDemo ) { itX_resetMatrix(); 
 																    window.setTimeout("document.itX_textCase.start.style.display='block'",5000); 
																	return; 
																  } else {
  itX_ct++;
  if (itX_ct <= 15) {
    
	  itXtype = ( (itX_ct % 3) == 0) ?  "row" : "col";
	  
	  switch (itXtype) {
	   case "row":
   	   itX_ct_Row = (itX_ct_Row == 4) ? 0 : itX_ct_Row+1;	   
	   itX_highlightRow(itX_seq_Row[itX_ct_Row],"on");	   
	   itX_checkKey(itX_seq_Row[itX_ct_Row],itX_seq_Col[itX_ct_Col],"row");	
	   break;
	   
	   case "col":
   	   itX_ct_Col = (itX_ct_Col == 9) ? 0 : itX_ct_Col+1;
	   itX_highlightCol(itX_seq_Col[itX_ct_Col],"on");
	   itX_checkKey(itX_seq_Row[itX_ct_Row],itX_seq_Col[itX_ct_Col],"col");	
	   break;
	   }	  
   
  	    
    } else {
  	  itX_ct = 0;
      itX_ct_Col = 0;
      itX_ct_Row = 0;          
	  itX_runSequence_rowcol();
	}  
  }
 }
  
  function itX_checkKey(r,c,rc) {
   
      // currentkey = itX_keys[r][c];
	  currentkey = itX_spellString.substr(itX_spellcounter,1);
	  currentkey = (currentkey=="space") ? " " : currentkey;
	  currentkey = (currentkey=="dot") ? "." : currentkey;
	  currentkey = (currentkey=="comma") ? "," : currentkey;
	  currentkey = (currentkey=="exclamation") ? "!" : currentkey;
	  currentkey = (currentkey=="question") ? "?" : currentkey;
	  currentkey = (currentkey=="enter") ? "/" : currentkey;
	  currentkey = (currentkey=="back") ? "<" : currentkey;
	  currentkey = (currentkey=="clear") ? "C" : currentkey;
	  currentkey = (currentkey=="alarm") ? "A" : currentkey;
	  currentkey = (currentkey=="mail") ? "M" : currentkey;
	  currentkey = (currentkey=="doc") ? "D" : currentkey;
	  currentkey = (currentkey=="speak") ? "K" : currentkey;
	  currentkey = (currentkey=="print") ? "P" : currentkey;
	 
	 keyMatch = ((rc=="row") ? itX_keyRows[r].indexOf(currentkey) : itX_keyCols[c].indexOf(currentkey)); 
	 
	 if (keyMatch != "-1") { // alert("ck:" + currentkey + " | km:" + keyMatch + " | string:" + (rc=="row"?itX_keyRows[r]:itX_keyCols[c]));
	   itX_hit++; 
	   if (itX_hit == 1) { itX_colorKey(itX_cr,itX_cc,"#fee01e"); }
	   if (itX_hit == 2) { itX_colorKey(itX_cr,itX_cc,"#66e200");  
	   	  		   	  	document.itX_textCase.txt.value += currentkey; 
						itX_spellcounter++; 
						window.setTimeout("itX_colorKey("+itX_cr+","+itX_cc+",'#0A161C')",150);						
						itX_ct = 16;
						itX_hit = 0; }
						  
     }
  
  }
  
  function itX_colorKey(r,c,colstr) {
  document.getElementById("itX_key_" + r + "_" + c).style.borderColor=colstr;  
  }
  
  // document.itX_textCase.txt.value = itX_keys[itX_seq_Row[itX_ct_Row]][itX_seq_Col[itX_ct_Col]]; 
  
  /* function itX_preFlicker(idx,cmd) {
   if (idx >= 50 && cmd=="off") { itX_runSequence_rowcol(); } else {
     hlRow = Math.floor(idx/10);
	 hlCol = (idx+"").substr((idx+"").length-1,1);
	 itX_highlightKey(hlRow,hlCol,cmd); 
	 idx++;
	 if (idx < 50) { itX_preFlicker(idx,cmd); } else { itX_preFlicker(0,"off"); }
	 } 
  } */
  
  function itX_hlAll() {
  itX_initRow(0,"on"); 
  itX_initRow(1,"on"); 
  itX_initRow(2,"on"); 
  itX_initRow(3,"on"); 
  itX_initRow(4,"on"); 
  }
    
  function itX_highlightKey(r,c,cmd) {
  document.getElementById("itX_key_" + r + "_" + c).src = "./keys/key_" + itX_keys[r][c] + "_" + cmd + ".png";
  }

  function itX_initRow(hlRow,cmd) {    
     for (hlCol=0; hlCol<10; hlCol++)  {  itX_highlightKey(hlRow,hlCol,cmd); }
	 if (cmd == "on") { window.setTimeout("itX_initRow("+hlRow+",'off')",2000);  }  
  }
  
  function itX_highlightRow(hlRow,cmd) {    
     for (hlCol=0; hlCol<10; hlCol++)  {  itX_highlightKey(hlRow,hlCol,cmd); }
	 if (cmd == "on") { window.setTimeout("itX_highlightRow("+hlRow+",'off')",70);  }	else { window.setTimeout("itX_flicker_rowcol()",150); }  
  }

  function itX_highlightCol(hlCol,cmd) {  
	 for (hlRow=0; hlRow<5; hlRow++) {  itX_highlightKey(hlRow,hlCol,cmd); }
	 if (cmd == "on") { window.setTimeout("itX_highlightCol("+hlCol+",'off')",70);  }	else { window.setTimeout("itX_flicker_rowcol()",150); }		   
  }

  function itX_scramble(vStr) {
  for (var itX_j, itX_x, itX_i = vStr.length; itX_i; itX_j = parseInt(Math.random() * itX_i), itX_x = vStr[--itX_i], vStr[itX_i] = vStr[itX_j], vStr[itX_j] = itX_x);
  return vStr;
  }     
  
  function itX_showVideo(videoBoxName) {
  itX_stopDemo = true;
  document.getElementById("itX_prodImg1").style.display="none";
  document.getElementById(videoBoxName).style.display="block"; 
  $f().play();
  }
  
  function itX_showDemo() {
  if ($f().isLoaded()) {$f().unload();}   
  document.getElementById("itX_prodImg1").style.display="none";
  document.getElementById("itX_video1").style.display="none";  
  }
  
  function itX_showImage() {
  if ($f().isLoaded()) {$f().unload();}
  document.getElementById("itX_video1").style.display="none";
  document.getElementById("itX_prodImg1").style.display="block";    
  }
  

