Array.prototype.in_array = function(p_val) {  for(var i = 0, l = this.length; i < l; i++) { if(this[i] == p_val) { return true; } } 	return false;	}	

	
jQuery(document).ready(function($){
	
	$("#index nav li a.img").mouseover(function(){
		$("#index nav li a.img").each(function(){
			$(this).css("opacity", .5);
		})
			$(this).css("opacity", 1);
	}).mouseout(function(){
		$("#index nav li a.img").each(function(){
			$(this).css("opacity", 1);
		})
	})
	
	$("#boulot nav.second li a.img").mouseover(function(){
		$("#boulot nav.second li a.img").each(function(){
			$(this).css("opacity", .5);
		})
			$(this).css("opacity", 1);
	}).mouseout(function(){
		$("#boulot nav.second li a.img").each(function(){
			$(this).css("opacity", 1);
		})
	})
	
	
	
	var aud = $('#player_1 .aud').get(0);
	  aud.pos = -1;
	
	
	$('.audio_player .aud').each(function(){
		target = $(this).get(0);
		target.addEventListener('progress', function() {	progress();	}, true);				
		target.addEventListener('timeupdate', function() {	timeupdate()}, true);
	})
	
		$('.audio_player a').bind('click', function(evt) {
			aud = $($(this).attr('href')+' .aud').get(0);
			
			return false;
		});
	
		$('.audio_player a.play').bind('click', function(evt) {		
			if (aud.paused){ aud.play(); } else { aud.pause() }
			$(this).toggleClass('play pause');
		});
	
		$('.audio_player .stop').bind('click', function(evt) {
				if (aud.paused == false){ $('.audio_player a.pause').toggleClass('play pause');	}	
				aud.pause();aud.currentTime = 0;											
		});
		
		// JQuery doesn't seem to like binding to these HTML 5
		// media events, but addEventListener does just fine
		
		function progress(){
		  var width = parseInt($('.progress').css('width'));
			var width = parseInt($('.audio_player .loader').css('width'));
			var percentLoaded = Math.round(evt.loaded / evt.total * 100);
			var barWidth = Math.ceil(percentLoaded * (width / 100));
			$('.audio_player .load-progress').css( 'width', barWidth );
		}
		
		function timeupdate(){
		  var width = parseInt($('.audio_player .loader').css('width'));
			var percentPlayed = Math.round(aud.currentTime / aud.duration * 100);
			var barWidth = Math.ceil(percentPlayed * (width / 100));
			$('.audio_player .play-progress').css( 'width', barWidth);
		}
	
	
	
})
