$(document).ready(function() {
   resize();
  $(".fancybox").fancybox();
   //gallerifficInit( ) ;

  	$.easing.elasout = function(x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	}; 

   $.easing.easeOutQuart = function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	};
 });
 $(window).resize(function() {
  resize();
});

 function resize(){
	 //if($(window).height());
	 $('#fonds #img_1').height($(window).height());
	 $('#fonds').height($(window).height());
//	 $('#img_1').height($(window).height()-4);
	 //$('#img_2').css("top",$(window).height() / 2 - 50);
	 }
	

	
function pointsdevente(){
	
	$('#pane-target div').hide(); // on cache les points de vente puis on les balaye pour fabriquer les options du select par magasin
	$('#pane-target div > span:first-child').each(function(index) {
		$('#pane-nave').append( $('<option value="'+  $(this).parent().attr('id') +'">' + $(this).text() + '</option>') );
	});
	
}
	

	
function pointsdeventescrollagence(id){	
	if ($("#pane-target  #imgPtVente").is(":visible")) {
		//$('#pane-target img').slideUp(750,'easeOutQuart');
		//$('#pane-target img').animate({opacity: 0, height: 'toggle'},500);
		$('#pane-target #imgPtVente').animate({opacity: [0, 'easeOutQuart'], height: [0, 'easeOutQuart']},500);
	}
	$('#select_dept').attr("selected","selected") ;
	
	$('#pane-target div').slideUp();
	$('#pane-target #'+id).show();	
}
	
function pointsdeventeaffichedept(id){	
	if ($("#pane-target #imgPtVente").is(":visible")) {
		//$('#pane-target img').slideUp(750,'easeOutQuart');
		$('#pane-target #imgPtVente').animate({opacity: [0, 'easeOutQuart'], height: [0, 'easeOutQuart']},500);
	}
	$('#select_ville').attr("selected","selected") ; 
	
	$('#pane-target div').hide();
	$('#pane-target .'+id).show();
	//if(!$('#pane-target div:not(:hidden)').size()>0){$('#pane-target img').stop().slideDown(750,'easeOutQuart');} // si aucun point de vente pour ce dpt on affiche l'image
	//$('#imgPtVente').height()
	if(!$('#pane-target div:not(:hidden)').size()>0){$('#pane-target  #imgPtVente').stop().animate({opacity: 1, height: ['200px', 'easeOutQuart']},500);} // si aucun point de vente pour ce dpt on affiche l'image
}	


	 
function gallerifficInit(){
   
				// Initially set opacity on thumbs and add
				// additional styling for hover effect on thumbs
	
   				// We only want these styles applied when javascript is enabled
				$('div.navigation').css({'width' : '508px', 'float' : 'left', 'margin-left' : '62px' });
				$('div.slideshow').css({'width' : '395px', 'float' : 'right'});
				$('div.content').css('display', 'block');	
				
				var onMouseOutOpacity = 0.87;
				$('.navigation ul.thumbs li').opacityrollover({
					mouseOutOpacity:   onMouseOutOpacity,
					mouseOverOpacity:  1.0,
					fadeSpeed:         'fast',
					exemptionSelector: '.selected'
				});
				
				// Initialize Advanced Galleriffic Gallery
				var gallery = $('#thumbs').galleriffic({
					delay:                     2500,
					numThumbs:                 24,
					preloadAhead:              10,
					enableTopPager:            false,
					enableBottomPager:         true,
					maxPagesToShow:            7,
					imageContainerSel:         '#slideshow',
					controlsContainerSel:      '#controls',
					captionContainerSel:       '#caption',
					loadingContainerSel:       '#loading',
					renderSSControls:          true,
					renderNavControls:         true,
					playLinkText:              'Play Slideshow',
					pauseLinkText:             'Pause Slideshow',
					prevLinkText:              '&lsaquo; Previous Photo',
					nextLinkText:              'Next Photo &rsaquo;',
					nextPageLinkText:          'Next &rsaquo;',
					prevPageLinkText:          '&lsaquo; Prev',
					enableHistory:             false,
					autoStart:                 false,
					syncTransitions:           true,
					defaultTransitionDuration: 900,
					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);
					}
				});

   
   
};












	
function pointsdevente_adet(){
/*
$('#pane-nave li').each(function(index) {
    //alert(index + ': ' + $(this).text());
	//alert(index + ': ' + $(this).attr("dest"));
	
	
   	$(this).click(function(){

		//$('#pane-target').stop().scrollTo( $(this).attr("dest"), 800, {easing:'elasout'} );
		$('#pane-target').stop().scrollTo( $(this).attr("dest"), 800, {easing:'easeOutQuart'} );
	});
	
  });
*/
$('#pane-target div').hide();	
$('#pane-target div > span:first-child').each(function(index) {
    //alert(index + ': ' + $(this).text());
	//alert(index + ': ' + $(this).parent().attr('id'));
	var id = $(this).parent().attr('id') ;	
		
	
	//alert(index + ': ' + $(this).text());
//	var temp_  = document.createElement('li').text($(this).text()).click(function() {alert(index + ': ' + id );	});
	//var temp_  = document.createElement('li').text('llllllllllll');
	//var temp_  = $('<li>' + $(this).text() + '</li>').click(function() {   $('#pane-target').stop().scrollTo( '#'+id , 800, {easing:'easeOutQuart'} );	});
//	temp_.css('cursor','pointer');
	
	//var temp_  = $('<option>' + $(this).text() + '</option>').click(function() {   $('#pane-target div').show();$('#pane-target').stop().scrollTo( '#'+id , 800, {easing:'easeOutQuart'} );	});
	var temp_  = $('<option id="ville_'+index+'">' + $(this).text() + '</option>').click(function() {   
			$('#select_dept').attr("selected","selected") ;$('#pane-target div').hide();$('#pane-target img').hide(500);$('#pane-target #'+id).show();	
		});
	
	$('#pane-nave').append(temp_);
/*	
	$('#pane-nave').change(function(){
			alert($(this).val());
						 });*/
	
  });




$('#departement option').each(function(index) {
    //alert(index + ': ' + $(this).text());
	//alert(index + ': ' + $(this).parent().attr('id'));

	$(this).click(function(){   
		$('#pane-target img').hide(500);
		$('#pane-target div').hide();
		$('#pane-target .'+$(this).attr('value')).show();
		if(!$('#pane-target div:not(:hidden)').size()>0){$('#pane-target img').stop().show(500);}
		$('#select_ville').attr("selected","selected") ;  		
	});

  });



}


