window.addEvent('load',function(e){
	
	$$('.biography').each(function(el,i){
		
		makeScrollbar(el);
		
	});
	
	
});


window.addEvent('domready',function(e){
	
	var overFx = [];
	var underoverFx = [];
	var Mosmargin = 10;
	
	$$('#listOeuvres .item div.over').each(function(el,i){  				    overFx[i] = new Fx.Morph(el, {duration:300, wait:false,transition:Fx.Transitions.Expo.easeOut}).set({'opacity':0})});
	$$('#listOeuvres .item div.underover').each(function(el,i){ el.addEvent('click',function(e){ document.location.href=el.getNext().get('href'); }); underoverFx[i] = new Fx.Morph(el, {duration:300, wait:false,transition:Fx.Transitions.Expo.easeOut}).set({'opacity':0,'margin-top':Mosmargin}) });
	
	
	
		$$('#listOeuvres .item').each(function(el,i){
			el.addEvents({
			'mouseover':function(e){  overFx[i].start({'opacity':0.9}); underoverFx[i].start({'opacity':1,'margin-top':0});  },
			'mouseleave':function(e){  overFx[i].start({'opacity':0}); underoverFx[i].start({'opacity':0,'margin-top':Mosmargin}); }			
			
			});
		});
		
});

function loadFlash(play){
	
	
	var obj = new Swiff('/wp-content/themes/silences/libraries/js/player.swf', {
	    id: 'silences',
	    container:'media',
	    width: 572,
	    height: 461,
	    params: {
	        wmode: 'transparent',
	        bgcolor: '#ffffff',
	        allowscriptaccess:'always',
	        allowfullscreen:'true'
	    },
	    vars: {
	        file: play,
	        title: 'Silences',
	        autostart : true,
	        controlbar : 'bottom',
	        skin:'/wp-content/themes/silences/libraries/js/stylish.swf',
	        repeat:'list'
	    }


	    
	});
	
	return obj;
	

}

function playerReady(obj) 
{
	
	$('silences').addControllerListener("ITEM", "itemChange");
}

function itemChange(obj)
{
	
	$$('ul.media li a').each(function(el,i){
		
		if(obj.index==i)
			el.addClass('selected');
		else
			el.removeClass('selected');
		
	});
	
	
}

window.addEvent('domready',function(e){
	
	if($$('.singleVideo').length==0)
		return;
	
	var url = location.href.split("#");
	
	 loadFlash(url[0]+'attachmentfeed/');
	
	
});
window.addEvent('domready',function(e){
	
	$$('.supprimer').each(function(el,i){
		
		el.addEvent('click',function(e){
				
		var choix = confirm(el.getProperty('title'));
		
		if(choix == false)
			new Event(e).stop();

		});

		
	});
});
window.addEvent('domready',function(e){
	
	
	if($$('.singleOeuvres').length==0)
		return;
	var url = location.href.split("#");
	 loadFlash(url[0]+'attachmentfeed/');
	
	 var silences = $('silences');
	 


	$$('ul.media li a').each(function(el,i){
		
		el.addEvent('click',function(e){
				new Event(e).stop();
				
				 
				silences.sendEvent('ITEM', i);
	});
	});
	
	var result = location.href.split("#");
	var anchor = (result.length > 1)? "artiste" : "oeuvre";
	
	
	
	
	var BoxesDim = {
			oeuvre : $('oeuvre').getHeight(),
			artiste : $('artiste').getHeight()
			
		};	
	$('artiste').setStyles({'position':'absolute','width':'375px','top':$('oeuvre').getTop()});
	var Boxes = {
				oeuvre : new Fx.Morph($('oeuvre'), {duration:400, wait:false,transition:Fx.Transitions.linear}).set({'opacity':0}),
				artiste : new Fx.Morph($('artiste'), {duration:400, wait:false,transition:Fx.Transitions.linear}).set({'opacity':0})
				
			 };

	
		eval("Boxes."+anchor).set({'opacity':1,'height':eval("BoxesDim."+anchor)});
	
	var current = anchor;
	
	function switchContent()
	{
		
		if(current == "oeuvre")
		{
			Boxes.oeuvre.start({'opacity':0}).chain(function(){
			
			});
			Boxes.artiste.start({'opacity':1,'height':BoxesDim.artite})
			current = "artiste";
		}
		else
		{
			Boxes.artiste.start({'opacity':0}).chain(function(){
				
			});
			Boxes.oeuvre.start({'opacity':1,'height':BoxesDim.oeuvre})
			current = "oeuvre";
		}
		
	}
	
	$$('.switchContent').addEvent('click',function(e){ new Event(e).stop(); switchContent(); });
	
	$('boxCommentaires').setStyle('overflow','hidden');
	$('relatedContent').setStyle('overflow','hidden');
	
	var boxCommentaires_H = $('boxCommentaires').getHeight();
	var boxCommentaires_M = $('boxCommentaires').getStyle('margin');

	var relatedContent_H = $('relatedContent').getHeight();
	var relatedContent_M = $('relatedContent').getStyle('margin');
	var relatedContent_P = $('relatedContent').getStyle('padding');
	
	var boxCommentaires = new Fx.Morph($('boxCommentaires'), {duration:800, wait:false,transition:Fx.Transitions.Back.easeIn}).set({'height':0,'opacity':0,'margin':0});
	var relatedContent =  new Fx.Morph($('relatedContent'), {duration:800, wait:false,transition:Fx.Transitions.Back.easeIn}).set({'height':0,'opacity':0,'margin':0,'padding':0});
	
	$('coms').addEvent('click',function(e){
		this.destroy();
		new Fx.Scroll(document.body, { offset:{'x':0,'y':-5}, transition:Fx.Transitions.linear,  duration: 500,    wait: false}).toElement($('boxCommentaires')).chain(function(){
			
			boxCommentaires.start({'height':boxCommentaires_H,'opacity':1,'margin':boxCommentaires_M});
			relatedContent.start({'height':relatedContent_H,'opacity':1,'margin':relatedContent_M,'padding':relatedContent_P});
			
			
		});
		
		
	});
	
});