if(navigator.userAgent.indexOf("MSIE") != -1) $(document.body).addClassName('msie');
if(navigator.userAgent.indexOf("Firefox") != -1) $(document.body).addClassName('firefox');
if(navigator.userAgent.indexOf("Safari") != -1) $(document.body).addClassName('safari');
if(navigator.userAgent.indexOf("Linux") != -1) $(document.body).addClassName('linux');
if(navigator.userAgent.indexOf("Windows") != -1) $(document.body).addClassName('win');
if(navigator.userAgent.indexOf("Macintosh") != -1) $(document.body).addClassName('mac');

function border(e) {
	if(e = $(e)) {
		if(e.style.position != 'absolute') {
			e.style.position = 'relative';
		}
		for(var i=0; i<8; i++) {
			var e2 = document.createElement('div');
			e2.className = 'b' + i;
			e.appendChild(e2);
		}
	}
}
$A($$('.border')).each(border);

// animation domaines
function anime() {
	var i = domaines_index;
	domaines_index += 1;
	if(domaines_index >= domaines.length) domaines_index = 0;
	var x = Math.random() * 80 - 5;
	if(x > 35) x += 110;
	var y = Math.random() * 60 + 5;
	$(domaines[i]).setStyle({ left: x + 'px' , top: y + 'px', fontSize: (Math.random() * 15 + 20) + 'px' });
	new Effect.Appear(domaines[i], { duration: 2, afterFinish: function(effect) { 
			new Effect.Fade(effect.element, { duration: 2 });
	}});
	setTimeout(anime, 500);
}
if($('domaines_prix')) {
	var domaines = $('domaines_prix').getElementsByTagName('li');
	var domaines_index = 0;
	for(var i = 0; i < domaines.length; i++) {
		$(domaines[i]).hide();
	}
	//for(var i = 0; i < domaines.length; i++) {
	//	$(domaines[i]).setStyle({left: (Math.random() * 230) + 'px' , top: (Math.random() * 70 + 5) + 'px', opacity: Math.random() *.5 + .3, fontSize: (Math.random() * 12 + 14) + 'px', display: 'block'});
	//}
	anime();
}

// animation portflio
var pf1 = null;
var pf2 = null;
var pf_speed = 1;
function animate() {
	pf1.setStyle({ left: (pf1.offsetLeft - pf_speed) + 'px' });
	if(pf1.offsetLeft <= -pf1.offsetWidth) {
		pf1 = pf2;
		pf2 = pf1.next();
		if(!pf2) pf2 = pf1.up().down();
		pf2.setStyle({left: (pf1.offsetLeft + pf1.offsetWidth + 10) + 'px'});
	} else {
		pf2.setStyle({ left: (pf2.offsetLeft - pf_speed) + 'px' });
	}
			
	setTimeout(animate, 1000/60)
}
if($('portfolio')) {
	pf1 = $('portfolio').down();
	pf2 = pf1.next();
	pf2.setStyle({left: (pf1.offsetLeft + pf1.offsetWidth + 10) + 'px'});
	animate();
}

var timer = null;
var left = 0;
var speedTime = 10;
var speedPx = 3;
function moveLeft() {
    var e = $('captures').down('ul');
    //if(e.scrollLeft + e.offsetWidth >= e.select('img').pluck('offsetWidth').inject(0, function(a, b) { return a + b; })) return;
    e.scrollLeft -= speedPx;
    timer = setTimeout(function() {moveLeft();}, speedTime);
}
function moveRight() {
    var e = $('captures').down('ul');
    //if(e.scrollLeft <= 0) return;
    e.scrollLeft += speedPx;
    timer = setTimeout(function() {moveRight();}, speedTime);
}
function noMove() {
    if(timer) { clearTimeout(timer); timer = null; }
}
if($('capture_gauche')) {
    $('capture_gauche').observe('mouseover', moveLeft);
    $('capture_gauche').observe('mouseout',  noMove);
    $('capture_droite').observe('mouseover', moveRight);
    $('capture_droite').observe('mouseout',  noMove);
}
function magnificator(link, url, width, height) {
    var img = $(link).down('img');
    var zi = 10000;
    var p = Position.cumulativeOffset(img);
    var p2 = Position.realOffset(img);
    p[0] -= p2[0];
    p[1] -= p2[1];
    var b = new Element('div')
        .setStyle({position: 'absolute', top: 0, left: 0, width: '100%', height: '100%', zIndex: zi, overflow: 'hidden'})
        .insert(
            new Element('div')
                .setStyle({position: 'absolute', top: 0, left: 0, width: '100%', height: '100%', zIndex: zi, overflow: 'hidden', background: 'black', opacity: '.6'})
        );
    var e = new Element('div')
        .setStyle({zIndex: zi + 1, position: 'absolute', left: p[0] + 'px', top: p[1] + 'px', width: img.offsetWidth + 'px', height: img.offsetHeight + 'px', display: 'none'})
        .insert(
            new Element('img', {src: img.src})
                .setStyle({position: 'absolute', left: 0, top: 0, width: '100%', height: '100%', zIndex: zi + 1})
        ).insert(
            new Element('img', {src: url})
                .setStyle({position: 'absolute', left: 0, top: 0, width: '100%', height: '100%', zIndex: zi + 2})
        ).insert(
            new Element('div')
                .setStyle({color: 'white', textAlign: 'left', marginTop: height + 'px', display: 'none'})
                .update($(link).down('.description') ? $(link).down('.description').innerHTML : '')
        );

    b.insert(e);
    Event.observe(b, 'click', function(event) {
        e.down('div').hide();
        new Effect.Parallel([
            new Effect.Fade(e, {sync: true}),
            new Effect.Morph(e, {style: 'width: ' + img.offsetWidth + 'px; height: ' + img.offsetHeight + 'px; left: ' + p[0] + 'px; top: ' + p[1] + 'px;', sync: true})
        ], {
            duration: 1,
            afterFinish: function(effect) {
                b.remove();
            }
        });
    }.bindAsEventListener(e));
    document.body.appendChild(b);
    new Effect.Parallel([
        new Effect.Appear(e, {sync: true}),
        new Effect.Morph(e, {style: 'width: ' + width + 'px; height: ' + height + 'px; left: ' + (b.offsetWidth - width) / 2 + 'px; top: ' + (b.offsetHeight - height) / 2 + 'px;', sync: true})
    ], { duration: 1, afterFinish: function(effects) { new Effect.Appear(effects.effects[0].element.down('div')); } });
}

if($('captures'))
    $('captures').select('a').each(function(a) {
        a.observe('click', function(event) {
            magnificator(a, a.href, parseFloat(a.readAttribute('_width')), parseFloat(a.readAttribute('_height')));
            event.stop();
        });
    });
        

