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

var bigImageHandles = new Array();
var bigImageTitles = new Array();
var totalImages = new Array();
var currentGalleryID = "";

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 borderStyle = 'style="width: '+(imgWidth+borderWidth)+'px; height: '+(imgHeight+borderWidth)+'px;"';
    var detailContent = '<div style="width: '+containerWidth+'px; height: '+containerHeight+'px;" class="image-border image-border-left">';
    detailContent += '<div class="image-border-t-l" '+borderStyle+'/>';
    detailContent += '<div class="image-border-b-r" '+borderStyle+'/>';
    detailContent += '<div class="image-border-t-r"/>';
    detailContent += '<div class="image-border-b-l"/>';
    if(window.galCloseImgSrc){detailContent += '<div class="gal-close"><a href="javascript:$.modal.close();"><img src="'+window.galCloseImgSrc+'" alt="close"/></a></div>';}
    if(window.galPrvImgSrc && totalImages[currentGalleryID] > 0){detailContent += '<div class="gal-prv" style="top: '+containerHeight/2+'px"><a href="javascript:checkModalContent(true)"><img src="'+window.galPrvImgSrc+'" alt="prv"/></a></div>';}
    if(window.galNxtImgSrc && totalImages[currentGalleryID] > 0){detailContent += '<div class="gal-nxt" style="top: '+containerHeight/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, id){
    currentGalleryID = id;
    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[currentGalleryID][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[currentGalleryID][me]);
}



function checkModalContent(back){
    $(galleryID).fadeOut("fast", function () {
        if(back == true){
            currentImageNo--;
            if(currentImageNo<0){currentImageNo = totalImages[currentGalleryID];}
        }else{
            currentImageNo++;
            if(currentImageNo>totalImages[currentGalleryID]){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[currentGalleryID][me]));
        $(window).trigger('resize.simplemodal');
        $(galleryID).fadeIn("fast");
    }
    tmpimg.src = bigImageHandles[currentGalleryID][me];
}
$(document).ready(function(){
    $(".company").hover(
        function() {
            $(".activeimg", this).animate({"opacity": "0"}, "slow");
        },
        function() {
            $(".activeimg", this).animate({"opacity": "1"}, "slow");
        });
        // rounded corners
        $('#header').corner( "top 15px");
        $('#wrap').corner( "br bl 15px");

});

