// JavaScript Document



function centre(){
    var bx = $('body').getSize().y;  
    var wx = window.getSize().y;
    var m = (wx - bx) / 2;
    if(m > 100) m = 100;
    if(m < 0) m = 0;
    $('body').setStyle('margin-top', m);
}


function rollover(){
	$$('#nav li a img').each( function(img){
		img.addEvent('mouseover', function(){
			if( !this.src.contains('_on') ) this.src = this.src.replace('.gif', '_on.gif');
		});
		img.addEvent('mouseout', function(){
			this.src = this.src.replace('_on', '');
		});
	});
}


window.addEvent('domready', function(){	
	rollover();
});
window.addEvent('resize', centre);


function aboutPage(){
	
	var swapSections = function(new_section, pic) {
        var p = $$('.about-content');
        var t = $$('.'+new_section);
    	
        var exampleFx = new Fx.Tween('img', { property: 'opacity', transition: 'quart:out', link: 'chain', duration: 1000 });
        exampleFx.start(0).chain(
            function(){
                p.hide();
        	    t.show();
                $('img').setStyle('background-image', 'url('+pic+')');
                this.start(1)
            }
        )

        p.tween('opacity', 0);
        t.tween.delay(1000, t, ['opacity', 1] );	    
	}
	
	
    $$('.about-us-link').addEvent('click', function(){
	    swapSections('about-us', 'galleries/home/cr-website-images-6.jpg')
    });
	$$('.what-we-do-link').addEvent('click', function(){
	    swapSections('what-we-do', 'images/way-we-work.jpg')
	});
    
    $$('.team-link').addEvent('click', function(){
        swapSections('the-team', 'images/the-team.jpg')
    });    
    $$('.henrietta-link').addEvent('click', function(){
        swapSections('the-team-henri', 'images/the-team-henri.jpg')
    });
    $$('.aimee-link').addEvent('click', function(){
        swapSections('the-team-aimee', 'images/the-team-aimee.jpg')
    });
    
    $$('.what-we-do').setOpacity(0);
	$$('.what-we-do').hide()
	$$('.the-team').setOpacity(0);
	$$('.the-team').hide();
	$$('.the-team-henri').setOpacity(0);
	$$('.the-team-henri').hide();
	$$('.the-team-aimee').setOpacity(0);
	$$('.the-team-aimee').hide();
	
	
}
