//Ing Alexis Ramiro Hernandez Bautista FRAYAL2008
//Fecha: 22/03/2008
var zoom = 4;
var speed = 4;
var real = 1;
var intervalIn;
var divs;

function cambiar_album(cmb){
  var spanres= document.getElementById("divfotos");
  ajax=NuevoAjax();
  ajax.open("post", "fotos.php",true);  
  ajax.onreadystatechange=function(){
          if(ajax.readyState==1){
			  		spanres.innerHTML="";
                    spanres.style.background = "url('img/loading.gif') no-repeat";
                }else if(ajax.readyState==4){
                        if(ajax.status==200){
								spanres.style.background="";
								//alert(ajax.responseText);
								spanres.innerHTML=ajax.responseText;
								load_imagealbum();
								initLytebox();
						}else if(ajax.status==404){
                                spanres.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;La página no existe";
                        }else{
                                spanres.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Error:" + ajax.status; 
                        }
                }
        }
 ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
 ajax.send("album="+cmb.value);
}

function load_imagealbum()
{
divs = document.getElementsByTagName('div');
for (var i=0; i<divs.length; i++)
{
  if (divs[i].id == 'livethumbnail')
  {
	var myimg = divs[i].getElementsByTagName('img')[0];	
	myimg.smallSrc = myimg.getAttribute('src');
	myimg.smallWidth = parseInt(myimg.getAttribute('width'));
	myimg.smallHeight = parseInt(myimg.getAttribute('height'));
	divs[i].onmouseover = scaleIn;
	divs[i].onmouseout = scaleOut;
	if (!myimg.smallWidth)
    {
	myimg.smallWidth=100;
	myimg.smallHeight=100;
    real = 0;
    }
    else
    {
  	  real = 1;
    }
  }
}

function scaleIn()
{
  var myimg = this.getElementsByTagName('img')[0];
  this.style.zIndex = 20;
  myimg.src = myimg.smallSrc;
  //alert(myimg.smallWidth + " - " + myimg.smallSrc);
  var count = 0;
  var real = 0;
  intervalIn = window.setInterval(scaleStepIn, 1);
  return false;

function scaleStepIn()
  {
	var widthIn = parseInt(myimg.style['width']);
	var heightIn = parseInt(myimg.style['height']);
	var topIn = parseInt(myimg.style['top']);
	var leftIn = parseInt(myimg.style['left']);
	if(widthIn >= heightIn) {
	  widthIn += speed;
	  heightIn += Math.floor(speed * (3/4));
	  topIn -= (Math.floor(speed * (3/8)));
	  leftIn -= (speed/2);
	}
	else
	{
	  widthIn += Math.floor(speed * (3/4));
	  heightIn += speed;
	  topIn -= (speed/2);
	  leftIn -= (Math.floor(speed * (3/8)));
	}
	myimg.style['width'] = widthIn + "px";
	myimg.style['height'] = heightIn + "px";
	myimg.style['top'] = topIn + "px";
	myimg.style['left'] = leftIn + "px";
	count++;
  	//alert("scalein src " + myimg.src + " count " + count + " zoom " + zoom );	
	if (count >= zoom)
	  window.clearInterval(intervalIn);
  }			

}


function scaleOut()
{
  window.clearInterval(intervalIn);
  var myimg = this.getElementsByTagName('img')[0];
  myimg.src = myimg.smallSrc;
  this.style.zIndex = 10;
  var mydiv = this;
  var interval = window.setInterval(scaleStepOut, 1);
  return false;

  function scaleStepOut()
  {
	var width = parseInt(myimg.style['width']);
	var height = parseInt(myimg.style['height']);
	var top = parseInt(myimg.style['top']);
	var left = parseInt(myimg.style['left']);
	if(width >= height) {
	  width -= speed;
	  height -= Math.floor(speed * (3/4));
  	  if(width < myimg.smallWidth + 4) {
	    myimg.style['width'] = myimg.smallWidth + "px";
	    myimg.style['height'] = myimg.smallHeight + "px";
	    myimg.style['top'] = "0px";
	    myimg.style['left'] = "0px";
		mydiv.style['zIndex'] = 1;
		window.clearInterval(interval);
	  }
	  else{
	    myimg.style['width'] = width + "px";
	    myimg.style['height'] = height + "px";
	    myimg.style['left'] = (left + (speed/2)) + "px";
	    myimg.style['top'] = (top + (Math.floor(speed * (3/8)))) + "px";
	  }
	}
	else
	{
	  width -= Math.floor(speed * (3/4));
	  height -= speed;
	  if(real==1)
	  {
	    if(width < myimg.smallWidth + 4)
	    {
	      myimg.style['width'] = myimg.smallWidth + "px";
	      myimg.style['height'] = myimg.smallHeight + "px";
		  myimg.style['top'] = "0px";
	      myimg.style['left'] = "0px";
		  mydiv.style['zIndex'] = 1;
	      window.clearInterval(interval);
		}
		else{
		  myimg.style['width'] = width + "px";
	      myimg.style['height'] = height + "px";
	      myimg.style['top'] = (top + (speed/2)) + "px";
	      myimg.style['left'] = (left + (Math.floor(speed * (3/8)))) + "px";
		}
	  }
	  else
	  {
	  	if(height < myimg.smallWidth + 4)
	    {
	      myimg.style['width'] = myimg.smallHeight + "px";
	      myimg.style['height'] = myimg.smallWidth + "px";
		  myimg.style['top'] = "0px";
	      myimg.style['left'] = "0px";
		  mydiv.style['zIndex'] = 1;
	      window.clearInterval(interval);
		}
		else{
		  myimg.style['width'] = width + "px";
	      myimg.style['height'] = height + "px";
	      myimg.style['top'] = (top + (speed/2)) + "px";
	      myimg.style['left'] = (left + (Math.floor(speed * (3/8)))) + "px";
		}
	  }
	}	  
  }
}


}

