/***	Module actu_home	***/
$(window).load(function() {
	$('#featured').orbit({
		'bullets': true,
        "advanceSpeed" : 6000,
        "restartClock" : true,
        "restartClockTimer" : 2000,
		'timer' : true,
		'animation' : 'horizontal-slide'
	});
});
/***	Module v5_listing_home***/
// <![CDATA[
$(document).ready(function(){

	//Display Loading Image
	function Display_Load()
	{
	    $("#loadingnews").fadeIn(900,0);
		$("#loadingnews").html("<img src='http://medias.3dvf.com/home/ajax-loader.gif' />");
	}
	//Hide Loading Image
	function Hide_Load()
	{
		$("#loadingnews").fadeOut('slow');
	};


   //Default Starting Page Results
	$("#paginationnews li:first").css({'color' : '#EB4C07'}).css({'border' : 'none'});
	Display_Load();
	$("#contentnews").load("/scripts/pagination_data.php?page=p1", Hide_Load());

	//Pagination Click
	$("#paginationnews li").click(function(){
		Display_Load();	
		
		//CSS Styles
		$("#paginationnews li")
		.css({'border' : 'none'})
		.css({'color' : '#A0A0A0'});
		$(this)
		.css({'color' : '#EB4C07'})
		.css({'border' : 'none'});

		//Loading Data
		var pageNum = this.id;
		$("#contentnews").load("/scripts/pagination_data.php?page=" + pageNum, Hide_Load());
	});


});
// ]]> 
/***	Module inspi_gal_homev2	***/
$(function() {
				/*
				 * just for this demo:
				 */
				$('#showcode').toggle(
					function() {
						$(this).addClass('up').removeClass('down').next().slideDown();
					},
					function() {
						$(this).addClass('down').removeClass('up').next().slideUp();
					}
				);
				$('#panel').toggle(
					function() {
						$(this).addClass('show').removeClass('hide');
						$('#overlay').stop().animate( { left : - $('#overlay').width() + 20 + 'px' }, 300 );
					},
					function() {
						$(this).addClass('hide').removeClass('show');
						$('#overlay').stop().animate( { left : '0px' }, 300 );
					}
				);

				var $container 	= $('#am-container'),
					$imgs		= $container.find('img').hide(),
					totalImgs	= $imgs.length,
					cnt			= 0;

				$imgs.each(function(i) {
					var $img	= $(this);
					$('<img/>').load(function() {
						++cnt;
						if( cnt === totalImgs ) {
							$imgs.show();
							$container.montage({
								fillLastRow				: true,
								alternateHeight			: true,
								alternateHeightRange	: {
									min	: 90,
									max	: 240
								}
							});

							/*
							 * just for this demo:
							 */
							$('#overlay').fadeIn(500);
						}
					}).attr('src',$img.attr('src'));
				});

			});
/*** Effect on Module WIP***/
$(function(){
	$(".size-s").hover(
		function() {
			$(this).css({'opacity':'0.6','filter':'alpha(opacity=60)'});
		},function () {
			$(this).css({'opacity':'1','filter':'alpha(opacity=100)'});
		}
	);
});
/***	Module block_lastMedia	***/
$(function(){
		var widthSlide =670;
		var nbFiches =  $('#nbFiches').val();
		var widthColumn = (100/nbFiches)-2;
		var posLastTab = 1;
		$('#menuLastMedia ul li.lastFilms').addClass('onTab');
		$('.lastMediaColumnLeft,.lastMediaColumnCenter,.lastMediaColumnRight').css("width",""+widthColumn+"%");
		$('#lastFilms .lineFiche').append('<div class="footSlide"><a href="/fiche-cinema.html">Toutes les Fiches Films ...</a></div>');
		$('#lastCourtMetrages .lineFiche').append('<div class="footSlide"><a href="/fiche-courtmetrage.html">Toutes les Fiches Court-Métrages ...</a></div>');
		$('#lastDemoreels .lineFiche').append('<div class="footSlide"><a href="/fiche-demo.html">Toutes les Fiches Démoréels ...</a></div>');
		$('#lastJeuxVideo .lineFiche').append('<div class="footSlide"><a href="/fiche-jeux.html">Toutes les Fiches Jeux Vidéo ...</a></div>');
		$('#lastLivres .lineFiche').append('<div class="footSlide"><a href="/fiche-livres.html">Toutes les Fiches Livres/Magazines ...</a></div>');
		$('#lastPublicites .lineFiche').append('<div class="footSlide"><a href="/fiche-publicite.html">Toutes les Fiches Publicités ...</a></div>');
		$('#blockLastMedia').show('fast');
		
		
		//  Change slide on click on Category
		$('#menuLastMedia ul li').click(function(){
			var whoAmI = $(this).attr("class");		// Define Category selected
			
				switch(whoAmI){ 	// According to whoAmI define all different position of slide
					case "lastFilms": posNowTab=1;	break;
					case "lastCourtMetrages": posNowTab=2;	break;
					case "lastDemoreels": posNowTab=3;	break;
					case "lastJeuxVideo": posNowTab=4;	break;
					case "lastLivres": posNowTab=5;	break;
					case "lastPublicites": posNowTab=6;	break;
				}
		
			$('#menuLastMedia ul li').removeClass('onTab'); 
			$('#menuLastMedia ul li.'+whoAmI).addClass('onTab'); 	// Add activated class to the category selected
			
			if(posLastTab!=posNowTab) {		
				if(posLastTab>posNowTab){		
					while(posLastTab>posNowTab){
						switch(posLastTab){
							case 1: whoWasI="lastFilms";	break;
							case 2: whoWasI="lastCourtMetrages";	break;
							case 3: whoWasI="lastDemoreels";	break;
							case 4: whoWasI="lastJeuxVideo";	break;
							case 5: whoWasI="lastLivres";	break;
							case 6: whoWasI="lastPublicites";	break;
						}
						
						$('#sliderLastMedia:nth-child(1)').animate({
							"margin-left": "+="+widthSlide+"px"
						},
						{	duration:800,
							step: function(now, fx) {
								var myPos =  now;
								var myLinkPos = myPos/-widthSlide;
								myLinkPos = Math.round(myLinkPos);
									switch(myLinkPos){
										case 0: myCatSwitch="lastFilms";	break;
										case 1: myCatSwitch="lastCourtMetrages";	break;
										case 2: myCatSwitch="lastDemoreels";	break;
										case 3: myCatSwitch="lastJeuxVideo";	break;
										case 4: myCatSwitch="lastLivres";	break;
										case 5: myCatSwitch="lastPublicites";	break;
									}
								$('#menuLastMedia ul li').not('onTab').css("background-color","#2E2E2E");
								$('#menuLastMedia ul li.'+myCatSwitch+'').css("background-color","#404040");
							}
						});
					posLastTab=posLastTab-1;
					}
				} else if(posLastTab<posNowTab) {
					while(posLastTab<posNowTab){
						switch(posLastTab){
							case 1: whoWasI="lastFilms";	break;
							case 2: whoWasI="lastCourtMetrages";	break;
							case 3: whoWasI="lastDemoreels";	break;
							case 4: whoWasI="lastJeuxVideo";	break;
							case 5: whoWasI="lastLivres";	break;
							case 6: whoWasI="lastPublicites";	break;
						}
							
						$('#sliderLastMedia:nth-child(1)').animate({
							"margin-left": "-="+widthSlide+"px"
						},
						{	duration:800,
							step: function(now, fx) {
								var myPos =  now;
								var myLinkPos = myPos/-widthSlide;
								myLinkPos = Math.round(myLinkPos);
									switch(myLinkPos){
										case 0: myCatSwitch="lastFilms";	break;
										case 1: myCatSwitch="lastCourtMetrages";	break;
										case 2: myCatSwitch="lastDemoreels";	break;
										case 3: myCatSwitch="lastJeuxVideo";	break;
										case 4: myCatSwitch="lastLivres";	break;
										case 5: myCatSwitch="lastPublicites";	break;
									}
								$('#menuLastMedia ul li').not('onTab').css("background-color","#2E2E2E");
								$('#menuLastMedia ul li.'+myCatSwitch+'').css("background-color","#404040");
							}
						});
					posLastTab=posLastTab+1;
					}
				}
			posLastTab = posNowTab;
			}
		});
		
		// Add an Hover effect on Column (Change border picture and title color)
		$('.lastMediaColumnLeft,.lastMediaColumnCenter,.lastMediaColumnRight').hover(
			function () {
				var iAmHover = $(this).attr("id");
				$('#'+iAmHover).css("background-color","#404040");
				$('#'+iAmHover+' a p.imgFiche img').css("border","1px solid #00FFD5");
				$('#'+iAmHover+' a p.titleFiche').css({"color":"#00FFD5","text-decoration":"none"});
			}, function () {
				var iAmHover = $(this).attr("id");
				$('#'+iAmHover).css("background-color","transparent");
				$('#'+iAmHover+' a p.imgFiche img').css("border","1px solid transparent");
				$('#'+iAmHover+' a p.titleFiche').css({"color":"#0AF","text-decoration":"none"});
			}
		);
});
/***	Module mod_calendar ***/
$(document).ready(function(){

	var centerPos = $('#recordPos').val(); // Get position of the last month event
	var height_slide = 40; // Height of slide
	var nb_event = $('#nb_res').val(); // Get event numbers
	var eventToShow = $('#toShow').val(); // According to the Height of  Slide
	var centerPos2=centerPos-eventToShow;
	var minHeight=eventToShow*height_slide;  // Minimal Height of the Event menu
	var maxHeight=nb_event*height_slide;	// Height of the list Event
	var limit_PastEvent = (nb_event-eventToShow)*height_slide; // Calcul When the slider stop
	var desc_state =""; var move_count=0;
	var height_desc=4*height_slide; // Height of Desc
	var limit_To_PastEvent = limit_PastEvent; // When the slider stop
	var menuHeight=minHeight+(height_slide/2);
	
	if(centerPos==0) {	// To center on event Now have to be define by the BDD
		var max_margin_topslider = 0; 
	}
	else if (centerPos2<0) {
		var max_margin_topslider = 0; 
	} else {
		var max_margin_topslider = (centerPos-centerPos2)*height_slide;
	}
			// Initialisation du menu
	$('.mod_menuEvent').css('height',menuHeight+'px');		// Define Height of Event menu
	$('.main_mod_menuEvent').css('height',minHeight+'px');	// Define Height of the apparent list
	$('.mod_menuEvent_slider').css('height',maxHeight+'px');// Define Height of the list
	$('.list_modEvent:first').css({"margin-top":"-"+max_margin_topslider+"px"});	// Center the Event menu on current event
	$('.my_mod_calendar').show('fast');
	
	
	function Default_menu () { // Function to set calendar's module to his default settings
			$('.desc_mod_event').slideUp();
			$('.mod_menuEvent_slider li').removeClass("activated_menu");
			desc_state="disabled"; limit_To_PastEvent=limit_PastEvent;
	}
	
	// Change Opacity onMouseHover / If title too big -> Show date onMouseHover
	$(".mod_menuEvent li").not(".desc_mod_event,#top_menuEvent,#bottom_menuEvent").hover(
		function() {
			var here = $(this).attr("id");
			var howLength = $("#date_"+here).css('display');
				if(howLength=="none") {
					$("#title_"+here).hide('fast');
					$("#date_"+here).show('slow');
				}
			$(this).css({'opacity':'0.6','filter':'alpha(opacity=60)'});
		},function () {
			var here = $(this).attr("id");
			var howLength = $("#title_"+here).css('display');
				if(howLength=="none") {
					$("#date_"+here).hide('fast');
					$("#title_"+here).show('slow');
				}
			$(this).css({'opacity':'1','filter':'alpha(opacity=100)'});
		}
	);
	
	$(".mod_menuEvent li#top_menuEvent").hover( // Change color and text of menu's top
		function() {
			$(this).css("background-color","rgb(158,11,15)").text("Cliquez ICI pour aller aux prochains évènements");
		},function () {
			$(this).css("background-color","#2e2e2e").text("Prochainement ...");
		}
	);
	$(".mod_menuEvent li#bottom_menuEvent").hover( // Change color and text of menu's bottom
		function() {
			$(this).css("background-color","rgb(158,11,15)").text("Cliquez ICI pour aller aux évènements antérieur");
		},function () {
			$(this).css("background-color","#2e2e2e").text("Anterieur ...");
		}
	);

	// Show Content onClick event
	$(".list_modEvent").click(
		function() {
			var classExist = $(this).attr("class");
				// Set the menu to Default if the current event is already activated
			if ((classExist =="list_modEvent activated_menu")||(classExist =="list_modEvent abroad_event activated_menu")||(classExist =="list_modEvent dev3dvf_event activated_menu") ){
					Default_menu(); 
			} else {
					var initModEvent= $('.mod_menuEvent_slider li:first').offset(); // Get initial position of first event
					var initPosEvent= initModEvent.top;
					initPosEvent=initPosEvent+max_margin_topslider;
					var posEvent = $(this).offset(); var posActuEvent = posEvent.top; // Get current position of selected event
					var id_content = $(this).attr("id");
					
				if(initPosEvent!=posActuEvent) {
						whereToMove = posActuEvent - initPosEvent;	// Define where to move
						whereToMove = whereToMove - move_count;		// Substract move_count to current movement
					if(desc_state=="activated") {	
						whereToMove = whereToMove-height_desc;		// Substract description height to current movement
						limit_To_PastEvent=limit_PastEvent+height_desc;
					}
					$(".list_modEvent:first").stop(true, true).animate({"margin-top": "-="+whereToMove+"px"}, "slow");
					move_count=move_count+whereToMove; 		// Increment move_count with the current movement
				}
				$('.mod_menuEvent_slider li').removeClass("activated_menu");
				$('.desc_mod_event').slideUp();
				$(this).addClass("activated_menu");
				$('#desc_'+id_content).slideDown();
				desc_state="activated";
			}
		}
	);
	
	// Move on Soon Event
	$("#top_menuEvent").click( function() {
			var margFirst = $('.list_modEvent:first').css('marginTop');
			var lgtMargFirst = margFirst.length;
			var limFirst = lgtMargFirst-2;
			var margTopFirst = margFirst.substr(0,limFirst);		// Get the margin-top value
				Default_menu();		// Set the default menu
			if(margTopFirst < 0){
				$('.list_modEvent:first').stop(true,true).animate({"margin-top": "+="+height_slide+"px"}, "slow");
				move_count=move_count-height_slide; 	// Deduct movement on move_count
			}
	} );
	
	// Move on Past Event
	$("#bottom_menuEvent").click( function() {
			var margFirst = $('.list_modEvent:first').css('marginTop');
			var lgtMargFirst = margFirst.length;
			var limFirst = lgtMargFirst-2;
			var margTopFirst = margFirst.substr(0,limFirst);	 // Get the margin-top value
				Default_menu();		// Set the default menu
			if(margTopFirst > -limit_To_PastEvent ){
				$('.list_modEvent:first').stop(true,true).animate({"margin-top": "-="+height_slide+"px"}, "slow");
				move_count=move_count+height_slide;		// Count movement on move_count
			}
	} );		
});
