function Gallery(){
  // Dimensiones
  var _s1 = 640,_s2 = 480,_pad=3;
  var _images = new Array();

  // Abro popup con la imagen ampliada
  this.OpenPopUp = function(i){
                     if(i<0)i=0;else if((_images.length-1)<i)i=_images.length-1;
                     var obj = _images[i];
                     var html = '';
                         html+= '<div class="gallery-content">';
                         if(0<i)
                           html+= ' <span class="prev"></span>';
                         if(i<(_images.length-1))
                           html+= ' <span class="next"></span>';
                         html+= ' <img src="'+obj.imgSrc+'" alt="'+obj.desc+'" />';
                         html+= ' <em>'+obj.desc+'</em>';
                         html+= '</div>';
                     var w,h;
                     if(obj.type=='wide'){w=_s1;h=_s2;}
                     else{w=_s2;h=_s1;}
                     //agrego padding
                     w+=2*_pad;
                     h+=2*_pad;
                     // Lanzo popup
                     if(PopUpActive!=null)PopUpActive.Close();
                     new PopUp(html,_GetJs(w,h,i),'normal',false,'.close',w,h);
                   }
  //  Retorna tipo de imagen: wide o vertical
  var _ImgType = function(a){
                    var type = 'wide';
                    var imgClass = $('img',a).attr('class');
                    if(imgClass=='vertical')
                      type = 'vertical';
                    return type;
                 }
  // Codigo js que debe correrse alabrir el popup
  var _GetJs = function(w,h,i){
                 var next = parseInt(i)+1;
                 var prev = parseInt(i)-1;
                 var JS ="";
                     JS+="$('span.prev',PopUpActive._divContent).click(function(){gallery.OpenPopUp('"+prev+"');}).css({'top':'"+parseInt(h/2-13)+"px'});";
                     JS+="$('span.next',PopUpActive._divContent).click(function(){gallery.OpenPopUp('"+next+"');}).css({'top':'"+parseInt(h/2-13)+"px'});";
                     JS+="$('em',PopUpActive._divContent).css({'width':'"+parseInt(w)+"px'});";
                 return JS;
               }
  var self = this;
  $('.images-gallery .row .img-item a,.galeria a').each(function(i){
    var a = $(this);
    var obj = {'imgSrc':a.attr('href'),'desc':$('img',a).attr('alt'),'type':_ImgType(a)};
    _images[i]=obj;
    a.click(function(){self.OpenPopUp(i);return false;});
  });


}
