$(document).ready(function(){

	/* Search form
	...........................*/
	var search_form = $('li.search div.search_form');
	var search_form_diplay = false;
	$('li.search a').click(function(){
		if(search_form_diplay == false){
			search_form.show("fast", function(){
				search_form_diplay = true;
			});
		} else{
			search_form.hide("fast", function(){
				search_form_diplay = false;
			});
		}
	});
	
	/* Lecteur Audio
	********************************************/
	$(".mp3").click(function(event){
		var href = $(this).attr('href');
		var id = $(this).attr('id');
		$("body").append('<embed id="'+id+'Embed" src="'+href+'" autostart="true" hidden="true"></embed>');
		$(this).css('display','none');
		$(this).parent().children(".mp3Play").css('display','block');
	});
	
	$(".mp3Play").click(function(event){
		var id = $(this).attr('id');
		$('#'+id+'Embed').remove();
		$(this).css('display','none');
		$(this).parent().children(".mp3").css('display','block');
	});
	
	
	/* Delete Title of image
	...........................*/
	$('img').removeAttr('title');
	
	
	
	/****** NEWS ******/
	
	/* Deactivate flash menu on smartphone
	.....................................*/
	/*if(iPhone == true){
		alert("hello");
        $("div#menu_text").css('display','block');
        $("div#menu_flash").remove();
    }
    
    
    /****** VIDEO ******/
    
    /* Scroll Navigation
    .....................................*/
    $("#downWhatsNew").click(function(){
		$.scrollTo('#Clips',800);
	});
	
	$("#upClips").click(function(){
		$.scrollTo('#WhatsNew',800);
	});
	$("#downClips").click(function(){
		$.scrollTo('#MakingOf',800);
	});
	
	$("#upMakingOf").click(function(){
		$.scrollTo('#Clips',800);
	});
	$("#downMakingOf").click(function(){
		$.scrollTo('#Interviews',800);
	});
	
	$("#upInterviews").click(function(){
		$.scrollTo('#MakingOf',800);
	});
	$("#downInterviews").click(function(){
		$.scrollTo('#Others',800);
	});
	
	$("#upOthers").click(function(){
		$.scrollTo('#Interviews',800);
	});
	
	$(".upArrow").click(function(){
		var previousH3 = $(this).parent().prev().prev();
		$.scrollTo(previousH3,800);
	});
	$(".downArrow").click(function(){
		var nextH3 = $(this).parent().next().next();
		$.scrollTo(nextH3,800);
	});

	/* Video Hover effect
	.....................................*/
	$(".a_video_post a").hover(
		function(){
			$(this).find('img.video_overlay').fadeIn();
		},function(){
			$(this).find('img.video_overlay').fadeOut();
	});
	
	
	/*Bubble Info
	.........................................*/
	$(".a_track_more").hover(function(){
		$(this).next().removeClass("a_track_more_no_hover").addClass("a_track_more_hover");
	},function(){
		var hoverBubble = false;
		var thisElement = $(this).next();
		
		thisElement.hover(function(){
			hoverBubble = true;
		},function(){
			hoverBubble = false;
			thisElement.removeClass("a_track_more_hover").addClass("a_track_more_no_hover");
		});
		
		setTimeout(function() {
			if(hoverBubble == true){} else{ 
				thisElement.removeClass("a_track_more_hover").addClass("a_track_more_no_hover");
			}
		}, 10);
	});
	
	/* Audio Player
	.........................................*/
	var play = false;
	$(".a_track_player_play").each(function(){
		if ($(this).attr("href") == ""){
			$(this).removeClass("a_track_player_play").addClass("a_track_player_play_no_link");
		}	
	});
	
	$(".a_track_player_play").click(function(){
		
		// If another song is playing we stop it and change button state
		$(".a_track_player_stop").css("display","none");
		$(".a_track_player_play").css("display","block");
		$(".sound").remove();
		
		// Change button state
		$(this).css("display","none");
		$(this).parent().children(".a_track_player_stop").css("display","block");
		
		// Load Sound
		var href = $(this).attr("href");
		$("body").append('<embed class="sound" src="'+href+'" autostart="true" hidden="true"></embed>');
		play = false;
	});
	
	$(".a_track_player_stop").click(function(){
		// Change button state
		$(this).css("display","none");
		$(this).parent().children(".a_track_player_play").css("display","block");
		
		// Stop sound
		$(".sound").remove();
		play = false;
	});
	
	/* Elipsis
	...........................................*/
	
	$(".a_track_title").hover(function(){
    	var boxWidth = $(this).width();
    	var originalText = $(this).children().text();
    	var originalTextWidth = $(this).children().width();
    	if (originalTextWidth > boxWidth){
    		$(this).children().attr('title', originalText);
    	}
    });
	
	/* Formulaire
	............................................*/
	$('#booking_form input').focusin(function(){
		if($(this).hasClass('bad')){
			$(this).removeClass('bad').addClass('required');
		}else{}
	});
	
	$('.required').focusout(function(){
		if($(this).val() == ''){
			$(this).removeClass('required good').addClass('bad');
		}else{
			if($(this).attr('name')=='mobile'){
				if($(this).val().length < 10){
					$(this).removeClass('required good').addClass('bad');
				}else{
					$(this).removeClass('required bad').addClass('good');
				}
			}else{
				if($(this).attr('name')=='budget'){
					if($(this).val() < 30000){
						$(this).removeClass('required good').addClass('bad');
						$(this).next('span').css('display','inline');
					}else{
						$(this).removeClass('required bad').addClass('good');
						$(this).next('span').css('display','none');
					}
				}else{
					$(this).removeClass('required bad').addClass('good');
				}
			}
		}
	});
	
	$('#booking_form input').focusout(function(){
		active_button();
	});	
	
	function active_button(){
		var rege = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
		if($('#booking_form .required').length < 1 && $('#booking_form .bad').length < 1 && rege.test($('#date1').val())){
			$('#send_button').removeAttr('disabled');
			$('#send_button').next('span').css('display','none');
		}else{
			$('#send_button').attr('disabled','disabled');
			$('#send_button').next('span').css('display','inline');
		}
		
	}
	
	$("input.numeric").keypress(function(e) { /* pour les champs qui ne prennent que du numeric en entrŽe */          
		var key = e.charCode || e.keyCode || 0;                     
		var keychar = String.fromCharCode(key);
        /*alert("keychar:"+keychar + " \n charCode:" + e.charCode + " \n key:" +key);*/
		if (  ((key == 8 || key == 9 || key == 46 || key == 35 || key == 36 || (key >= 37 && key <= 40)) && e.charCode==0) /* backspace, end, begin, top, bottom, right, left, del, tab */
		        || (key >= 48 && key <= 57) ) { /* 0-9 */
		    return;
		} else {
		    e.preventDefault();
		}
	});
	
	/** DISCOGRRAPHY **/
	
	/* Accordion
	*********************************/
	$(".accordionContent:not(.accordionContent.open)").hide();
	$(".accordionMenuButton").click(function(){
		$('.accordionMenuPuce').css('background-position', 'top left');
		if ($(".accordionContent:not:visible") .get()[0] !== $(this).parent().next().get()[0]) {	
			if($('.accordionMenuButtonActive')){
				$('.accordionMenuButtonActive').removeClass('accordionMenuButtonActive').addClass('accordionMenuButton');
			}
			$(this).removeClass('accordionMenuButton').addClass('accordionMenuButtonActive');
			$(".accordionContent").fadeTo("fast", 0);
			$(".accordionContent").slideUp("fast");
			
			$(this).parent().next().slideDown("def");
			$(this).parent().next().fadeTo("def", 1);
			$(this).children('.accordionMenuPuce').css('background-position', 'bottom left');
		}
		else {
			$(this).removeClass('accordionMenuButtonActive').addClass('accordionMenuButton');
			$(this).parent().next().fadeTo("fast", 0);
			$(this).parent().next().slideUp("fast");
			$(this).children('.accordionMenuPuce').css('background-position', 'top left');
		}
		return true;
	});
		
		
	/* Animation sur les africanism
	********************************************/
	$('.oneAfricanism').hover(
		function(){
			$(this).find('.oneAfricanismDescription').slideDown(200);
		}, function(){
			$(this).find('.oneAfricanismDescription').slideUp();
	});
	
});
