function mel(prefixe,domaine) {
	var adresse;
	adresse = prefixe + "@" + domaine;
  	document.write(adresse);
}
function meltxt(prefixe,domaine,txt) {
	adresse = prefixe+"@"+domaine;
  	document.write('<a href="mailto:'+adresse+'">'+txt+'</a>')
}
function mail(prefixe,domaine) {
	adresse = prefixe+"@"+domaine;
  	document.write('<a href="mailto:'+adresse+'">'+adresse+'</a>')
}
function mailnoprint(prefixe,domaine){
	adresse = prefixe+"@"+domaine;
  	document.write('<a href="mailto:'+adresse+'"></a>')
}
function isIe6() {
    return $.browser.msie && $.browser.version=="6.0";
}
function isIe() {
    return $.browser.msie;
}
/**
 * Aligner verticalement
 */
function verticalAlign($e) {

    var $container      = $(window);
    if($.browser.msie) {
        var pageHeight      = $e.height();
    } else {
        var pageHeight      = $e.innerHeight();
    }
    var containerHeight = $container.height();

    if(pageHeight < containerHeight) {
        $e.css({
            'position'       : 'absolute'
            ,
            'margin-top'    : (containerHeight / 2) - (pageHeight / 2)
            ,
            'margin-left'   : -($e.outerWidth() / 2) + 'px'
            ,
            'left'          : '50%'
        });
    }
    if(!isIe6()) {
    	$('#conotent').css({
    		'margin-top'    : (containerHeight / 2) - (pageHeight / 2)
    	});
    }
}

//
// centrer verticalement
$(function() {
    verticalAlign($('#all'));
    $(window).resize(verticalAlign);
});

//
// Effet de survol
$(function() {
    if(!isIe6()) {
        $('.produit').each(function() {
            var $produit = $(this);
            var url      = $('a',$produit).attr('href');
            var title      = $('a',$produit).attr('title');
            $produit.append('<a class="effectShine" href="' + url + '" title="' + title + '"></a>');
        });
        $('.produit').mouseenter(function() {
            var $produit    = $(this);
            var $effect     = $('.effectShine',$produit);
            if($effect.is(':animated')) $effect.stop();
            $effect.css("background-position","-500px 0");
            $effect.animate({
                backgroundPosition: '200px 0'
            },700);
        });
    }
});


//
// Popins
var popin = {

    add: function() {
        var $popin    = $('#popin');
        if($popin.length == 0) {

            $('body').append('\
<div id="popin-modal"></div>\n\
<div id="popin"><div id="popin-internal">\n\
   <div id="popin-content"></div>\n\
   <div id="popin-close"></div>\n\
</div></div>');
            $('#popin-modal').fadeTo(0,0.2);
            $('#popin-modal').click(function() {
                popin.remove();
            });
            $('#popin-close').click(function() {
                popin.remove();
            });
            $popin    = $('#popin');
        }
        return $popin;
    }

    ,
    remove : function() {
        var $popin    = $('#popin');
        $popin.fadeOut('slow', function() {
            $(this).remove();
            $('#popin-modal').remove();
        });
    }

    ,
    init : function() {
        $('.popin').click(function() {
            var $link     = $(this);
            var url       = $link.attr('href');
            var callback = $link.data('callback') || function(){}

            var $popin    = popin.add();

            var $popinContent = $('#popin-content');
            $.get(url,{}, function(html) {

                var $container      = $(window);
                var containerHeight = $container.height();
                var maxHeight          = parseInt(containerHeight * 70 / 100);

                $popinContent.html(html);
                $popin.css({
                    'max-height' : maxHeight + 'px'
                });
                verticalAlign($popin);

                $('#popin-modal').css({
                    'height': parseInt(containerHeight) + 'px'
                    ,
                    'top':0
                });
                $('#popin-modal').fadeIn('normal');


                $popin.fadeIn('normal');
                //return false;
            //callback();
            });


            return false;
        });
    }
}

$(function() {
    popin.init();
});
