function StartGallery(img){

    collect_gallery(img);

}

function toronto_models(num){

  var xmlhttp = new xmlhttprequest();

    var statechanged = function(){

           if(xmlhttp.readyState == 4 ){

               var str = xmlhttp.responseText.split(":");
               var amount = (num == 10) ? 10 : str.length -1;
               var div = document.createElement("div");
               div.id = "quick_teasers";
               //div.setAttribute("class","quick_teasers");
               //$(div).css("margin","0 0 20px 0");
               TFD("#page_content").appendChild(div);
               var delay = 250;
               for(var i = 0; i < amount ; i++){


                    var img = new Image();
                    img.source = str[i];

                    var eleimg = document.createElement("img");
                    eleimg.src = img.source;
                    //$(eleimg).css({"margin":"10px 5px 0 0","border":"2px solid #cc9933"});
                    eleimg.onclick = function(){
                         var ig = this.src.replace("thumbs/","photos/");
                         //alert(this.src);
                         var ig1 = new Image();
                         ig1.src = ig;

                         StartGallery(ig1);

                    }
                    eleimg.style.height = 175+"px";
                    eleimg.style.width = 125+"px";

                    div.appendChild(eleimg);
                    $(eleimg).hide();
                    $(eleimg).delay(delay).fadeIn(1000);
                    delay += 125;

                    //document.write("<img src='"+img+"'>");

               }


            }else{

            }
    }

var url = "config/ajax.php";
var params = "toronto_models=true";
//var send = new Ajax(xmlhttp,url,params,statechanged);
xmlhttp.open("POST",url, true);
//Send the proper header information along with the request
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length",params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.onreadystatechange = statechanged;
xmlhttp.send(params);
}

function collect_gallery(img){

  var xmlhttp = new xmlhttprequest();//Initiate XMLHttp Request


  var func = this;

    var statechanged = function(){
            Gallery.numImgs = 0;
            Gallery.Images = {};

           //Call Back to the server is successful and completed
           if(xmlhttp.readyState == 4 && xmlhttp.statusText == "OK" ){


              //Split the response from server into an Array
              Gallery.tempPhotos = xmlhttp.responseText.split(":");//response from server is a list of all image paths separated by a :



              //Loop through array to add Photos to Gallery.photos and do a little cleaning if necassary
              for(var i = 0; i < Gallery.tempPhotos.length; i++){

                  if(Gallery.tempPhotos[i] != ""){//check that the element if not empty in case of server side error
                    var newImage = new Image();
                    newImage.src = Gallery.tempPhotos[i].replace(" ","%20");
                    Gallery.Images[i] = newImage;//check for spaces in names

                    Gallery.numImgs++;
                  }

              }
              //Loop Finished Gallery.photos Array complete and ready for use



              //Every thing is ready, time to display the Outer Gallery Holder
              //****************************************************************
              //****************************************************************
            (typeof img == "object") ? Gallery.addListener(img) : Gallery.addListener(Gallery.Images[0]);
            }
    }
var model = (typeof img != "object") ? "&model="+img : false;
var d = new Date();//make new date to have new call back to the server
var t = d.getTime();//get the time in seconds
var url = "config/ajax.php";//path to where the Server Side coding
var params = "gallery=true"+model+"&t="+t;//parameters Gallery true is for the server to Listen out for
var send = new Ajax(xmlhttp,url,params,statechanged);//Start Ajax Callback
}
//******************************************************************************
