// coding: utf-8

function CreateMailTo() {
    if(document.getElementById('mailto') == null) return;
    var par = document.getElementById('mailto');
    var target = par.firstChild;
    var linkinfo = par.childNodes[1];
    var p = 'al is better than rick but jo internet offers best.';
    var href1 = String.fromCharCode(58)+p.substr(0,2)+p.substr(18,3);
    var href2 = p.substr(27,2)+p.substr(40,2)+p.charAt(11)+p.substr(30,2)+p.charAt(p.length-1)+p.substr(35,3);
    
    target.onmouseover = function() {
	this.style.cursor = 'pointer';
	linkinfo.style.visibility = 'visible';
    };
    target.onmouseout = function() {
	linkinfo.style.visibility = 'hidden';
    };
    target.onclick = function() {
	//~ alert(this.id+href);
	window.location = par.id+href1+String.fromCharCode(64)+href2;
    };
}

window.onload = function() {
    //~ CreateMailTo();
    // liens sites externes en target _blank
    $('#projlist a').attr('target', '_blank');
    // clic sur le +
    var $shown = 0;
    var $tit = $('#showplus').attr('title');
    $('#showplus').click(function(e) {
	e.preventDefault();
	var $this = $(this);
	$('#plus').animate({'height':'toggle'}, 'fast', function() {
	    $shown = $shown ? 0 : 1;
	    if($shown) $this.text('-').attr('title', 'cacher à nouveau');
	    else $this.text('+').attr('title', $tit);
	});
	this.blur();
    });
    // clic sur contact
    var $grown = 0;
    $('#contact h4').click(function(e) {
	e.preventDefault();
	if(!$grown) {
	    $(this).animate({
		'width':'170px', 'height':'77px', 'padding-top':'13px',
		'border-top-left-radius':'4px', 'border-top-right-radius':'4px',
		'border-bottom-left-radius':'4px', 'border-bottom-right-radius':'4px'
		}, 300,
		function() { $(this).toggleClass('expanded'); $grown = 1; }
	    );
	} else {
	    $(this).toggleClass('expanded').animate({'width':'80px', 'height':'52px', 'padding-top':'28px', 'border-radius':'40px'}, 300);
	    $grown = 0;
	}
    });
    // clics sur boutons de controle de l'apparence
    $('#ALT').click(function(e) {
	e.preventDefault();
	if($('body').hasClass('pic') && !$('body').hasClass('alt')) $('body').removeClass('pic');
	$('body').toggleClass('alt');
    });
    $('#GFX').click(function(e) {
	e.preventDefault();
	if($('body').hasClass('pic') && !$('body').hasClass('gfx')) $('body').removeClass('pic');
	$('body').toggleClass('gfx');
    });
    $('#PIC').click(function(e) {
	e.preventDefault();
	if($('body').hasClass('alt')) $('body').removeClass('alt');
	if($('body').hasClass('gfx')) $('body').removeClass('gfx');
	$('body').toggleClass('pic');
    });
    // bulle "Try this! :)"
    if($('#controls p').css('display') != 'none') $('#controls p').hide().delay(1000).fadeIn(1500).delay(4000).fadeOut(900);
};

