/* 
   This function loads a random image on page load 
*/
function rotatePics() {
    var imageList = [];

    /* 
      The imageList stores a two part labeled entry, one for the imgsrc url and
      then one for the the linktarget url 
     */

imageList[0] = {'imgsrc' : 'gfx/haasdoor_dyk.gif', 'linktarget' : 'about/units/haas/'};
    imageList[1] = {'imgsrc' : 'gfx/lgannounce.gif', 'linktarget' : 'http://libguides.wcsu.edu'};
    imageList[2] = {'imgsrc' : 'gfx/refstacks_dyk.gif', 'linktarget' : 'assistance/reference/ask'};
    imageList[3] = {'imgsrc' : 'gfx/study_dyk.gif', 'linktarget' : 'about/units/haas/related/floorplans/'};
    imageList[4] = {'imgsrc' : 'gfx/young_dyk.gif', 'linktarget' : 'about/units/young/'};
    imageList[5] = {'imgsrc' : 'gfx/intercampus.gif', 'linktarget' : 'services/circulation/related/intercampus/'};
    imageList[6] = {'imgsrc' : 'gfx/research_help.gif' , 'linktarget' : 'assistance/research/consultations/consult.tkl'};
    imageList[6] = {'imgsrc' : 'gfx/haas40years.gif' , 'linktarget' : 'about/units/archives/Haas/'};


        
       
    var x = Math.floor(Math.random() * imageList.length);
    var i = x || 1  // some times x was coming up undefined
    var workingimg = imageList[i]  

    var newDiv = DIV({'id' : 'rotateDiv', 'class' : 'rotation'},
        A({'href':workingimg.linktarget},IMG({'src' : workingimg.imgsrc,
            'alt' : 'Picture of the library'})));

    swapDOM('rotateDiv', newDiv);
}


/* 
   MochiKit Simple XMLHttpRequest Call
*/
function loadXhtmlFragment(url) {
    var doReplace = function (req) {
        $('rotateDiv').innerHTML = req.responseText;
    };
                                                                                                                                                         
    var doReplaceError = function () {
        $('rotateDiv').innerHTML = 'Click the buttons above to search!';
    };
                                                                                                                                                         
    var res = MochiKit.Async.doSimpleXMLHttpRequest(url);
    res.addCallbacks(doReplace,doReplaceError);
}
 
/* The next four functions load the designated xhtml fragment from the 
   includes directory replacing the picture. This keeps the portal doc
   (index.tkl) very simple. If they fail you just have to click on the big
   images to go directly to the search. 
*/

function showEResNote() {
  loadXhtmlFragment('http://library.wcsu.edu/web/includes/eres.xml'); 
}

function showConsulsNote() {
  loadXhtmlFragment('http://library.wcsu.edu/web/includes/books.xml'); 
}

function showResearchNote() {
  loadXhtmlFragment('http://library.wcsu.edu/web/includes/help.xml'); 
}

function showArticleNote() {
  loadXhtmlFragment('http://library.wcsu.edu/web/includes/articles.xml'); 
}

function loadNewTitles() {
  var doReplace = function (req) {
    $('rss_box').innerHTML = req.responseText;
  };

  var doReplaceError = function () {
    $('rss_box').innerHTML = "Error loading new books RSS";
  };

  var req =
    MochiKit.Async.doSimpleXMLHttpRequest('http://library.wcsu.edu/test/rss/?num=5');
  req.addCallbacks(doReplace, doReplaceError);
}


// I'm not using this but I might 
function roundDivs() {
  MochiKit.Visual.roundClass('div', "menu1");
}


if (window.attachEvent)
  window.attachEvent("onload", roundDivs)
  else
  window.onload=roundDivs;


MochiKit.Signal.connect(window, "onload", roundDivs);
