	
	(function($){
		
		$.fn.triggerAjaxCall = function(ajaxUrl){
		//	if($(document).data('itemIsTriggered') == false) {
	               	
					$('#player')[0].action('pause');
					$('#player').fadeTo('slow', 0.3);
					$('#placeholder').load(ajaxUrl).fadeIn(1500);
				//	doc.data('itemIsTriggered',true);
		//		}
	        };
		
		$.fn.triggerAjaxClose = function(){
				
				$('#placeholder').fadeOut('slow', function() { $(this).hide(); })
				$("#mp3_bonus_div").html(""); // stops bonus audio
				$("#video_bonus_div").html(""); // stops bonus video
				$("#bonus_content").html(""); // emptiesbonus container
				
				$('#player').animate({ opacity:1 },180);	
		    	$('#player')[0].action('play');
			//	doc.data('itemIsTriggered',false);
		    };	
		
		
		$.fn.openDrawer = function(){
			$(this).animate({ top:'0', "opacity": 1 },1200,'easeInOutQuint').css('cursor', 'pointer');
			
			var $element_descr = $(this).find('.thumb_description'); /* var is necessary when calling setTimeout*/
			var $element = $(this); /* var is necessary when calling setTimeout*/
			
			setTimeout( function() { $element_descr.stop().animate( {"top": -70} ) }, 5000 );
			setTimeout( function() { $element.stop().animate({"opacity": 0.3}) }, 7000 );
			
			$(this).hover(function() { 
				$element_descr.stop().animate({"top": 0},280);
			    $(this).stop().animate({"opacity": 1}, 100); 
				$('.info_drawer', this).stop().animate({top:'30px', "opacity": 0.7}, 200,'easeInOutQuint' ); 
			},function() { 
				
				$element_descr.stop().animate({"top": -70}, 340);
			    $(this).stop().animate({"opacity": 0.4});

			});
		};

		
	})(jQuery)


var changing = true;
var dateChanging = true;

function updateValuesChanged(event, ui, changing){
	if (!changing)
		displayValues(ui.label, ui.values)	
}

function updateValuesChanging(event, ui, changing){
	if (changing)
		displayValues(ui.label, ui.values)
}

function displayValues(slider, values){

  	slider.parents("form").find("input[name=min]").val(values.min);
  	slider.parents("form").find("input[name=max]").val(values.max);

}

function makeSlider(selector, options){
	var slider = $(selector)
		.rangeSlider(options)
		.bind("valuesChanging", function(event, ui){updateValuesChanging(event, ui, changing);})
		.bind("valuesChanged", function(event, ui){updateValuesChanged(event, ui, changing);
		$('#result').load('ajax_archive.php', {min_date:values.min, max_date:values.max});})
		.addClass("ui-rangeSlider-dev");
	displayValues(slider, slider.rangeSlider("values"));
}



function setOption(element, option, value){
	if (value == "null") {
		value = null
	}
	$(element).parents(".example").find(".slider").rangeSlider("option", option, value);
	$(element).parents(".example").find(".dateSlider").dateRangeSlider("option", option, value);
}

function getOption(element, option){
	return $(element).parents(".example").find(".slider").rangeSlider("options")[option];
}

$(document).ready(function(){
	
	makeSlider("#defaultSlider", {});

	$("form").submit(function(){return false;});

	$(".dateValues input[name=min]").change(function() {
	  
	});
	

	$("input[type=reset]").click();
});


$(document).ready(function() {
	
	
	/* TABS */	

	$(".tab_content").hide();
	$("ul.tabs li:eq(0)").addClass("active").show();
	$(".tab_content:eq(0)").show();
		
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active");
		$(this).addClass("active");
		$(".tab_content").hide();

		var activeTab = $(this).find("a").attr("href");
		$(activeTab).fadeIn();
		return false;
		
	});
	
	
	/* LOGOS */
	
	$('#logo_rts').hover(
	    function() {
	        $(this).stop().animate({backgroundPositionY: '33'}, 320,'easeOutBack' );
	        },
			function () {
	        $(this).stop().animate({backgroundPositionY: '66'}, 1200,'easeOutQuint' );	
	    });
	
	
	$('#logo_la_premiere').hover(
	    function() {
	        $(this).stop().animate({backgroundPositionY: '140'}, 520,'easeOutBack' );
	        },
			function () {
	        $(this).stop().animate({backgroundPositionY: '70'}, 1200,'easeOutQuint' );	
	    });
	
	
	$('#logo_map').hover(
	    function() {
	        $(this).stop().animate({backgroundPositionY: '70'}, 520,'easeOutBack' );
	        },
			function () {
	        $(this).stop().animate({backgroundPositionY: '140'}, 1200,'easeOutQuint' );	
	    });
	
	
	

	
	
	/* PANEL TOGGLE */
	
	$('#panel_toggler').hover(
	  function() {
	        $(this).find('img').stop().fadeTo('fast', 0);
	        },
	    	function () {
	        $(this).find('img').stop().fadeTo('fast', 1);
	});
	
	
	
	/*
	
	$('#panel_toggler').toggle(
		function() { $('#panel').animate({ height: '280'}, 620,'easeInOutQuint' );
		},
		function() { $('#panel').animate({ height: '0'}, 200 );
	});
	
	*/
	
	$('#panel_toggler').click(function() {
	  $('#panel').slideToggle('620', function() {
	   
	  });
	});
	


	/* HOVER BACKGROUND-COLOR */
	$('#top_left').hover(
	    function() {
	        $(this).stop().animate({backgroundColor: '#83d4f8'}, 10,'easeInOutQuint' );
	        },
			function () {
	        $(this).stop().animate({backgroundColor: '#FFFFFF'})	
	    });

	$('#top_right').hover(
	   function() {
	       $(this).stop().animate({backgroundColor: '#F8F85a'}, 10,'easeInOutQuint' ); 
	       },
		function () {
	       $(this).stop().animate({backgroundColor: '#FFFFFF'})	
	   });



	/* HOVER BACKGROUND-COLOR */
	$('.scroll').click(
		function(){
			$.smoothScroll({scrollTarget: '#player_div', easing: 'easeInOutQuint', speed: 1100});
	 });
	
	
	/* KEYWORDS */
	$('#lookup_keywords').fadeTo('0', 0.3);
	
	$('#lookup_keywords').attr("disabled","disabled");
	
	$('#keywords_select_1, #keywords_select_2, #keywords_select_3').bind('change', function() {
			
			var keywords_1 	= $('#keywords_select_1 :selected').text(); 
			var keywords_2 	= $('#keywords_select_2 :selected').text();
			var keywords_3 	= $('#keywords_select_3 :selected').text();
			
			if ( keywords_1 == 'Choisir...' ) {
				$('#keywords_select_1').parent().css('background-color', 'rgba(255,255,255,0.4)');
				
			} else {
				$('#keywords_select_1').parent().css('background-color', 'rgba(131,212,248,0.6)');
			}
			
			if ( keywords_2 == 'Choisir...' ) {
				$('#keywords_select_2').parent().css('background-color', 'rgba(255,255,255,0.4)');
				
			} else {
				$('#keywords_select_2').parent().css('background-color', 'rgba(248,248,90,0.6)');
			}
			
			if ( keywords_3 == 'Choisir...' ) {
				$('#keywords_select_3').parent().css('background-color', 'rgba(255,255,255,0.4)');
				
			} else {
				$('#keywords_select_3').parent().css('background-color', 'rgba(255,255,255,0.7)');
			}
			
			if ( ( keywords_1 != 'Choisir...' ) || ( keywords_2 != 'Choisir...' ) || ( keywords_3 != 'Choisir...' ) ) {
				$('#lookup_keywords').fadeTo('slow', 1);
				$('#lookup_keywords').removeAttr("disabled");
			}
			else {
				$('#lookup_keywords').fadeTo('slow', 0.3);
				$('#lookup_keywords').attr("disabled","disabled");
			}
		
	});
	
	
	/* LINKS */

	var color_array = new Array("#ebebeb","#dbdbdb","#f0f0f0","#e5e5e5","#e0e0e0","#f5f5f5");	
	
	var links = $('.link_button');
	
	$(links).each( function(index) {		
		$(this).hover(
		   function() {
		       $(this).stop().animate({backgroundColor: color_array[index]}, 'fast' );
			   $(this).find('.link_thumb').stop().fadeTo('fast', 0.2); 
		       },
			function () {
		       $(this).stop().animate({backgroundColor: '#FFFFFF'});
				$(this).find('.link_thumb').stop().fadeTo('slow', 1); 	
		   });
		}
	);
	
	$(links).last().removeClass('links_border_bottom');
	$(links).first().addClass('links_no_padding_top ');
	
	
	
	
	
	$('.item_type_video, .item_type_audio').fadeTo(0, 0);  
		
	var links = $('.item');
	
	$(links).each( function(index) {		
		$(this).hover(
		   function() {
				
				if($(this).hasClass('type_video')){ bgColor = '#F8F85a';}
				if($(this).hasClass('type_audio')){ bgColor = '#83d4f8';}
			
		       $(this).stop().animate({backgroundColor: bgColor}, 'fast' );
			   $(this).find('img').stop().fadeTo('fast', 0.2);
			   $(this).find('.item_type_video, .item_type_audio').stop().fadeTo('fast', 1);  
				
		       },
			function () {
		       $(this).stop().animate({backgroundColor: '#FFFFFF'});
				$(this).find('img').stop().fadeTo('slow', 1);
				$(this).find('.item_type_video,.item_type_audio').stop().fadeTo('slow', 0);  
			    	
		   });
		}
	);

	
	
	/* SLIDERS */

	$(function(){
		$('#slides').slides({
			preload: true,
			generateNextPrev: false
		});
	});

		
	
	/* ROUNDED CORNERS */

	if (!($.browser.msie) )  {
		$('#main, #sub,.rounded_button,.sub_sections').corner('3px');
		$('.ui-rangeSlider-innerBar').corner('2px');
		$('.keywords_box').corner('6px');
	  }
	else {
		//$('.rounded_button,.keywords_box').addClass('explorerBg');
		$('.keywords_box').addClass('explorerBg');
	}

	
	
	/*
	var f = function (event) {
		$('#test').html('progress event time: ' + event.time);
	};
	
	window.connection_stream_progress = f;
	
	var p = document.getElementById('player');
	p.action('addJsListener', ['connection_stream_progress', 'window.connection_stream_progress']);

	*/
	
	//$('#player').action('addJsListener', ['connection_stream_progress', 'window.connection_stream_progress']);

	
	
	$(function () {
		var player = $('#player')[0],
		// custom actions (action that needs to be prepared before they are sent to the player)
		actions = {
			load: function(a) {
				player.action('load', [{id: $('input', a.parent()).val(), autoplay:true}]);
			},
			loadPlay: function(a) {
				player.action('load', [{id: $('.action').attr('id'), autoplay:true}]);
			},
			loadAndPlay: function(a) {
				player.action('load', [{id: $('input', a.parent()).val(), autoplay:true}]);
			},
			transparent: function(a) {
				player.action('load', [$.parseJSON($('input', a.parent()).val())]);
			},
			normal: function(a) {
				player.action('load', [$.parseJSON($('input', a.parent()).val())]);
			},
			changeVolume: function(a) {
				player.action('changeVolume', [{info: {level: $('input', a.parent()).val()}}]);
			},
			changeQuality: function(a) {
				player.action('changeQuality', [{info: {id: $('input', a.parent()).val()}}]);
			},
			seek: function(a) {
				player.action('seek', [{info: {percent: $('input', a.parent()).val()}}]);
			},
			setEmbedMode: function(a) {
				var isTrue = $('select', a.parent()).val() == 'true';
				player.action('setEmbedMode', [isTrue]);
				if (isTrue)
					$('select', a.parent()).val('false');
				else
					$('select', a.parent()).val('true');
			},
			getUid: function(player) {
				// create a new uid					
				if (typeof player.uid == 'undefined')
					player.uid = 'rtsplayer_' + Math.floor(Math.random() * 1000) + '_' + (new Date()).getTime();
				return player.uid;
			},
			addJsListener: function(key, func) {
				// init listeners array (create one if none exists)
				var uid = this.getUid(player);
				if (typeof window[uid] == 'undefined') {
					window[uid] = [];
				}
				window[uid][key] = func;
				player.action('addJsListener', [key, 'window.' + uid + '.' + key]);			
			},
			removeJsListener: function(key) {
				var uid = this.getUid(player);
				if (typeof window[uid] == 'undefined' || typeof window[uid][key] == 'undefined')
					return;
				player.action('removeJsListener', [key, 'window.' + uid + '.' + key]);
			},
			addStreamSetListener: function() {
				this.addJsListener('player_stream_set', function (e) {
					log('stream set event:');
					log(e);
				});
			},
			addProgressListener: function() {
				this.addJsListener('connection_stream_progress', function (e) {
					$('#test').html('progress event time: ' + e.time);
				});
			},
			addPauseListener: function() {
				this.addJsListener('player_pause', function(e) {
					log('player pause');
				});
			},
			addPlayingListener: function() {
				this.addJsListener('player_playing', function(e) {
					log('player playing');
				});
			},
			removePlayingListener: function() {
				this.removeJsListener('player_playing');
			},
			removePauseListener: function() {
				this.removeJsListener('player_pause');
			},
			removeStreamSetListener: function() {
				this.removeJsListener('player_stream_set');
			},
			removeProgressListener: function() {
				this.removeJsListener('connection_stream_progress');
			}
		}, 
		log = function (s) {
			var l = $('#log');
			l.html(l.html() + "\n" + s);
			if (typeof console != 'undefined') {
				console.log(s);
			}
		},
		asReadyCallback = function() {
			log('asReadyCallback');
			player.action('toggleDebug');
		};

		// must be declared in global scope	
		asReadyCallback = asReadyCallback;

		$('a.resize').click(function (i, e) {
			var me = $(this);
			$(player).attr('style', '').css({	
				'width': $('input[name=w]', me.parent()).val(), 
				'height': $('input[name=h]', me.parent()).val()
			});
			return false;
		});
		
		
		// redefine all 'action' links
		$('a.action').bind('click', function(i,e){

			var me = $(this),
			a = me.attr('href').split('#')[1];
			
			// use the custom action when available
			if (actions[a]) {
			
				actions[a](me);
				return false;	
			}

			// by default, directly call the action in the player
			try {
				r = player.action(a);
				if (r != undefined)
					log(r);
			} catch (e) {
				log(e);
			}

			// always cancel the link defautlt behaviour
			return false;
		});
		
	
	
		
		
		
		
		$('.pause').bind('click', function() {
				player.action('pause');
				$('#player').fadeTo('slow', 0.5);
		});
		
		});
		
		
		
		
		var prop_1 			= $('#proposition_1');
		var prop_2 			= $('#proposition_2');
		var prop_3 			= $('#proposition_3');
		var prop_4 			= $('#proposition_4');
		var prop_5 			= $('#proposition_5');
		var prop_6 			= $('#proposition_6');
		var prop_7 			= $('#proposition_7');
		var prop_1_close  	= $('#proposition_1 > p');
		var prop_2_close  	= $('#proposition_2 > p');
		var prop_3_close  	= $('#proposition_3 > p');
		var prop_4_close  	= $('#proposition_4 > p');
		var prop_5_close  	= $('#proposition_5 > p');
		var prop_6_close  	= $('#proposition_6 > p');
		var prop_7_close  	= $('#proposition_7 > p');
		var placeholder		= $('#placeholder');
		var video_container	= $('#video');
		var doc             = $(document);
		doc.data('itemIsTriggered',false);
		
		
	
		$('#close').live('click', function() {
			$(this).triggerAjaxClose();
		});
		
				
		prop_1.live('click', function() {
			//	if(doc.data('itemIsTriggered') == false) {
					var id = $(this).attr('name');
					$(this).triggerAjaxCall('bonus.php?id=' + id);
					$('#player').animate({ opacity: 0.2 },1200,'easeInOutQuint');			//	}
		});
		
		prop_2.live('click', function() {
			//	if(doc.data('itemIsTriggered') == false) {
					var id = $(this).attr('name');
					$(this).triggerAjaxCall('bonus.php?id=' + id);
					$('#player').animate({ opacity: 0.2 },1200,'easeInOutQuint');			//	}
		});
		
		prop_3.live('click', function() {
			//	if(doc.data('itemIsTriggered') == false) {
					var id = $(this).attr('name');
					$(this).triggerAjaxCall('bonus.php?id=' + id);
					$('#player').animate({ opacity: 0.2 },1200,'easeInOutQuint');			//	}
		});
		
		prop_4.live('click', function() {
			//	if(doc.data('itemIsTriggered') == false) {
					var id = $(this).attr('name');
					$(this).triggerAjaxCall('bonus.php?id=' + id);
					$('#player').animate({ opacity: 0.2 },1200,'easeInOutQuint');			//	}
		});
		
		prop_5.live('click', function() {
			//	if(doc.data('itemIsTriggered') == false) {
					var id = $(this).attr('name');
					$(this).triggerAjaxCall('bonus.php?id=' + id);
					$('#player').animate({ opacity: 0.2 },1200,'easeInOutQuint');			//	}
		});
		
		prop_6.live('click', function() {
			//	if(doc.data('itemIsTriggered') == false) {
					var id = $(this).attr('name');
					$(this).triggerAjaxCall('bonus.php?id=' + id);
					$('#player').animate({ opacity: 0.2 },1200,'easeInOutQuint');			//	}
		});
		
		prop_7.live('click', function() {
			//	if(doc.data('itemIsTriggered') == false) {
					var id = $(this).attr('name');
					$(this).triggerAjaxCall('bonus.php?id=' + id);
					$('#player').animate({ opacity: 0.2 },1200,'easeInOutQuint');			//	}
		});
		
		
			// $('body').data('default_id')
		
		
		
		
		
		
		/* PRELOAD */
		if($('body').data('default_id') != ''){
			
			var id = $('body').data('default_id') ;
			
			$.getJSON('ajax_bonus_triggers.php?media_id=' + id, function(triggers) {
						
						if (triggers && triggers.length) {
								var triggers_array = [];
						  		$.each( triggers, function(key, val) {
						    		triggers_array.push(val.bonus_time_trigger);
						 });
						
						}
						
								
					
					
		$('#cartridge').load('ajax_bonus.php?media_id=' + id, function() { });
						
								
				
				var f = function (event) {
				var elapsed_time = event.time;
			 
					
				//	if (!($.browser.msie) )  {
						
							if(elapsed_time > triggers_array[0] && elapsed_time < triggers_array[0] + '.80') { $('#proposition_1').openDrawer(); }
							if(elapsed_time > triggers_array[1] && elapsed_time < triggers_array[1] + '.80') { $('#proposition_2').openDrawer(); }
							if(elapsed_time > triggers_array[2] && elapsed_time < triggers_array[2] + '.80') { $('#proposition_3').openDrawer(); }
							if(elapsed_time > triggers_array[3] && elapsed_time < triggers_array[3] + '.80') { $('#proposition_4').openDrawer(); }
							if(elapsed_time > triggers_array[4] && elapsed_time < triggers_array[4] + '.80') { $('#proposition_5').openDrawer(); }
							if(elapsed_time > triggers_array[5] && elapsed_time < triggers_array[5] + '.80') { $('#proposition_6').openDrawer(); }
							if(elapsed_time > triggers_array[6] && elapsed_time < triggers_array[6] + '.80') { $('#proposition_7').openDrawer(); }
					 
				//	 }
					
				
					
					
					
					
					$.each( triggers_array, function(key, val) {
										if ( elapsed_time > val && elapsed_time < val + '.10') { 
											$('#proposition_' + val ).openDrawer();
										}
					});
					
					
			
			
				};

				window.connection_stream_progress = f;
				$('#player')[0].action('addJsListener', ['connection_stream_progress', 'window.connection_stream_progress']);			

				
				
					});
			
	
			
			
	};

		
		
		
	
			$('a.play_media').live('click', function() {
			
				var id = $(this).attr('id');
				var type = $(this).attr('name');
				
				$('#audio_text, #placeholder').fadeOut('slow', function() { $(this).hide(); })
				$.smoothScroll({scrollTarget: '#player_div', easing: 'easeInOutQuint', speed: 1100});
			
			
				if ( type == 'type_class_1' ) {
					
			  		$('#audio_text').fadeOut('slow', function() {
			  		$('#audio_text').load('ajax_audio_text.php?id='+id).fadeIn(2500);
				
				});
			
			}
			
			
			
			$('#player').fadeTo('slow', 1);					
										
			$.getJSON('ajax_bonus_triggers.php?media_id=' + id, function(triggers) {
						
						if (triggers && triggers.length) {
								var triggers_array = [];
						  		$.each( triggers, function(key, val) {
						    		triggers_array.push(val.bonus_time_trigger);
						 });
						
						}
						
								
					
					
					$('#cartridge').load('ajax_bonus.php?media_id=' + id, function() {
				
						//$('#proposition_1').openDrawer();
				
					});
						
								
				//$('#player')[0].action('load', [{id: media_id, autoplay:true}]);
				
				var f = function (event) {
				var elapsed_time = event.time;
			 
				//	$('#log_div').html(elapsed_time);
					
				//	if (!($.browser.msie) )  {
							if(elapsed_time > triggers_array[0] && elapsed_time < triggers_array[0] + '.80') { $('#proposition_1').openDrawer(); }
							if(elapsed_time > triggers_array[1] && elapsed_time < triggers_array[1] + '.80') { $('#proposition_2').openDrawer(); }
							if(elapsed_time > triggers_array[2] && elapsed_time < triggers_array[2] + '.80') { $('#proposition_3').openDrawer(); }
							if(elapsed_time > triggers_array[3] && elapsed_time < triggers_array[3] + '.80') { $('#proposition_4').openDrawer(); }
							if(elapsed_time > triggers_array[4] && elapsed_time < triggers_array[4] + '.80') { $('#proposition_5').openDrawer(); }
							if(elapsed_time > triggers_array[5] && elapsed_time < triggers_array[5] + '.80') { $('#proposition_6').openDrawer(); }
							if(elapsed_time > triggers_array[6] && elapsed_time < triggers_array[6] + '.80') { $('#proposition_7').openDrawer(); }
					 
				//	 }
					
				
					
					
					
					
					$.each( triggers_array, function(key, val) {
										if ( elapsed_time > val && elapsed_time < val + '.10') { 
											$('#proposition_' + val ).openDrawer();
										}
					});
					
					
			
			
				};

				window.connection_stream_progress = f;
				$('#player')[0].action('addJsListener', ['connection_stream_progress', 'window.connection_stream_progress']);			

				
				
					});
			
			
			
			
			
			
			$('#player')[0].action('load', [{id: id, autoplay:true}]);	
			  return false;
			});

			
			
			
			
			
			
			
	
		
});




