//Developed by Carlos Lacayo
//September 29,2009
//University of Houston-Downtown | Scholars Academy
//The purpose of this JavaScript file is to create a function that will able to view pictures larger without opening a new html file
//Questions or pregunta, email me at lacayoc@gmail.com

function ImageExpander(oThumb, sImgSrc)
{
   // store thumbnail image and overwrite its onclick handler.
   this.oThumb = oThumb;
   this.oThumb.expander = this;
   this.oThumb.onclick = function() { this.expander.expand(); }

   // record original size
   this.smallWidth = oThumb.offsetWidth;
   this.smallHeight = oThumb.offsetHeight;    
   // initial settings
   this.bExpand = true;
   this.bTicks = false;

   // insert into self organized list
   if ( !window.aImageExpanders )
      window.aImageExpanders = new Array();
	  
   window.aImageExpanders.push(this);

   // create the full sized image and automatically expand when loaded
   this.oImg = new Image();
   this.oImg.expander = this;
   this.oImg.onload = function(){this.expander.onload();}
   this.oImg.src = sImgSrc;
}



ImageExpander.prototype.onload = function()

{
   this.oDiv = document.createElement("div");
   document.body.appendChild(this.oDiv);
   this.oDiv.appendChild(this.oImg);
   this.oDiv.style.position = "absolute";
   this.oDiv.expander = this;
   this.oDiv.onclick = function(){this.expander.toggle();};
   this.oImg.title = "Click to reduce.";
   this.bigWidth = this.oImg.width;
   this.bigHeight = this.oImg.height;
   
   if ( this.bExpand )
   {
      this.expand();
   }
   else
   {
      this.oDiv.style.visibility = "hidden";
      this.oImg.style.visibility = "hidden";
   }
}



ImageExpander.prototype.toggle = function()
{
   this.bExpand = !this.bExpand;
   if ( this.bExpand )
   {
      for ( var i in window.aImageExpanders )
         if ( window.aImageExpanders[i] !== this )
            window.aImageExpanders[i].reduce();
   }
}
