function MiramapaTransicion(curva,ms,callback){
    this.ant=0.01;
    this.done_=false;
    var _this=this;
    this.start=new Date().getTime();
    this.init=function(){
        setTimeout(function(){
                if(!_this.next()){
                    callback(1);
                    _this.done_=true;
                    window.globalIntervalo=0;
                    return;
                }
                callback(_this.next());
                _this.init();
            },13);
    }
    this.next=function(){
        var now=new Date().getTime();
        if((now-this.start)>ms)
            return false;
        return this.ant=curva((now-this.start+.001)/ms,this.ant);
    }
}
function setClosePopup(o,inicioL,finL,inicioT,finT,inicioH,finH,inicioW,finW){
    
		//var playerYT = document.getElementById('reproductorYT');
	 	
        o.obj.style.height = finH + 'px';
        o.obj.style.width = finW + 'px';
        
        o.contenedor.style.height = finH + 'px';
        o.contenedor.style.width = finW + 'px';
        
        o.centro.style.height = finH - 46+'px';
        o.centro.style.width = finW - 46+'px';
        
        o.latSup.style.width = finW - 46 +'px';
    	o.latInf.style.width = finW -46 +'px';
    	o.latDer.style.height = finH - 46  +'px';
    	o.latIzq.style.height = finH - 46 +'px';
    	
    	//if(  playerYT )playerYT.style.width = "140px";
    	//if(  playerYT )playerYT.style.height = "75px";
    	//if( playerYT )playerYT.stopVideo();
    	o.ocultarObj(o.obj);
    	o.visualizarObj(o.pico);
    	//Activamos el drag&drop del mapa para que no se puede mover mientras que este abierta la ventana maximizada
    	map.enableDragging();
    	
 
}
function closePopup(o,inicioL,finL,inicioT,finT,inicioH,finH,inicioW,finW){
    
	var t = new MiramapaTransicion(desacelerado,1000,function(p){ 
		
        o.obj.style.left = inicioL+((finL-inicioL)*p)+'px';
        o.obj.style.top = inicioT+((finT-inicioT)*p)+'px';
        o.obj.style.height = inicioH+((finH-inicioH)*p)+'px';
        o.obj.style.width = inicioW+((finW-inicioW)*p)+'px';
        
        o.contenedor.style.height = inicioH+((finH-inicioH)*p)+'px';
        o.contenedor.style.width = inicioW+((finW-inicioW)*p)+'px';
        
        o.centro.style.height = (inicioH+((finH-inicioH)*p))- 46+'px';
        o.centro.style.width = (inicioW+((finW-inicioW)*p))- 46+'px';
        
        o.latSup.style.width = (inicioW+((finW-inicioW)*p))- 46 +'px';
    	o.latInf.style.width = (inicioW+((finW-inicioW)*p))- 46 +'px';
    	o.latDer.style.height = (inicioH+((finH-inicioH)*p))- 46  +'px';
    	o.latIzq.style.height = (inicioH+((finH-inicioH)*p))- 46 +'px';
    	
    	if(inicioW+((finW-inicioW)*p) == finW){
    			o.ocultarObj(o.obj);
    			o.visualizarObj(o.pico);
    			//Activamos el drag&drop del mapa para que no se puede mover mientras que este abierta la ventana maximizada
    			map.enableDragging();
    	}
    });
    t.init();
    t=null;
}
function moverPopup(o,obj,inicioL,finL,inicioT,finT,inicioH,finH,inicioW,finW,esCliente){
	 
	 
	 var t = new MiramapaTransicion(desacelerado,1000,function(p){ 
        
		o.obj.style.left = inicioL+((finL-inicioL)*p)+'px';
        o.obj.style.top = inicioT+((finT-inicioT)*p)+'px';
        o.obj.style.height = inicioH+((finH-inicioH)*p)+'px';
        o.obj.style.width = inicioW+((finW-inicioW)*p)+'px';
        
        o.contenedor.style.height = inicioH+((finH-inicioH)*p)+'px';
        o.contenedor.style.width = inicioW+((finW-inicioW)*p)+'px';
        
        o.centro.style.height = (inicioH+((finH-inicioH)*p))- 46+'px';
        o.centro.style.width = (inicioW+((finW-inicioW)*p))- 46+'px';
        
        o.latSup.style.width = (inicioW+((finW-inicioW)*p))- 46 +'px';
    	o.latInf.style.width = (inicioW+((finW-inicioW)*p))- 46 +'px';
    	o.latDer.style.height = (inicioH+((finH-inicioH)*p))- 46  +'px';
    	o.latIzq.style.height = (inicioH+((finH-inicioH)*p))- 46 +'px';
    	
    	var playerYTF = document.getElementById('fotoVideoYoutube');
	   	if(  playerYTF != null ){
	   		
	   			playerYTF.style.width = (inicioW+((finW-inicioW)*p)) - 280  +'px';
	   		
	   			playerYTF.style.height = (inicioH+((finH-inicioH)*p)) - 150  +'px';
	   	}		
	   	
	  if(inicioW+((finW-inicioW)*p) == finW){
		  	var videoH = parseInt(finH / 1.8);
		  	var videoW = parseInt(finW / 1.8);
		  	if(finW > finH){
		  		
		  		videoH = parseInt(videoW * 0.66666);
		  		if(esCliente)miramapaPopup.fotos.innerHTML = miramapaPopup.getVideo(videoW,videoH,obj);
		  		else miramapaPopup.fotos.innerHTML = miramapaPopup.getVideoNoCliente(videoW,videoH,obj);
		  		
		  	} else {
		  		
		  		videoW = parseInt(videoH / 0.66666);
		  		
		  	}
	   }	
    });
    t.init();
    t=null;
}

function desacelerado(p,ant){
    var maxValue=1, minValue=.001, totalP=1, k=.25;
    var delta = maxValue - minValue; 
    var stepp = minValue+(Math.pow(((1 / totalP) * p), k) * delta); 
    return stepp; 
}

function linear(p,a){
    return p;
}
function fx(obj,efectos,ms,cola,curva){
	
    if(!window.globalIntervalo)
        window.globalIntervalo=1;
    else {
        if(cola)
            return setTimeout(function(){fx(obj,efectos,ms,cola,curva)},30);
        else
            return;
    }    
    var t=new MiramapaTransicion(
    curva,ms,function(p){
        for (var i=0;efectos[i];i++){
            if(efectos[i].fin<efectos[i].inicio){
                var delta=efectos[i].inicio-efectos[i].fin;
                obj.style[efectos[i].propCSS]=(efectos[i].inicio-(p*delta))+efectos[i].u;
                if(efectos[i].propCSS=='opacity'){
                    obj.style.zoom=1;
                    obj.style.MozOpacity = (efectos[i].inicio-(p*delta));
                    obj.style.KhtmlOpacity = (efectos[i].inicio-(p*delta));
                    obj.style.filter='alpha(opacity='+100*(efectos[i].inicio-(p*delta))+')';
                }
            }
            else{
                var delta=efectos[i].fin-efectos[i].inicio;
                obj.style[efectos[i].propCSS]=(efectos[i].inicio+(p*delta))+efectos[i].u;
                if(efectos[i].propCSS=='opacity'){
                    obj.style.zoom=1;
                    obj.style.MozOpacity = (efectos[i].inicio+(p*delta));
                    obj.style.KhtmlOpacity = (efectos[i].inicio+(p*delta));
                    obj.style.filter='alpha(opacity='+100*(efectos[i].inicio+(p*delta))+')';
                }
            }
        }
        
    });
    t.init();
    t=null;
}
