/*global abstractof, current_day, calendarwrite*/
  //creates the html tags for the search bar
function createSearch()
  {
    var head = document.getElementById('header');
  //jsonml
    var search_form = [
        "form",
        {"class" : "search"},
        {"id" : "search"},
        {"method" : "get"},
        {"action" : "recherche.html"},
        {"name" : "search"},
        ["input",
        {"class" : "textbox"},
        {"type" : "text"},
        {"name" : "mot"}],
        ["input",
        {"class" : "button"},
        {"type" : "submit"},
        {"value" : "chercher"}]
    ];    
      

      
    var head_form = search_form.parseJsonML();
    head.appendChild(head_form);
    }


/*-------------------------------------------
Vieileries neuves
original code : alejandro Gervasio @ devarticles.com
title : front end headlines with ajax
modifications and others chaostifiactions : jean-marc juin
--------------------------------------------*/

  // initialize data arrays and index
  var textes=[];
  var auteurs=[];
  var index=0;
  // send http requests
  function sendHttpRequest(url,callbackFunc,respXml){
      var xmlobj=null;
      try{
          xmlobj=new XMLHttpRequest();
      }
      catch(e){
          try{
              xmlobj=new ActiveXObject("Microsoft.XMLHTTP");
          }
          catch(e){
              alert('AJAX is not supported by your browser! En anglais ça le fait !!!');
              return false;
          }
     }
     xmlobj.onreadystatechange=function(){
          if(xmlobj.readyState==4){
              if(xmlobj.status==200){
                  respXml?eval(callbackFunc+'(xmlobj.responseXML)'):eval(callbackFunc+'(xmlobj.responseText)');
              }
          }
      }
      // open socket connection
      xmlobj.open('GET',url,true);
      // send http header
      xmlobj.setRequestHeader('Content-Type','text/xml;charset=UTF-8');
      xmlobj.setRequestHeader('cache','no-cache');
      // send http request
      xmlobj.send(null);
  }
  //creates the html tags for the xxxxxxxxml reader : vieilleries neuves
  function createE()
  {
  var doc=document.getElementById('neuv');
                   if(!doc){return};
  //jsonml                 
  var cont=["div", 
                    {"id":"side_box"}]
                  
  var navig=["div",{"id":"navig"}, 
                    /*["ul",*/
                    /*["li",*/   
                    ["a",
                    /*{"href":"#"},*/
                    {"class":"swapr"},
                    ["span","avancer"]]/*]]*/,
                    /*["li",*/
                    ["a",
                    /*{"href":"#"},*/
                    {"class":"swapl"},
                    ["span","retourner"]]/*]*/,
                    
                    ["p","clavier : fleches droites/gauche ou +/- selon navigateur"]
                    ];
           
                    


      var side_block=cont.parseJsonML();
      var side_navig=navig.parseJsonML();
      //doc.appendChild(side_block);
      doc.parentNode.insertBefore(side_block,doc.nextSibling);
      doc.parentNode.insertBefore(side_navig,doc.nextSibling.nextSibling);
  }

  // store headlines
  function storeHeadlines(vieilleries){
              var vieilleries=vieilleries.getElementsByTagName('neuves');
              // save headlines to data arrays
              for(var i=0;i<vieilleries.length;i++){
                          textes[i]=vieilleries[i].getElementsByTagName('texte')[0].firstChild.nodeValue;
                          auteurs[i]=vieilleries[i].getElementsByTagName('auteur')[0].firstChild.nodeValue;
                          
              // display first headline
              displayHeadline();         
  }
  }
  // display headline
  function displayHeadline(){
            var side_box=document.getElementById('side_box');  
               if(!side_box){return};
              // clean up headlines container
            side_box.innerHTML='';
                
                var blq = document.createElement('blockquote');
              // create  p texte
              var d=document.createElement('p');
                  d.appendChild(document.createTextNode(textes[index]));
              //create cite auteur
              var citer=document.createElement('cite');
                  citer.appendChild(document.createTextNode(auteurs[index]));	
                  citer.setAttribute('id','extrait');
             
             // append p to blockquote
             blq.appendChild(d);
             
              // append elements to headlines container
              side_box.appendChild(blq);
              side_box.appendChild(citer);
              
  }
  
 

  // initialize navigation panel
  function initializeNavigationPanel(){
              // attach 'displayHeadline()' function to left button 
              var doc1=document.getElementById('navig');
              doc1.getElementsByTagName('a')[1].onclick=function(){
                          displace_r();
              }
              doc1.getElementsByTagName('a')
  [0].onclick=function(){
                          displace_l();
              }    
             
            
  } 
 //forward and backward
function displace_r()
{
index--;
if(index<0){index=0;} 
displayHeadline();
}
function displace_l()
{
index++;
if(index>textes.length-1)
{index=textes.length-1};
displayHeadline();
}

//keyboard events :-)
//inspiration by Alessandro Fulciniti
//and its minislides...
function CaptureKey(e){
var key;
if (!e) 
{e = window.event;}
if (e.keyCode) {key=e.keyCode;}
else if (e.which) {key=e.which;}
if(key==37 || key==45) {displace_r();}                     
if(key==39 || key==43) {displace_l();} 
if(key==32) {displace_l();}                     
} 
   

  //helper function
  function addEvent(elm, evType, fn, useCapture){
    if (elm.addEventListener) 
    {
      elm.addEventListener(evType, fn, useCapture);
      return true;
    } else if (elm.attachEvent) { 
      var r = elm.attachEvent('on' + evType, fn);
      return r;
    } else {
      elm['on' + evType] = fn;
    }
  }

  if (document.createElement && document.createTextNode)
  {
    //addEvent(window,'load',createSearch,false);
//    addEvent(window,'load',createE,false);
   // addEvent(window,'load',initializeNavigationPanel,false);
    //addEvent(window,'load',calendarwrite,false);
    //addEvent(window,'load',activLink,false);
   // addEvent(window,'load',cursor,false);
    

  window.onload=function()
  {
  createE();
  sendHttpRequest('js/vieilleries.xml','storeHeadlines',true);
  initializeNavigationPanel();
  }
  document.onkeypress=CaptureKey;	
  }

  
    
    

