// JavaScript Document

j.fn.center = function () {
    
    this.css("position","absolute");
    
    if(this.height() > j(window).height()){
       this.css("top", j(window).scrollTop() +  "px");
    }else{
        this.css("top", ( j(window).height() - this.height() ) / 2+j(window).scrollTop() + "px");    
    }
    
    if(this.width() > j(window).width() ){
       this.css("left", j(window).scrollLeft() + "px");    
    }else{
       this.css("left", ( j(window).width() - this.width() ) / 2+j(window).scrollLeft() + "px");    
    }
    
    return this;
}

function addLightBoxEffects(e){
    
    j(e).center();    
  /*  j(e).draggable({ cancel:''}); */
    
    j(document).keyup(function(ev) {
        // ESCAPE key pressed
            if (ev.which  == 27) {
                lightServiciosOff();
            }
            return true;
    });
    
    
   // alert(" e->(800) "+j(e).width()+" >= " + j(window).width()  );
    /*
    alert(j(window).html());
    */
    
    // windwos small
    if( 800 >= j(window).width() ){
        // fix to 800
       j(e).addClass('lightbox-small');         
       
       j(e).width(j(window).width());
       j(e).children("#lightBoxContent").width(j(window).width()-15);
       
    }else{
       j(e).removeClass('lightbox-small');          
       j(e).children("#lightBoxContent").width(785);
       j(e).width(800);
    }
    
}


function lightServiciosOn(){
	document.getElementById('lightbox_servicios').style.display='block'; 
	document.getElementById('fondo').style.display='block';	
    
    addLightBoxEffects(j('#lightbox_servicios'));
}    
    
	
function lightServiciosOff(){
	document.getElementById('lightbox_servicios').style.display='none'; 
	document.getElementById('fondo').style.display='none';	}
	

function lightProxOn(){
	document.getElementById('lightbox_prox').style.display='block'; 
	document.getElementById('fondo-prox').style.display='block';	}
	
function lightProxOff(){
	document.getElementById('lightbox_prox').style.display='none'; 
	document.getElementById('fondo-prox').style.display='none';	}
	
function lightAddProdOn( $box_id, $qty ){
	boxLoadAction(
				'lightbox_addprod',
				'boxClass',
				'ajax/lightboxAddProd.php',
				'prodID='+$box_id+'&prodQty='+$qty+'&rand='+Math.random()
			);
	document.getElementById('lightbox_addprod').style.display='block'; 
	document.getElementById('fondo-prox').style.display='block';	}
	
function lightAddProdOff(){
	document.getElementById('lightbox_addprod').style.display='none'; 
	document.getElementById('fondo-prox').style.display='none';	}
	
function lightStockOn(){
	document.getElementById('lb-out-stock').style.display='block'; 
	document.getElementById('fondo-prox').style.display='block';	}
	
function lightStockOff(){
	document.getElementById('lb-out-stock').style.display='none'; 
	document.getElementById('fondo-prox').style.display='none';	}
	
