

modViewer.prototype.Open = function(obj,id,posid){  
   if(obj){
      this.id = $(obj).attr('id');
   }else if(id){
      this.id = id;
   }
   
   if(posid){
      this.posid = posid;
   }else{
      this.posid = this.id;
   }      
   
   if(this.id){
      var instance = this;
      instance.Overlay();
   }   
}


modViewer.prototype.Overlay = function(){
	var w  = '100%'
	var dh = parseInt($(document).height(),10);
	var wh = parseInt($(window).height(),10);
	var h  = 2000+'px';
	if(dh>wh){h = dh+'px';}else{h = wh+'px';}
	
	if(!$('#PopoverBlocker').length){  	
  	$('<div id="PopoverBlocker" style="height:'+h+';width:100%;position:absolute;z-index:20;top:0;left:0;background-color:black;">&nbsp;</div>').appendTo("body");
  	$('#PopoverBlocker').css({
  	   opacity: .2,
  	   display: 'block'
  	});
		
  	var instance = this;
  	$('#PopoverBlocker').animate({
  	   opacity: .4
  	}, 300,false,function(){instance.Viewer();});
  }      
}

modViewer.prototype.Properties = function(all){
   var b = $('#'+this.posid).position();
   return {
      button_c_left : parseInt(b.left + (parseInt($('#'+this.id).width(),10) / 2),10),
      button_c_top  : parseInt(b.top + (parseInt($('#'+this.id).height(),10) / 2),10),
      w_top         : all ? parseInt(($(window).height() / 2 - this.bg_h / 2 + $(window).scrollTop()),10) : 0,
      w_left        : all ? parseInt(($(window).width() / 2 - this.bg_w / 2),10) : 0
   };   
}   


modViewer.prototype.Viewer = function(){    
   var p = this.Properties(true);  
   var instance = this;
   $('<img id="PopoverBlockerBack" src="/view/img/modview.png" style="width:1px;z-index:101;position:absolute;left:'+p.button_c_left+'px;top:'+p.button_c_top+'px;"/>').appendTo("body");
     
   $('#PopoverBlockerBack').animate({
      left:  p.w_left,
      top:   p.w_top >= 0 ? p.w_top : 0,
      width: instance.bg_w,
      height: instance.bg_h
   }, 500, false, function(){
      $('<div id="PopoverContent" style="width:'+instance.bg_w+'px;height:'+instance.bg_h+'px;z-index:102;position:absolute;left:'+(p.w_left)+'px;top:'+(p.w_top >= 0 ? p.w_top : 0)+'px;"></div>').appendTo("body");
      
      var r = '';
      var j = 0;
      jQuery.each(instance.photos,function(i, val){
         j++;
         if(j<5){
            r += '<div><a id="over_'+i+'" class="ImgNormal" href="javascript:void(0);" onmouseover="$(\'#BigImgSrc\').attr(\'src\',\''+val+'\');ActiveMe(this);"><img src="'+val+'" style="width:80px;"/></a></div>';
         }
      });
      
      var a = '';
      a += '<div class="modViewerHeader" style="width:538px;height:80px;float:right"><div onclick="modViewerVar.Close();" style="float:right;width:50px;height:50px;cursor:pointer;"><img src="/view/img/dot.gif" style="width:50px;height:50px;"/></div></div>';
      a += '<div style="width:'+instance.wysodiv+'px;height:595px;float:left;"><img style="float:right;border:1px solid #d94a4a;" id="BigImgSrc" src="'+instance.photos[instance.id]+'"/></div>';
      a += '<div class="modViewerAll" style="width:105px;height:595px;float:left;padding-left:20px;">'+r+'</div>';
      
      $(a).appendTo("#PopoverContent");     
      ActiveMe('#over_'+instance.id);   
   }); 
}

modViewer.prototype.OverlayOff = function(){
   if($('#PopoverBlocker').length){
      $('#PopoverBlocker').animate({
         opacity: .0
      }, 300,false,function(){
        $('#PopoverBlocker').remove();       
      });        
   }
}

modViewer.prototype.Close = function(){
   var instance = this;      
   var p = this.Properties(false);
     
   $('#PopoverBlockerBack,#PopoverContent').animate({
      left:  p.button_c_left,
      top:   p.button_c_top,
      width: '1px',
      height: '1px'
   }, 500, false, function(){
      $('#PopoverContent').remove();
      $('#PopoverBlockerBack').remove();         
      instance.OverlayOff();
   });      
   document.getElementById('div_logo').style.visibility='visible';
}   


function ActiveMe(obj){
   $('#PopoverContent .ImgNormal, #PopoverContent .ImgActive').removeClass('ImgNormal').removeClass('ImgActive').addClass('ImgNormal');
   $(obj).removeClass('ImgNormal').removeClass('ImgActive').addClass('ImgActive');
}

