$(function(){
    $('.zooming').fancyzoom({Speed:400,showoverlay:true, overlay:4/10});
    $('.zooming img:first').each(function() {
        var imgDir = '/img/ressources/';
        var $this = $(this);
        oImgZoom = $('<img>').css({position:'absolute',top:0,left:0,cursor:'pointer',zIndex:2});
        //reset the img zoom and fix png on it if plugin available
        oImgZoom.attr('src',imgDir+'closebox.png').appendTo('body').hide();
        if($.fn.ifixpng) {$.ifixpng(imgDir+'blank.gif');oImgZoom.ifixpng(imgDir+'blank.gif');}

        //oImgZoom.css({left:(dimBoxTarget.left+ dimBoxTarget.width-22-(dimBoxTarget.width-oImgDisplay.width())/2),top:dimBoxTarget.top});
    });
    $('#loginform').jqm({
       //ajax: 'example.php',
       trigger: 'a.login',
       overlay: 30,
       onHide: function(hash) {
    	    var $modalWindow = $(hash.w);
    	    $modalWindow.fadeOut('2000', function()
    	    {
    	        hash.o.remove();
    	        //refresh parent
    	        if (hash.refreshAfterClose == true)
    	        {
    	            window.location.href = document.location.href;
    	        }
    	    });
    	},
       onShow: function(hash) {
    	    var $trigger = $(hash.t);
    	    var $modalWindow = $(hash.w);
    	    var myTitle = $trigger.attr('title');
    	    var newWidth = '300', newHeight = '200', newLeft = '50%', newTop = '50%';
    	    var newTop = Math.floor(parseInt($(window).height() / 2) - parseInt(newHeight) / 2);
    	    var newLeft = Math.floor(parseInt($(window).width() / 2) - parseInt(newWidth) / 2);
    	    // do the animation so that the windows stays on center of screen despite resizing
    	    $modalWindow.css({
    	         top: 0,
    	         left: '60%',
    	         width: newWidth,
    	         height: newHeight,
    	         opacity: 0
    	    }).jqmShow().animate({
    	         width: newWidth,
    	         height: newHeight,
    	         top: newTop,
    	         left: newLeft,
    	         marginLeft: 0,
    	         opacity: 1
    	     }, 'slow');
    	}
    });

});
