function hideDiv(divid){
    $(divid).fadeOut("fast");
}
var galleryID = '#gallerydetail';
var galleryBasePath = '';
var simpleModalDialog = '';

function fillGalleryDetail(img, txt){
    var borderWidth = 22;
    var imgWidth = img.width;
    var imgHeight = img.height;
    var containerWidth = imgWidth + borderWidth + borderWidth;
    var containerHeight =  imgHeight + borderWidth + borderWidth;
    var detailContent = '<div style="width: '+containerWidth+'px; height: '+containerHeight+'px;" class="image-border image-border-left">';
    detailContent += '<div class="image-border-t-r" style="left: '+(imgWidth-102)+'px; top: -73px"/>';
    detailContent += '<div class="image-border-b-l"/>';
    detailContent += '<div class="gal-close" style="width: '+containerWidth+'px"><a href="javascript:$.modal.close();">fenster schliessen</a></div>';
    if(window.galPrvImgSrc && totalImages > 0){detailContent += '<div class="gal-prv" style="top: '+(containerHeight-90)/2+'px"><a href="javascript:checkModalContent(true)"><img src="'+window.galPrvImgSrc+'" alt="prv"/></a></div>';}
    if(window.galNxtImgSrc && totalImages > 0){detailContent += '<div class="gal-nxt" style="top: '+(containerHeight-90)/2+'px"><a href="javascript:checkModalContent()"><img src="'+window.galNxtImgSrc+'" alt="nxt"/></a></div>';}
    detailContent += '<div class="gal-txt">'+txt+'</div>';
    detailContent += '<div class="image-content" style="height: '+imgHeight+'px;">';
    detailContent += '<a href="javascript:checkModalContent();"><img width="'+imgWidth+'" src="'+img.src+'"/></a>';
    detailContent += '</div>';
    detailContent += '</div>';
    return detailContent;
}

function displayModalContent(me){
    window.currentImageNo = me;
    var tmpimg = new Image();
  $(tmpimg)
    // once the image has loaded, execute this code
    .load(function () {
      // set the image hidden by default
      $(this).hide();
      $(galleryID).html(fillGalleryDetail(this, bigImageTitles[me]));
      $("#gallerydetail").modal({overlayClose:true,overlay:90, overlayCss: {backgroundColor:"#000"},onOpen: function (dialog) {
          simpleModalDialog = dialog;
            dialog.overlay.fadeIn('fast', function () {
                dialog.data.hide();
                    dialog.container.fadeIn('fast', function () {
                        dialog.data.slideDown('slow');
                    });
                });
            }});
    })
    .attr('src', bigImageHandles[me]);
}



function checkModalContent(back){
    $(galleryID).fadeOut("fast", function () {
        if(back == true){
            currentImageNo--;
            if(currentImageNo<0){currentImageNo = totalImages;}
        }else{
            currentImageNo++;
            if(currentImageNo>totalImages){currentImageNo = 0;}
        }
        resizeModal(currentImageNo);
    });
}


function resizeModal(me){
    var tmpimg = new Image();
    tmpimg.onload = function(){
        var pic_real_width = this.width;
        var pic_real_height = this.height;
        simpleModalDialog.container.width(pic_real_width+44);
        simpleModalDialog.container.height(pic_real_height+44);
        $(galleryID).html(fillGalleryDetail(this, bigImageTitles[me]));
        $(window).trigger('resize.simplemodal');
        $(galleryID).fadeIn("fast");
    }
    tmpimg.src = bigImageHandles[me];
}

function removeDefault(formField, value){
    if(formField.value == value){
        formField.value = "";
    }
}
function resetDefault(formField, value){
    if(formField.value == ""){
        formField.value = value;
    }
}

$(document).ready(function(){
    $(".activeimg").hover(
        function() {
            $(this).animate({"opacity": "0"}, "slow");
        },
        function() {
            $(this).animate({"opacity": "1"}, "slow");
        });
});




