<?xml version="1.0" encoding="UTF-8" ?>
<Module>
    <ModulePrefs title="__MSG_title__" 
    title_url="http://geektechjl.blogspot.com/2009/08/animated-flickr-collage-google-gadget.html"
    description="__MSG_description__"  

   author="Jim Laurino" 
   author_email="jlaurino67.feedback+coolgadget@gmail.com"
   author_location="Oceanside, Ca"
   author_affiliation="Interstate Dist Co"
   author_photo="http://jimlaurino.hostzi.com/images/me.png"
   author_aboutme="Former Audio Programmer for video games. Worked on Midtown Madness 1 and 2 for PC among some others. 
Now a cross country trucker"
   author_link="http://jimlaurino.hostzi.com/"
   screenshot = "http://jimlaurino.hostzi.com/images/animflickrtablecap.png"
   thumbnail = "http://jimlaurino.hostzi.com/images/animflickrtabletn.png"
   height = "240">

    
<Locale messages="http://jimlaurino.hostzi.com/gadgets/langbundleaft/All_All.xml"/>

<Locale lang="es" messages="http://jimlaurino.hostzi.com/gadgets/langbundleaft/es_All.xml"/>

<Locale lang="de" messages="http://jimlaurino.hostzi.com/gadgets/langbundleaft/de_All.xml"/>


<Locale lang="fr" messages="http://jimlaurino.hostzi.com/gadgets/langbundleaft/fr_All.xml"/>

<Locale lang="it" messages="http://jimlaurino.hostzi.com/gadgets/langbundleaft/it_All.xml"/>

<Locale lang="hi" messages="http://jimlaurino.hostzi.com/gadgets/langbundleaft/hi_All.xml"/>

</ModulePrefs> 



   
  <UserPref name="caption" display_name="__MSG_Caption__" default_value="" datatype="string"/>
  <UserPref name="tags" display_name="__MSG_Searchtags__"  default_value="mountain" datatype="string"/>
  <UserPref name="username" display_name="__MSG_username__"  default_value="" datatype="string"/>
  
  <UserPref name="bgcolor" display_name="__MSG_Backgroundcolor__" default_value="Black" datatype="enum">
    <EnumValue value = "Aqua" display_value="__MSG_Aqua__" />
    <EnumValue value = "Black" display_value="__MSG_Black__"/>
    <EnumValue value = "Blue" display_value="__MSG_Blue__"/>
    <EnumValue value = "Fuchsia" display_value="__MSG_Fuchsia__"/>
    <EnumValue value = "Gray" display_value="__MSG_Gray__"/>
    <EnumValue value = "Green" display_value="__MSG_Green__"/>
    <EnumValue value = "Lime" display_value="__MSG_Lime__"/>
    <EnumValue value = "Maroon" display_value="__MSG_Maroon__"/>
    <EnumValue value = "Navy" display_value="__MSG_Navy__"/>
    <EnumValue value = "Olive" display_value="__MSG_Olive__"/>
    <EnumValue value = "Purple" display_value="__MSG_Purple__"/>
    <EnumValue value = "Red" display_value="__MSG_Red__"/>
    <EnumValue value = "Silver" display_value="__MSG_Silver__"/>
    <EnumValue value = "Teal" display_value="__MSG_Teal__"/>
    <EnumValue value = "White" display_value="__MSG_White__"/>
    <EnumValue value = "Yellow" display_value="__MSG_Yellow__"/>
  </UserPref>

  <UserPref name="txtcolor" display_name="__MSG_Textcolor__" default_value="Yellow" datatype="enum">

    <EnumValue value = "Aqua" display_value="__MSG_Aqua__" />
    <EnumValue value = "Black" display_value="__MSG_Black__"/>
    <EnumValue value = "Blue" display_value="__MSG_Blue__"/>
    <EnumValue value = "Fuchsia" display_value="__MSG_Fuchsia__"/>
    <EnumValue value = "Gray" display_value="__MSG_Gray__"/>
    <EnumValue value = "Green" display_value="__MSG_Green__"/>
    <EnumValue value = "Lime" display_value="__MSG_Lime__"/>
    <EnumValue value = "Maroon" display_value="__MSG_Maroon__"/>
    <EnumValue value = "Navy" display_value="__MSG_Navy__"/>
    <EnumValue value = "Olive" display_value="__MSG_Olive__"/>
    <EnumValue value = "Purple" display_value="__MSG_Purple__"/>
    <EnumValue value = "Red" display_value="__MSG_Red__"/>
    <EnumValue value = "Silver" display_value="__MSG_Silver__"/>
    <EnumValue value = "Teal" display_value="__MSG_Teal__"/>
    <EnumValue value = "White" display_value="__MSG_White__"/>
    <EnumValue value = "Yellow" display_value="__MSG_Yellow__"/>
  </UserPref> 

 
  <UserPref name="tabledims" display_name="__MSG_Tabledimensions__" default_value="2x2" datatype="enum">
    <EnumValue value = "1x1" />
    <EnumValue value = "1x2" />
    <EnumValue value = "2x1" />
    <EnumValue value = "2x2" />
  </UserPref> 

  <UserPref name="numpicstoload" display_name="__MSG_Numpicstoload__" default_value="15" datatype="enum">
    <EnumValue value = "10" display_value="__MSG_10__"/>
    <EnumValue value = "15" display_value="__MSG_15__"/>
    <EnumValue value = "20" display_value="__MSG_20__"/>
    <EnumValue value = "30" display_value="__MSG_30__"/>
  </UserPref> 


  <Content type="html">
    <![CDATA[






<style type="text/css">

div.content{
   text-align: center;
}

div.form{
   text-align: center;
   color: red;
   background-color: black; 

}


</style>

<script type="text/javascript">

/////////////xml.js
jl_xml_loadDoc = function(fname){
    
    var xmlDoc=null;
    // code for IE
    if (window.ActiveXObject){

       xmlDoc=new ActiveXObject("Microsoft.XMLDOM");

       if(!xmlDoc){
           alert("loadXMLDoc() Microsoft.XMLDOM creation failure ");
           return null;
       }
    } else if (document.implementation && document.implementation.createDocument) { 
           //code for Mozilla, Firefox, Opera, etc. 

           xmlDoc=document.implementation.createDocument ("","",null);

        }else {
            alert('Your browser cannot handle this script');
            return null; 
        }

        xmlDoc.async=false;
        xmlDoc.load(fname);
        return(xmlDoc);

}


///////////errhandle.js

jl_eh_debuglevel = 2;
jl_eh_outputsepwin = false;
jl_eh_srcurl = null;
jl_eh_dbugwin = null;

jl_eh_dbugwrite = function(msg){

	if(jl_eh_dbugwin === null){
		jl_eh_dbugwin = window.open();
	}

	jl_eh_dbugwin.document.write(msg);

}

jl_eh_setoutputsepwin = function(value){
    jl_eh_outputsepwin =  value;
}

jl_eh_setdebuglevel = function(level){
    jl_eh_debuglevel = level;
    if(level === 0){
       window.onerror=null;
    }else{
       window.onerror = jl_eh_handleErr;
    }

}

jl_eh_setsrcurl = function(url){
    jl_eh_srcurl = url;
}

jl_eh_getsrcurl = function(url){
    return jl_eh_srcurl;
}

jl_eh_dumpobject = function(prefix,theobject,outwin){

      var avar = null; 
      for(avar in theobject) {
          var newprefix = prefix + "[" +  avar + "]";
 
          if(typeof(theobject[avar]) === 'function'){
              continue;
          }   
          outwin.document.write(newprefix + " = " + theobject[avar] + "<br>" );

           
     }
}

jl_eh_dispconfbox = function(msg){

     var txt = msg + "\r\n " + " click ok to continue, click cancel to terminate";

    var r=confirm(txt);
    if (r == false)
    {
        //force termination by generating an error
        addlert();
    }

 
}


jl_eh_handleErr = function(msg,url,line){

    var outwin = null;

    if(jl_eh_debuglevel >= 2){ 
   
        if(jl_eh_outputsepwin === true){
            outwin = window.open();
        }else{
            outwin = window;
        }

    }     


    function outputurl(){
        var themsg = null;
        //check the current page first before the .js files

        if(jl_eh_getsrcurl() !== null){
  
        themsg = "Error: " + msg + " url " + jl_eh_getsrcurl() + " line " + line; 

        jl_eh_displayerrhtml(jl_eh_getsrcurl(),themsg,50,Number(line),outwin);   
          

        }else{
            //this does not work with angel fire. Have to set the 
            //src properly
            themsg = "Error: " + msg + " url " + url + " line " + line; 
            jl_eh_displayerrhtml(url,themsg,50,Number(line),outwin);

        }
    }//end outputurl 

    function outputscripts(){

        var themsg = null;
        var scriptnodes = document.getElementsByTagName("script"); 
    
        var i = 0;
        for(i = 0;i<scriptnodes.length;i += 1){
 
             if(scriptnodes[i].src){
                 
                 themsg = "Error: " + msg + " script file " + scriptnodes[i].src + " line " + line; 

                 jl_eh_displayerrhtml(scriptnodes[i].src,themsg,50,Number(line),outwin);      

             }    
        }
    }//end outputscripts
    
    function displayconfirmbox(){
        
        var txt = "";
        
        txt += "Error: " + msg + "\n";
        txt += "URL: " + url + "\n";
        txt += "Line: " + line + "\n\n";
            
        if(jl_eh_debuglevel >= 2) {
            txt += "src files outputed to page\n\n";
        }
    
        txt += "Click OK to continue \n\nCANCEL to terminate.\n\n";
        var r = confirm(txt);

        if (r == false){
            //force termination by generating an error
            addlert();
        }
    }

    
    if(jl_eh_debuglevel >= 2){
          outputurl();
          outputscripts();
    } 

    displayconfirmbox();


    return true;
}

jl_eh_displayerrhtml = function(url,msg,totallines,linehighlight,outwin){

    var params = {};
    var custparams = {};


    custparams.errorcb = function(txt,theparams){

        if(txt === "Permission denied"){

             alert("jl_eh_displayerrhtml error " + txt + "\r\n" + "enable your browser to access data across domains"); 

        }else{            
            alert("jl_eh_displayerrhtml error " + txt); 
            //force termination
            addlert();  
        }
  
    }


    function parsetxt(txt){
        
        var newtxt = txt.replace(/\r\n/g,"\n");
        newtxt = newtxt.replace(/\r/g,"\n");
        
        var wrkarray = newtxt.split("\n");
        var i=0; 
        newtxt = "";
        for(i=0;i<wrkarray.length;i += 1){
            var tmptxt = String(i + 1) + " " + wrkarray[i];
            wrkarray[i] = tmptxt;

        }  
        return wrkarray;
    }   

    custparams.parsecb = function(thedata,theparams){
         
        //local variables stored in lv json object
        var lv = {};
        lv.data = parsetxt(thedata);

        function lineinrange(){

            if(!theparams.linehighlight){
                return true;
            }

            if((theparams.linehighlight - 1) >= lv.data.length){
                return false; 
            }    

        }


        function initdiv(){

            //search for unused div. 

            var i = 0; 
            var thedoc = outwin.document;   
            while(1){
                lv.thediv = thedoc.getElementById("debugdiv" + String(i));

                if(lv.thediv){ 
                    i += 1;
                    continue;
                }

                lv.thediv=thedoc.createElement("div"); 
                lv.thediv.id = "debugdiv" + String(i); 
                lv.thediv.style.backgroundColor = "black";
                lv.thediv.style.color = "silver";
                thedoc.body.appendChild(lv.thediv);
                break;
   
            }   
            lv.thediv.appendChild(thedoc.createElement("br"));
        } 
         
        function createtable(){
            
            var thedoc = outwin.document;
            var tablenode = thedoc.createElement("table");
            tablenode.style.backgroundColor = "black";
            tablenode.style.color = "silver";
            tablenode.width = "100%";
            lv.thediv.appendChild(tablenode);
            tablenode.border = "1";

            var thnode = thedoc.createElement("thead");
            tablenode.appendChild(thnode);

            lv.headerrow =  thedoc.createElement("tr");
            thnode.appendChild(lv.headerrow);
            lv.headerdata = thedoc.createElement("th");

            var tbnode = thedoc.createElement("tbody");
            tablenode.appendChild(tbnode);

            var bodyrow =  thedoc.createElement("tr");
            tbnode.appendChild(bodyrow);
            lv.bodydata = thedoc.createElement("td");
            bodyrow.appendChild(lv.bodydata);
      
        }//end createtable
        
        function filltableheader(){
             
            var thedoc = outwin.document;
            if(theparams.msg){

                lv.headerdata.appendChild(thedoc.createTextNode(theparams.msg));
                lv.headerrow.appendChild(lv.headerdata);


            }
        }//end filltableheader

        function filltabledata(){ 
            var i=0;
            var startindex = 0;
            var thedoc = outwin.document;
            var endindex = lv.data.length - 1;
              
            if(theparams.totallines){
               
                if(theparams.linehighlight){

                     startindex = theparams.linehighlight - (theparams.totallines/2) - 1;

                     if(startindex < 0){
                         startindex = 0;
                     }   

                 }   
                 endindex = (startindex + theparams.totallines) - 1; 
                 if(endindex >= lv.data.length){
                     endindex = lv.data.length - 1;    
                 } 
            }
 

            for(i=startindex;i <= endindex;i += 1){
                
                var textnode = thedoc.createTextNode(lv.data[i]);
                var brnode = thedoc.createElement("br"); 
                var fileline = i + 1;

                if(fileline === theparams.linehighlight){
                    var spnode =  thedoc.createElement("span");     
                    spnode.style.color = "black";
                    spnode.style.backgroundColor = "silver";
                    spnode.appendChild(textnode);
                    lv.bodydata.appendChild(spnode);
                    lv.bodydata.appendChild(brnode);
                    continue;
                }

                lv.bodydata.appendChild(textnode);
                lv.bodydata.appendChild(brnode);

            }

        }//end filltabledata

        function filltable(){

            filltableheader();  
            filltabledata();
        }

        if(lineinrange() === false){

            return; 

        } 
        initdiv();
        createtable();
        filltable();  

    }//end displaycb

    params[jlaurino.xmlhttp.RequestParameters.CONTENT_TYPE] = jlaurino.xmlhttp.ContentType.TEXT;

    custparams.parseparams = {};
    custparams.parseparams.linehighlight = linehighlight;
    custparams.parseparams.totallines = totallines;
    custparams.parseparams.msg = msg;

    jlaurino.xmlhttp.readfile(url,params,custparams);
    
}

window.onerror = jl_eh_handleErr;


//////////////// flickrwrapper.js

var gjl_FlickrWrapper = null;

jl_getflickrwrapper = function(){

    if(gjl_FlickrWrapper === null){
          gjl_FlickrWrapper = new jl_Flickrwrapper();
    }

    return gjl_FlickrWrapper;

}

jl_Flickrwrapper = function(){
    
    jlaurino.json.seturl("http://api.flickr.com/services/rest/");
    this.sizetag = null;
    
}



jl_Flickrwrapper.prototype.getcmdobject = function(){
    return jlaurino.json;
}

jl_Flickrwrapper.prototype.setmethod = function(method){
    jlaurino.json.setmethod("method=" + method);
}

jl_Flickrwrapper.prototype.setsizetag = function(tag){

    this.sizetag = tag;

}

jl_Flickrwrapper.prototype.buildclickhref = function(theimginfo){

    if(typeof(theimginfo) === 'undefined'){
	alert("jl_Flickrwrapper.prototype.buildclickhref() invalid image info type " + typeof(theimginfo));
	return null;

    }		

    if(theimginfo === null){
	alert("jl_Flickrwrapper.prototype.buildclickhref() invalid image info null");
	return null;

    }		


    	
    var pglink = "http://www.flickr.com/photos/" + theimginfo.owner + "/" + theimginfo.id;
    return pglink; 
}

jl_Flickrwrapper.prototype.buildimghref = function(theimginfo){

//http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}_[mstb].jpg

    if(typeof(theimginfo) === 'undefined'){
	alert("jl_Flickrwrapper.prototype.buildimghref() invalid image info type " + typeof(theimginfo));
	return null;

    }		

    if(theimginfo === null){
	alert("jl_Flickrwrapper.prototype.buildimghref() invalid image info null");
	return null;

    }		


    var retval = "http://farm" + theimginfo.farm + ".static.flickr.com/" + theimginfo.server + "/" + theimginfo.id + "_" + theimginfo.secret + "_" + this.sizetag + ".jpg"; 
    return retval;  
}



///////////////flickrinfo.js

if(typeof(jlaurino) === 'undefined') jlaurino = {};
if(typeof(jlaurino.flickr) === 'undefined') jlaurino.flickr = {};


jlaurino.flickr.grabflickrkey = function(){

     //return jim Laurino's api key for flickr
     return "0fa8d26ebc31414f1d3ec642baeaedfc";
}

////////////mvcollage.js

var jl_mvcmgr = null;
jl_Imagewrapper = function(image,clickhref){

    //now check to see if param 1 is a string or
    // a javascript image

    if(typeof(image.src) !== 'undefined'){

         this.image = image;
            
    }else{

        this.image = new Image();
        this.image.src = image;
          
    }
 
    this.clickhref = clickhref;

}//end imagewrapper ctor

jl_Imagewrapper.prototype.loadcomplete = function(){
	return this.image.completed;
}


jl_Imagewrapper.prototype.imageloadstatus = function(){
   return this.imageloaded;
}

jl_Imagewrapper.prototype.getimagename = function(){
   return this.image.src;
}

jl_Imagewrapper.prototype.getclickhref = function(){
   return this.clickhref;
}

jl_Imagewrapper.prototype.sethtmlimage = function(theid){
    document.getElementById(theid).src = this.image.src;
}

jl_Imagewrapper.prototype.setclickhref = function(theid){
     document.getElementById(theid).href = this.clickhref;
}



jl_Mvcollagemgr = function(linkcolor,tablewidth,tableheight,updaterate){

    this.procstate = 0;
    this.procckload = 0;
    this.procgntble = 1;         
    this.procanimtble = 2;
    this.procabort = 3;
    this.procThandle = null;
    this.procmseconds = 1000;
    this.tablewidth = tablewidth;
    this.tableheight = tableheight;
    this.tablecellwidth = "100";
    this.tablecellheight = "68";
    this.tablesize = tablewidth*tableheight;
    this.imageheight = -1;
    this.imagewidth = -1;
    this.newwinonclick = false;
    this.imagewrapperarray = new Array(0);
    this.visipicref = null;
    this.invisipicref = null;
    this.updaterate = (updaterate * 1000) + .5;
    this.invisiindex = 0;
    this.linkcolor = linkcolor;

}//end mvcollagemgr ctor

jl_Mvcollagemgr.prototype.getimagename = function(index){
    if(index >= this.tablesize){
          //the user requested a table be created
          //that was larger than num images loaded
          index = 0;

    }     
    return this.imagewrapperarray[index].getimagename();
}

jl_Mvcollagemgr.prototype.setimageheight = function(height){
     this.imageheight = height;
}

jl_Mvcollagemgr.prototype.setimagewidth = function(width){
     this.imagewidth = width;
}

jl_Mvcollagemgr.prototype.settablecellwidth = function(width){
    this.tablecellwidth = width;
} 

jl_Mvcollagemgr.prototype.settablecellheight = function(height){
    this.tablecellheight = height;
}

jl_Mvcollagemgr.prototype.getclickhref = function(index){
    if(index >= this.tablesize){
          //the user requested a table be created
          //that was larger than num images loaded
          index = 0;
    }     
    return this.imagewrapperarray[index].getclickhref();
}

jl_Mvcollagemgr.prototype.numimagesloaded = function(){
    return this.imagewrapperarray.length;
}

jl_Mvcollagemgr.prototype.addimagedata = function (image,clickhref){
    var imgwrapper = new jl_Imagewrapper
(image,clickhref);
    this.imagewrapperarray.push(imgwrapper);
}
 
jl_Mvcollagemgr.prototype.sethtmlimage = function(index,theid){
    this.imagewrapperarray[index].sethtmlimage(theid); 
}

jl_Mvcollagemgr.prototype.setclickhref = function(index,theid){
         this.imagewrapperarray[index].setclickhref(theid); 
}

jl_Mvcollagemgr.prototype.setnewwinonclick = function(val){
      this.newwinonclick = val;
}

jl_Mvcollagemgr.prototype.imageldcomplete = function(){
    var i=0;
    for(i=0;i<this.imagewrapperarray.length;i++){
        if(this.imagewrapperarray[i].loadcomplete() === false){
            return false;
        }   
    }
    return true;
}

jl_Mvcollagemgr.prototype.initimageswapper = function(){

    if(this.numimagesloaded() <= this.tablesize){
         return false;
    }

    this.visipicref = new Array(this.tablesize);
    var invisipicrefsize = this.numimagesloaded() - this.tablesize;

    this.invisipicref = new Array(invisipicrefsize);
    var i = 0;

 
    for(i=0;i<this.visipicref.length;i++){
 
         this.visipicref[i] = i;

    }

    for(i=0;i<this.invisipicref.length;i++){
 
         this.invisipicref[i] = i + this.tablesize;

    }


    return true;
}

jl_Mvcollagemgr.prototype.writeheader = function(header){

    var headernode = document.createElement("h3");
    var txtnode = document.createTextNode(header);
    headernode.appendChild(txtnode); 
    jl_ut_getcontentdiv().appendChild(headernode); 

}

jl_Mvcollagemgr.prototype.gencollage = function(){
        

     var irow=0;
     var icol=0; 
     var idnum = 0;
          
     for(irow=0;irow<this.tableheight;irow++){
             
         jl_ut_getcontentdiv().appendChild(document.createElement("br"));
 
         for(icol=0;icol<this.tablewidth;icol++){

              var aAnchor = document.createElement("a");
              var aHtmlImage = document.createElement("img");

              if(this.newwinonclick){
                  aAnchor.target = "_blank";
              } else {
                  aAnchor.target = "_self";
              }  

              aAnchor.style.color = this.linkcolor;
              aAnchor.id = "mvchref" + String(idnum); 
              aAnchor.href = this.getclickhref(idnum); 
              aHtmlImage.id = "mvcimg" + String(idnum); 

              if(this.imageheight !== -1){
                  aHtmlImage.height = this.imageheight;
              } 

              if(this.imagewidth !== -1){
                  aHtmlImage.width = this.imagewidth;
              }
 
              aHtmlImage.src = this.getimagename(idnum); 
              aAnchor.appendChild(aHtmlImage);

              jl_ut_getcontentdiv().appendChild(aAnchor);
              idnum++;  

          }

              
     }

     return true;
}

jl_Mvcollagemgr.prototype.killanimthread = function(){
    window.clearTimeout(this.procThandle);
}

jl_Mvcollagemgr.prototype.procstartrun = function(mseconds){

    this.procstate = this.procckload;
    this.procmseconds = mseconds;

    if(this.procThandle !== null){
        window.clearTimeout(this.procThandle);
        this.procThandle = null;
    }
        
    jl_mvcprocrun();
}


jl_Mvcollagemgr.prototype.procrun = function(){
    
    switch(this.procstate){

        case this.procckload:

               if(this.imageldcomplete() === true){
                   this.procstate = this.procgntble;  
               }
               this.procmseconds = 500; 
               break;

        case this.procgntble:
                   
               if(this.initimageswapper() === false){
                   this.procmseconds = 500; 
                   return;
               }
                       
               if(this.gencollage() === false){
                   jl_ut_getcontentdiv().innerHTML += "<p>Not enough images loaded to create table. Must be more images loaded than size of table.</p>";

                    this.procstate = this.procabort;
                    return;

               }
                     

               this.procstate = this.procanimtble;
               this.procmseconds = this.updaterate; 
               break;

        case this.procanimtble:
              
               this.tableupdater(0); 
               break;

    }
}


jl_Mvcollagemgr.prototype.tableupdater = function(){

    if(this.invisipicref === null) return;
 
     var visiindex = jl_ut_randomize(0,(this.visipicref.length - 1));

     var invisiindex = this.invisiindex;

     var imgid = "mvcimg" + String(visiindex);
     var imgwrap = this.imagewrapperarray[this.invisipicref[invisiindex]]; 

     var clickhrefid = "mvchref" + String(visiindex);
     imgwrap.sethtmlimage(imgid);
     imgwrap.setclickhref(clickhrefid);

     //swap visible and invisible references
     var oldvisiref = this.visipicref[visiindex];
     this.visipicref[visiindex] = this.invisipicref[invisiindex];
     this.invisipicref[invisiindex] = oldvisiref;

     this.invisiindex +=  1;
     if(this.invisiindex >= this.invisipicref.length){
         this.invisiindex = 0;
     }

}

jl_Mvcollagemgr.prototype.abortthread = function(){

    return (this.procstate === this.procabort);       

}

jl_Mvcollagemgr.prototype.initthreadtimer = function(){

    this.procThandle = window.setTimeout(jl_mvcprocrun,this.procmseconds);

}



jl_mvcprocrun = function(){

     if(jl_mvcmgr === null){
         return;
     }
    
     if(jl_mvcmgr.abortthread() === false){
         
         jl_mvcmgr.procrun();
         jl_mvcmgr.initthreadtimer();
             
     }
},

jl_createmvcmgr = function(linkcolor,tablewidth,tableheight,updaterate){

      if(jl_mvcmgr=== null){
          jl_mvcmgr = new jl_Mvcollagemgr(linkcolor,tablewidth,tableheight,updaterate);
      }else{

         jl_mvcmgr.killanimthread();
         //just reinit it for now.
         jl_mvcmgr = new jl_Mvcollagemgr(linkcolor,tablewidth,tableheight,updaterate);

      } 
 
      return jl_mvcmgr;

}



////////////jsoncmd.js

if(typeof jlaurino === 'undefined') jlaurino = {};
if(typeof(jlaurino.json) === 'undefined') jlaurino.json = {};

jlaurino.json.url = "";
jlaurino.json.args = "";
jlaurino.json.method = "";

jlaurino.json.addarg  = function(cmd,arg){

    this.args += "&" + cmd + "=" + arg;
}
jlaurino.json.clearargs = function(){
    this.args = "";
}

jlaurino.json.seturl = function(txt){
    this.url = txt;
}

jlaurino.json.setmethod = function(txt){
    this.method = txt;
}

jlaurino.json.setargs = function(txt){
    this.args = txt;
}

jlaurino.json.getcommandline = function(){
    var cmdline =  this.url + "?"  +  this.method + this.args;  
    return cmdline;
}


jlaurino.json.sendcommand = function(){

    var headid = document.getElementsByTagName("head")[0];
    var newscript = document.createElement("script");
    newscript.type = "text/javascript";
    newscript.src = this.getcommandline();
    headid.appendChild(newscript);
    this.clearargs();

} 

/////////utils.js

String.prototype.entityify = function () {
    return this.replace(/&/g, "&amp;").replace(/</g,        "&lt;").replace(/>/g, "&gt;");
};

String.prototype.quote = function () {
    var c, i, l = this.length, o = '"';
    for (i = 0; i < l; i += 1) {
        c = this.charAt(i);
        if (c >= ' ') {
            if (c === '\\' || c === '"') {
                o += '\\';
            }
            o += c;
        } else {
            switch (c) {
            case '\b':
                o += '\\b';
                break;
            case '\f':
                o += '\\f';
                break;
            case '\n':
                o += '\\n';
                break;
            case '\r':
                o += '\\r';
                break;
            case '\t':
                o += '\\t';
                break;
            default:
                c = c.charCodeAt();
                o += '\\u00' + Math.floor(c / 16).toString(16) +
                    (c % 16).toString(16);
            }
        }
    }
    return o + '"';
};

String.prototype.trim = function () {
    return this.replace(/^\s+|\s+$/g, "");
}; 

jl_ut_randomize = function(lownum,highnum){

      var retnum = Math.round((highnum - lownum) * Math.random());
      return lownum + retnum; 
}

jl_ut_contentdiv = null;

jl_ut_setcontentdiv = function(thediv){

    jl_ut_contentdiv = thediv;
}

jl_ut_getcontentdiv = function(){

    return jl_ut_contentdiv;
}

//swiped from Douglas Crockford's site
jl_ut_typeOf = function(value){

    var s = typeof value;
    if (s === 'object') {
        if (value) {
            if (typeof value.length === 'number' &&
                    !(value.propertyIsEnumerable('length')) &&
                    typeof value.splice === 'function') {
                s = 'array';
            }
        } else {
            s = 'null';
        }
    }
    return s;
}

jl_ut_initddarray = function(numouter,numinner) {

     var thearray = new Array(numouter);
     var i=0;
     for(i=0;i<numouter;i++){
         thearray[i] = new Array(numinner);
     }

     return thearray;
}


jl_ut_cleararray = function(thearray){
     
    while(thearray.length > 0) {
        thearray.pop();            
    }
}

jl_ut_catarray = function(toarray,fromarray){
    var i=0;
    for(i=0;i<fromarray.length;i++) {
        toarray.push(fromarray[i]);            
    }
}


/////////

var gFlickrparams = {};
gFlickrparams.username = null;
gFlickrparams.numpicstoload = 0;

var gGadgetdoc = null;


function setdisplaycolors(bgcolor,txtcolor){

    var divid = jl_ut_getcontentdiv();

    divid.style.backgroundColor=bgcolor;
    divid.style.color=txtcolor;
    divid.color = txtcolor;
    document.body.style.backgroundColor=bgcolor;
    document.body.style.color=bgcolor;


}

function initflickrtable(tabletype,header){
        
    var tablecols = 0;
    var tablerows = 0;  
    var updaterate = 1.5;
    
 
    if(tabletype === "1x1"){
          tablecols = 1;
          tablerows = 1;
          updaterate = 2.5;
    } else if(tabletype === "1x2"){
          tablecols = 1;
          tablerows = 2;
          updaterate = 2.0;
    }else if(tabletype === "2x1"){
          tablecols = 2;
          tablerows = 1;
          updaterate = 2.0;
    }else if(tabletype === "2x2"){
          tablecols = 2;
          tablerows = 2;
          updaterate = 1.5;
    }else {
          tablecols = 1;
          tablerows = 2;
          updaterate = 2.0;
    }
  
    var divid = jl_ut_getcontentdiv();
    var mvcmgr = jl_createmvcmgr(divid.style.color,tablecols,tablerows,updaterate);

    if(header !== null){
       
       header.entityify(); 
       mvcmgr.writeheader(header);
    
    }
  
    mvcmgr.setnewwinonclick(true);
    var flickit = jl_getflickrwrapper();
    var cmdobject = flickit.getcmdobject();

    if(gFlickrparams.username !== null){



	flickit.setmethod("flickr.people.findByUsername");
	cmdobject.addarg("api_key","0fa8d26ebc31414f1d3ec642baeaedfc");
	cmdobject.addarg("username",gFlickrparams.username);
	cmdobject.addarg("format","json");
	cmdobject.addarg("jsoncallback","flkr_getusernamersp");	
	cmdobject.sendcommand();

     }else{

    
	flickit.setsizetag("s");        
	flickit.setmethod("flickr.photos.search");
	
	cmdobject.addarg("api_key","0fa8d26ebc31414f1d3ec642baeaedfc");
	cmdobject.addarg("format","json");
	cmdobject.addarg("jsoncallback","flkr_tagsearchjsonrsp");
    
	if(gFlickrparams.tags !== null){
		
		cmdobject.addarg("tags",gFlickrparams.tags);
	}

	cmdobject.addarg("per_page",gFlickrparams.numpicstoload);
	cmdobject.sendcommand();


     }	




}

var gPrefs = new gadgets.Prefs();

function displayit(){

     
     gFlickrparams.tags = gPrefs.getString("tags");


     if(gFlickrparams.tags === ""){

	gFlickrparams.tags = null;
     }



     gFlickrparams.username = gPrefs.getString("username");

     if(gFlickrparams.username === ""){

	gFlickrparams.username = null;
     }

     var header = gPrefs.getString("caption");
     var bgcolortext=gPrefs.getString("bgcolor");
     var colortext = gPrefs.getString("txtcolor");
     var tabledimstext=gPrefs.getString("tabledims");
     var numpicsloadedtxt=gPrefs.getString("numpicstoload");

     gFlickrparams.numpicstoload = Number(numpicsloadedtxt);

     jl_ut_setcontentdiv(document.getElementById("thediv"));
     jl_ut_getcontentdiv().innerHTML = "";

     setdisplaycolors(bgcolortext,colortext,null);
 
     initflickrtable(tabledimstext,header);

}


flkr_getusernamersp = function(rsp){



    if(rsp.stat !== "ok"){

          flkr_getusernamefail(rsp);
          return;
    }  
        
    var flickit = jl_getflickrwrapper();
    var cmdobject = flickit.getcmdobject();

    flickit.setsizetag("s");        
    flickit.setmethod("flickr.photos.search");

    cmdobject.addarg("user_id",rsp.user.nsid);
    cmdobject.addarg("api_key","0fa8d26ebc31414f1d3ec642baeaedfc");
    cmdobject.addarg("format","json");
    
    cmdobject.addarg("user_id",rsp.user.nsid);
    cmdobject.addarg("jsoncallback","flkr_tagsearchjsonrsp");
    
    if(gFlickrparams.tags !== null){
	cmdobject.addarg("tags",gFlickrparams.tags);
    }

    cmdobject.addarg("per_page",gFlickrparams.numpicstoload);
    cmdobject.sendcommand();
       


}


flkr_tagsearchjsonrsp = function(rsp){
    

    if(rsp.stat !== "ok"){

          flkr_tagsearchfail(rsp);
          return;
    }  
        
    var imglist = flkr_successsearchbytags(rsp);
        
    if(imglist === null){
         return;
    }
        
    for(i=0;i<imglist.length;i+=1){

        jl_mvcmgr.addimagedata(imglist[i],imglist[i].clickhref);

    }//end for
        
    jl_mvcprocrun();
       


}

flkr_getusernamefail = function(rsp){

    //username not found so just use the tags
    var flickit = jl_getflickrwrapper();
    var cmdobject = flickit.getcmdobject();

    flickit.setsizetag("s");        
    flickit.setmethod("flickr.photos.search");

    cmdobject.addarg("api_key","0fa8d26ebc31414f1d3ec642baeaedfc");
    cmdobject.addarg("format","json");
    cmdobject.addarg("jsoncallback","flkr_tagsearchjsonrsp");
    
    if(gFlickrparams.tags !== null) cmdobject.addarg("tags",gFlickrparams.tags);

    cmdobject.addarg("per_page",gFlickrparams.numpicstoload);
    cmdobject.sendcommand();
 

}


flkr_tagsearchfail = function(rsp){

    var divid = jl_ut_getcontentdiv()

    divid.innerHTML  = "flickr api call failed.<br/>";
    divid.innerHTML  += "stat " + rsp.stat + " code " + rsp.code + " message " + rsp.message + "<br/>";
    divid.innerHTML  += "If user name field is used be certain that it is a valid user on flickr.<br/>";
 

}


flkr_successsearchbytags = function(rsp){

    var divid = jl_ut_getcontentdiv();
    var imglist = new Array(0);
    var flickit = jl_getflickrwrapper();
                
    if((rsp.photos.total < 6) || 
        (rsp.photos.pages === 0) || (rsp.photos.photo === undefined)){

        divid.innerHTML = "failed call to flickr api - not enough photos found to animate table.<br/>";
	divid.innerHTML += "Possible causes - the user name has no photos or none with the specified tags<br/>";
	divid.innerHTML += "You can specify a user name with no tags, this will use all photos from that user<br/>";
	divid.innerHTML += "You can also use search tags only and leave the user name blank.<br/>";
	divid.innerHTML += "using no user name searches the entire flickr pool using the specified tags.<br/>";
      
        return null;

    }

    var i=0;
    

    if(rsp.photos.perpage > rsp.photos.total){

	rsp.photos.perpage = rsp.photos.total;

    }
 
    for(i=0;i<rsp.photos.perpage;i++){

        //hack! there is an intermittent bug in which one or more of
        //the photos come up null. this prevents a crash
        if((typeof(rsp.photos.photo[i]) === 'undefined') || (rsp.photos.photo[i] === null)) continue;

        var img = new Image();
        
        img.src =  flickit.buildimghref(rsp.photos.photo[i]);
        img.clickhref = flickit.buildclickhref(rsp.photos.photo[i]);   
        imglist.push(img);
          
    }

    return imglist;

}


gadgets.util.registerOnLoadHandler(displayit);


 
</script>


<div id = "thediv" class = "content"></div>



    ]]>
  </Content>
</Module>