﻿
   function ToggleLargerImageBox(blnShow) {
      if (blnShow) {
         $('#divLargerImage_ImageBox').show();

         var intWindowWidth = parseInt($(window).width());
         var intWindowHeight = parseInt($(window).height());

         //window.alert("Window: " + intWindowWidth + ' x ' + intWindowHeight);
         
         var intBoxWidth = $('#divLargerImage_ImageBox').width();
         var intBoxHeight = $('#divLargerImage_ImageBox').height();

         //window.alert("Box: " + intBoxWidth + ' x ' + intBoxHeight);
         
         var intTopPos = 0;
         var intLeftPos = parseInt((intWindowWidth - intBoxWidth)/2);
         if(intBoxHeight<intWindowHeight)
         {
            var scrollY = self.pageYOffset ? self.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body ? document.body.scrollTop : null;
            intTopPos = parseInt((intWindowHeight - intBoxHeight)/2) + scrollY;
         }

         //window.alert("divLargerImage: left=" + intLeftPos + " top= " + intTopPos);

         $('#divLargerImage').insertAfter('body');
         $('#divLargerImage').css("margin-top", (intTopPos) + "px");
         $('#divLargerImage').css("margin-left", (intLeftPos) + "px");
         

            //$('#bodyBackground').css('width', intWidth);
            //$('#bodyBackground').css('height', intHeight);
            //$('#bodyBackground').find('img').attr('width', intWidth);
            //$('#bodyBackground').find('img').attr('height', intHeight);

         
         $('#mdlWrap').show();
      } else {
         $('#divLargerImage_ImageBox').find('iframe').remove();
         
         $('#divLargerImage_ImageBox').hide();
         $('#mdlWrap').hide(); 
      }
   }
 
   function ShowImage(strImageName) {
      var imageInBox = document.getElementById('divLargerImage_ImageBox_Image');
      imageInBox.src = "/storeimages/600x600/" + strImageName;
      ToggleLargerImageBox(true);
   }

   function PreviewImage(strImageName) {
      $('.scImgViewItem_MainImage').attr('src', '/storeimages/400x400/' + strImageName);
   }

   $(document).ready(function() {
      $('#mdlWrap').click(function() {
         
         ToggleLargerImageBox(false); 
      });
      
      //$('#divLargerImage').appendTo('body');
   });
   
