$(document).ready(function(){
    $('#productGallery  a').css('display','inline-block');
    $('#fancy_outer').css('z-index','1000'); 

    if($('#productGallery  a.fancybox').length > 1){
        var imagePreview = new Image();
        var imagePreviewLink = document.createElement('a')
        $(imagePreviewLink).append(imagePreview);
        $(imagePreviewLink).addClass('fancybox');
        $(imagePreviewLink).fancybox();
        imagePreview.src = $('#productGallery  a img')[0].src; 
        $(imagePreviewLink).href= $('#productGallery a img')[0].src.replace('medium','large'); 
        $('#productGallery  a.fancybox  img').css('height','75px');
        $('#productGallery  a.fancybox  img').css('width','75px');
        $('#productGallery  a.fancybox').css('width','75px');
        $('#productGallery  a.fancybox').css('padding','0px 5px');
        $('#productGallery').prepend($(imagePreviewLink));
        $('#productGallery  a  img').mouseover(function(e){
                imagePreview.src = this.src;
                imagePreviewLink.href = this.src.replace('medium','large');
        });
        $('#productGallery a.fancybox').attr('rel','group'); 
    }else{
        var imagePreview = $('#productGallery  a.fancybox img')[0]; 
    }
    
    $('#productGallery a img:first').css('max-width','200px');
    $('#productGallery a img:first').css('height','200px');
    $(imagePreview).css('display','block');
    $(imagePreview).css('margin','0px auto');
    $(imagePreview).css('max-height','200px');
    $(imagePreview).css('max-width','200px');
    $('#productGallery').wrap('<center>');
    var rollMessage = document.createElement('div');
    rollMessage.innerHTML = 'Click any photo to Enlarge';
    $(rollMessage).insertAfter('#productGallery a.fancybox:last'); 
});

