/**
 * 
 */

$( function(){
	//MenuDeroulant.init();
	changeTexte.init();
	//PageReconstruction.init();
	MailEnvoi.init();
	Reequilabrage.init();
	Diapo.init();
	SupprimerTitleImage.init();
	SupprimerTextLangue.init();
	SuppressionPBRgenereParTiny.init();
	filArianeSuppHomeEnHome.init();
	NavDroitePress.init();
	ParaPossedantImgEffaceMarge.init();
	Ombre.init();
	lienALAMANO.init();
	RechercheVille.init();
	
	CreerTonLook.init();
	
	$( '.thumb' ).click( function(){
		if( $( '.image-wrapper' ).is( ':animated' ) ) return false;
	});
	   $('#slider-one').movingBoxes({
	    startPanel  : 3,     // start with this panel
	    width       : 695,   // overall width of movingBoxes
	    panelWidth  : 0.3,    // current panel width adjusted to 50% of overall width
	    imageRatio  : 16/9,  // Image ratio set to 16:9
	    fixedHeight  : false,
	    buildNav     : true, // if true, navigation links will be added
		reducedSize : 1,
	    navFormatter : function(index, panel){ return panel.find('h2 span').text(); }, // function which gets nav text from span inside the panel header
	    
	   });
	
	   $('#slider-two').movingBoxes({
	    startPanel  : 3,     // start with this panel
	    width       : 600,   // overall width of movingBoxes
	    panelWidth  : .7,    // current panel width adjusted to 50% of overall width
	    imageRatio  : 16/9,  // Image ratio set to 16:9
	    buildNav     : true, // if true, navigation links will be added
	    navFormatter : function(index, panel){ return panel.find('h2 span').text(); }, // function which gets nav text from span inside the panel header
	   });
	
	   // Example of how to move the panel from outside the plugin, only works on first selector (Use ID instead of class to target other movingboxes).
	   // get: var currentPanel = $('.slider').data('movingBoxes').currentPanel(); // returns # of currently selected/enlarged panel
	   // set: var currentPanel = $('.slider').data('movingBoxes').currentPanel(2); // scrolls to 2nd panel & returns 2.
	
	   // Set up demo external navigation links
	   var i, t = '', len = $('#slider-one .panel').length + 1;
	   for ( i=1; i<len; i++ ){
	    t += '<a href="#" rel="' + i + '">' + i + '</a> ';
	   }
	   $('.dlinks')
	    .find('span').html(t).end()
	    .find('a').click(function(){
	     $('#slider-one').data('movingBoxes').currentPanel( $(this).attr('rel') );
	     return false;
	    });
	
	   // Report events to firebug console
	   $('.slider').bind('initialized initChange beforeAnimation completed',function(e, slider, tar){
	    // show object ID + event in the firebug console
	    if (window.console && window.console.firebug){
	     var txt = slider.$el[0].id + ': ' + e.type + ', now on panel #' + slider.curPanel
	     txt += (typeof(tar) == 'undefined') ? '' : ', targeted panel is ' + tar;
//	     console.debug( txt );
	    }
	   });
	
	
	// Initially set opacity on thumbs and add
	// additional styling for hover effect on thumbs
	
	
	onMouseOutOpacity = 0.5;

	$( '#controls' ).fadeTo( 0, 0.0 );
	$( '#caption' ).fadeTo( 0,	 0.0 );
	$( '.ss-controls' ).css( 'display','none' );
	
	
	$( '#gallery' ).mouseenter( 
		function(){
			$( '#controls' ).fadeTo( 400, 1.0 );
			$( '.ss-controls' ).css( 'display','none' );
			// Cache le bloc de texte $( '#caption').fadeTo( 400, 1.0 );
		}).mouseleave(
		function(){
			$( '#controls' ).fadeTo( 600, 0.0 );
			// Cache le bloc de texte$( '#caption' ).fadeTo( 600, 0.0 );
			$( '.ss-controls' ).css( 'display','none' );
		}
	);
		
	$('#thumbs ul.thumbs li').opacityrollover({
		mouseOutOpacity:   onMouseOutOpacity,
		mouseOverOpacity:  1.0,
		fadeSpeed:         'fast',
		exemptionSelector: '.selected'
	});
	
	var gallery = $('#thumbs').galleriffic({
	        delay:                     2500, // in milliseconds
	        numThumbs:                 parseInt( $( '#NIMAGEPARPAGE' ).text() ), // The number of thumbnails to show page
	        preloadAhead:              40, // Set to -1 to preload all images
	        enableTopPager:            false,
	        enableBottomPager:         true,
	        maxPagesToShow:            7,  // The maximum number of pages to display in either the top or bottom pager
	        imageContainerSel:         '#slideshow',
	        captionContainerSel:       '#caption',
	        controlsContainerSel:      '#controls',
	        loadingContainerSel:       '#loading',
	        renderSSControls:          true, // Specifies whether the slideshow's Play and Pause links should be rendered
	        renderNavControls:         true, // Specifies whether the slideshow's Next and Previous links should be rendered
	        playLinkText:              'Play',
	        pauseLinkText:             'Pause',
	        prevLinkText:              "<img src='"+$( '#BTNPRE' ).text()+"'/>",
	        nextLinkText:              "<img src='"+$( '#BTNSUI' ).text()+"'/>",
	        nextPageLinkText:          '&rsaquo;',
	        prevPageLinkText:          '&lsaquo;',
	        enableHistory:             false, // Specifies whether the url's hash and the browser's history cache should update when the current slideshow image changes
	        enableKeyboardNavigation:  true, // Specifies whether keyboard navigation is enabled
	        autoStart:                 false, // Specifies whether the slideshow should be playing or paused when the page first loads
	        syncTransitions:           false, // Specifies whether the out and in transitions occur simultaneously or distinctly
	        defaultTransitionDuration: 900, // If using the default transitions, specifies the duration of the transitions
	        onSlideChange:             function(prevIndex, nextIndex) {
	        	// 'this' refers to the gallery, which is an extension of $('#thumbs')
	        	this.find('ul.thumbs').children()
	        		.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
	        		.eq(nextIndex).fadeTo('fast', 1.0);
	        },
	        onPageTransitionOut:       function(callback) {
	        	this.fadeTo('fast', 0.0, callback);
	        },
	        onPageTransitionIn:        function() {
	        	this.fadeTo('fast', 1.0);
	        }
	    });
	
});

lienALAMANO = {
	init : function()
	{
		$( 'img' ).removeAttr( 'height');
		$( 'img' ).removeAttr( 'width');
		
		//$( '#navSecondaire li:first' ).addClass( 'premiereLINavSec' );
		
		var imageComing = $( 'p:has(img[src$=coming_soon.jpg])' );
		var fresh = $( 'a:has(img[src$=fresh_news_img.png])' );
		var marque = $( 'a:has(img[src$=la_marque_img.png])' );
		var magasin = $( 'a:has(img[src$=magasins.png])' );
		var onparle = $( 'a:has(img[src$=on_en_parle_img.png])' );
		
		var presseFREN = $( '.icl-en a[ href$="com?lang=en"], .lang_.icl-en a[ href$="/en/" ]' ); // dans le cas ou on est sur presse fr et qu'on clique sur en*/
		presseFREN.attr( 'href', 'http://www.letempsdescerisesjeans.com/?page_id=1243&lang=en' );
		/*var presse = $( 'a[href$=750]' );
		var presseEN = $( 'a[href$="391&lang=en"]' );
		
		
		//imageComing.css( 'margin', 0 );
		
		//presse.attr( 'href', 'http://www.letempsdescerisesjeans.com/?page_id=742' );
		//presseEN.attr( 'href', 'http://www.letempsdescerisesjeans.com/?page_id=1462&lang=en' );
		//presseFREN.attr( 'href', 'http://www.letempsdescerisesjeans.com/?page_id=1462&lang=en' );
		
		/*fresh.attr( 'href','http://www.letempsdescerisesjeans.com/?page_id=685');
		marque.attr( 'href','http://www.letempsdescerisesjeans.com/?page_id=320');
		magasin.attr( 'href','http://www.letempsdescerisesjeans.com/?page_id=323');
		onparle.attr( 'href','http://www.letempsdescerisesjeans.com/?page_id=742');*/
	}
};

ParaPossedantImgEffaceMarge = {
	init : function()
	{
		ParaPossedantImgEffaceMarge.para = $( 'p:has( img )' );
		
		ParaPossedantImgEffaceMarge.para.css( 'margin',0 );
	}
};

filArianeSuppHomeEnHome = {
	init : function(){
		$( '.post-727 #menu li:first' ).addClass( 'current-menu-item' );
		$( '#filAriane a:first' ).attr( 'href','http://www.letempsdescerisesjeans.com/?page_id=675' );
		$( '.langue-en #filAriane a:first' ).attr( 'href','http://www.letempsdescerisesjeans.com/?page_id=1243' );
		$( '.post-675 #filAriane,.post-1243 #filAriane' ).html( 'Home' );
	}
};

SupprimerTextLangue = {
	init : function()
	{
		
		$( '#lang_sel_list li' ).each( function(){
			var image = $( this ).children( 'a' ).children( 'img' );
			
			$( this ).children( 'a' ).empty();
			
			$( this ).children( 'a' ).append( image );
		});
	}
	
};

SuppressionPBRgenereParTiny = {
	init : function()
	{
		SuppressionPBRgenereParTiny.balise = $( 'p:has( br[class=spacer_] )' );
		SuppressionPBRgenereParTiny.balise.hide();
	}
	
};

MenuDeroulant = {
	init : function(){
		MenuDeroulant.lien = $( '#menu' ).children( 'li' );
		MenuDeroulant.sousmenu = MenuDeroulant.lien.children( 'ul' );
		MenuDeroulant.sousmenu.hide();
		
		MenuDeroulant.auSurvole();
	},

	auSurvole : function()
	{
		MenuDeroulant.lien.mouseenter( function(){
			MenuDeroulant.lien.children( 'ul' ).slideUp();
			if( $( this ).children( 'ul' ).is( ':animated' ) )
			{
				$(this).children( 'ul' ).stop( true, true);
				$(this).children( 'ul' ).slideDown();
			}
			
			if( $( this ).children( 'ul' ).is( ':hidden' ) ) $(this).children( 'ul' ).slideDown(); 
		});
		MenuDeroulant.lien.mouseleave( function(){
			MenuDeroulant.lien.children( 'ul' ).slideUp();
		});
	}
};

SupprimerTitleImage = {
	init : function()
	{
		$( 'img' ).attr( 'title','' );
	}
};

changeTexte = {
	init : function(){
		changeTexte.mention = $('.blocCache.mention').text();
		changeTexte.contactez = $( '.blocCache.contactez' ).text();
		
		changeTexte.mentionSauve = $( '#mention' ).html();
		changeTexte.contactezSauve = $( '#contactez' ).html();		
		
		changeTexte.credit = $( '#credit a' );
		
		changeTexte.credit.hover( 
			function(){
				if( $( '#mention' ).is( ':animated' ) == false )
				{
					$( '#mention' ).fadeOut(0).fadeIn(200);
					$( '#contactez' ).fadeOut(0).fadeIn(200);
					
					$( '#mention' ).html(changeTexte.mention );
					$( '#contactez' ).html( changeTexte.contactez );
				}
			},	
			function(){
				$( '#mention' ).fadeOut(0).fadeIn(200);
				$( '#contactez' ).fadeOut(0).fadeIn(200);
				
				$( '#mention' ).html( changeTexte.mentionSauve );
				$( '#contactez' ).html( changeTexte.contactezSauve );
			} 
		);
		changeTexte.credit.click( function(){ return false; });
	}
};

OmbrePortee = {
		init : function(){
			OmbrePortee.obOmbre = $( '.objetAvecOmbre' );
			
			OmbrePortee.obOmbre.PastelShadow(
	            {
	                x: 3,
	                y: 3,
	                blur: 5,
	                color: "#333"
	            }
	        );
		}
};

PageReconstruction = {
	init : function(){
		PageReconstruction.titre1 = $( '#contenuTexte h1' );
		PageReconstruction.titre2 = $( '#contenuTexte h2' );
		
		if( PageReconstruction.titre2.html() != null )
		{
			PageReconstruction.media = PageReconstruction.titre2.next( '*' );
		}
		else
		{
			PageReconstruction.media = PageReconstruction.titre1.next( '*' );
		}
		
		PageReconstruction.reconstruire();
	},
	
	reconstruire : function(){
		if( PageReconstruction.titre1.html() != null && PageReconstruction.titre2.html() != null )
		{
			$( '#pageConstructonColonne1' ).prepend( '<div><hr/><h1>'+PageReconstruction.titre1.html()+'</h1><h2>'+PageReconstruction.titre2.html()+'</h2></div>' );
		}
		else if ( PageReconstruction.titre1.html() == null && PageReconstruction.titre2.html() != null )
		{
			$( '#pageConstructonColonne1' ).prepend( '<div><hr/><h2>'+PageReconstruction.titre2.html()+'</h2></div>' );
		}
		else if ( PageReconstruction.titre1.html() != null && PageReconstruction.titre2.html() == null )
		{
			$( '#pageConstructonColonne1' ).prepend( '<div><hr/><h1>'+PageReconstruction.titre1.html()+'</h1></div>' );
		}
		
		if( PageReconstruction.media.html() != 'null' )
		{
			$( '#pageConstructonColonne2' ).prepend( PageReconstruction.media.html() );
			PageReconstruction.titre2.remove();
		}	
		
		
		PageReconstruction.titre1.remove();
		PageReconstruction.media.remove();
	}
};

Diapo = {
	init : function(){
		
		Diapo.btnSui = $( '#btnSUI' );
		
		Diapo.btnSui.click( function(){
			
			if ( $( '#diapoContent .nDiapo' ).is( ':animated' ) == false )
			{
				Diapo.transition();
			}
			
			return false;
		});
	},
	
	transition : function(){
		
		var $active = $('#diapoContent .nDiapo.active');
		
	    if ( $active.length == 0 ) $active = $('#diapoContent .nDiapo:last');
	
	    var $next =  $active.next().length ? $active.next()
	        : $('#diapoContent .nDiapo:first');
	
	    $active.addClass('derniere');
	
	    $next.css({opacity: 0.0})
	        .addClass('active')
	        .animate({opacity: 1.0}, 1000, function() {
	            $active.removeClass('active derniere');
	        });
	}
}

NavDroitePress = {
	init : function()
	{
		NavDroitePress.bloc1 = $( '.post-329 #navSecondaire li:first, .post-742 #navSecondaire li:first, .post-755 #navSecondaire li:first, .post-1456 #navSecondaire li:first, .post-1462 #navSecondaire li:first' );
		NavDroitePress.bloc2 = $( '.post-329 #navSecondaire li:last, .post-742 #navSecondaire li:last, .post-755 #navSecondaire li:last, .post-1456 #navSecondaire li:last, .post-1462 #navSecondaire li:last' );
		
		NavDroitePress.bloc1.addClass( 'navDPresse1' );
		NavDroitePress.bloc2.addClass( 'navDPresse2' );
	}
};

MailEnvoi = {
	/*
		apartir de l'id du form 
		je boucle pour recupere chaque enfant stoquer dans un tableau var lesInputs_tab
		ensuite pour chaque enfant je stoque la valeur dans var valeurInputs_tab
	*/
	init : function()
	{
		/*MailEnvoi.champsMail = $( '#champsMail' );
		MailEnvoi.contenu = MailEnvoi.champsMail.val();
		
		MailEnvoi.champsMail.focus( function() {
			
			if( $( this ).val() == MailEnvoi.contenu )
			{
				$( this ).val( '' );
			}
		});
		MailEnvoi.champsMail.blur( function(){
			if( $( this ).val() == '' )
			{
				$( this ).val( MailEnvoi.contenu );
			}
		});*/
		MailEnvoi.valeurCache = '';
		
		$( '.wpcf7 form input[type="text"]' ).focus( function( e ){
			MailEnvoi.contenu =  $( e.target ).val();
			
			if( $( this ).val() == MailEnvoi.contenu )
			{
				$( this ).val( '' );
				
				MailEnvoi.valeurCache = MailEnvoi.contenu;
			}
		});
		
		$( '.wpcf7 form input[type="text"]' ).blur( function( e ){
			MailEnvoi.contenu =  $( e.target ).val();
			
			if( $( this ).val() == '' )
			{
				$( this ).val( MailEnvoi.valeurCache );
			}
		});
	}
};

Reequilabrage = {
	init : function(){
		Reequilabrage.tdSurDeux = $( '#zoneTexte td:even' );
		
		Reequilabrage.tdSurDeux.addClass( 'colonneDeGaucheGrand' );
	}
};

RechercheVille = {
	init : function(){
		RechercheVille.selecteur = $( '#rechercheUneVille' );
		
		if( $( '#cacheImage' ).val() != undefined )
		{
			$( '.premiere img' ).remove();
			$( '.premiere' ).addClass( 'premierePetit' );
			$( '.deuxieme' ).addClass( 'deuxiemeGrand');
		}
		
		
		RechercheVille.selecteur.change( function(){
			$( this ).submit();
		});
	}
}

Ombre = {
	init : function(){
		
		//alert( $( '.nDiapo:first-child' ).children( 'span' ).html() );
		$( '.nDiapo:last-child' ).children( 'span' ).addClass( 'ombreImage' );
	}
}

CreerTonLook = {

	init : function(){
		$( '.panel' ).click( function(){
            index = $(this).attr('id').replace('panel', '');
			CreerTonLook.prenom = $( '.prenomCreerLook'+index).html();
			CreerTonLook.ville = $( '.villeCreerLook'+index).html();
			CreerTonLook.img = $( '.imgCreerLook'+index).html();
			
			$( '.vignettephoto strong' ).text( CreerTonLook.prenom );
			$( '.vignettephoto em' ).text( CreerTonLook.ville );
			$( '#imagePrinCreer img' ).attr( 'src', CreerTonLook.img );
		});
		
		// Gestion du style du bouton d'upload
		$("input[type=file]").filestyle({ 
			 image: "/wp-content/themes/mongi/images/enfants/lookderue/parcourir.png",
			 imageheight : 22,
			 imagewidth : 82,
			 width : 145
		 });
	}
}


