/* Author: GRAMM Développement - 2011

*/

$(document).ready(function() {
	
	$('#containerGamme').hide();
	
	$('.listeGamme').hide();
	
	var container = $( ".listeGamme" );
	
	$('.btGamme').mouseenter(function(e){
		$('#containerGamme').show('fast', function(){
			togglePanel(container);
		});
		e.preventDefault();
	});
	
	$('.page-realisations .btGamme').click(function(e){
		e.preventDefault();
	});
	
	$( ".listeGamme" ).hover(function(){
		$(this).addClass('open').show();
	});
	
	$('.wrapperGamme').mouseleave(function(){
		$('.listeGamme').delay(200).removeClass('open').slideUp( 'medium' , function(){
			$('#containerGamme').hide();
		});
	});
	
	$('#navPages a').hide();
	$('#navReal a span').hide();
	
	$('#navPages li').hover(function(){
		$(this).children('a').slideDown('slow');
	}, function(){
		$(this).children('a').slideUp('slow');
	});

	$('#navReal a.top2bottom').hover(function(){
		$(this).children('span').stop(true, true).slideUp('slow');
		//togglePanel($(this).children('span'));
	}, function(){
		$(this).children('span').slideDown('slow');
	});

	$('#navReal a').hover(function(){
		$(this).children('span').stop(true, true).slideDown('slow');
	}, function(){
		$(this).children('span').slideUp('slow');
	});
	
	if($('#browsable').length){
		var api_scrollable = $("#browsable").scrollable().navigator();
		
		/* Init pour Swipe iPad/iPhone */ 
		$('.swipe').swipe({
			swipeLeft: function() { api_scrollable.next(); },
			swipeRight: function() { api_scrollable.prev(); }
		});
	}
	
	
	
	if($('#diaporamaReal').length){
		initDiapos();
	}
});

function togglePanel(container){
	if(!container.hasClass('open')){
		if (container.is( ":visible" )){
 
			container.slideUp( 'medium' );
 
		} else {
 
			container.slideDown( 'medium' );
 
		}
	}	
}

function initDiapos(){

	$('#zoomProduit .retour').live('click', function(e){
		e.preventDefault();
		$('#zoomProduit').hide().remove();
  		$('.navi').toggle();
  		$('.next').toggle();
  		$('.prev').toggle();		
	});	

	$('.vueReal a').bind('click', function(e){
		e.preventDefault();
		$.get($(this).attr('href'), function(data) {
  			$(data).insertAfter('#browsable');
  			$('#zoomProduit').append('<a href="#" title="Retour" class="retour">retour</a>');
  			/* Cacher les élements de navigation du diaporama */
  			$('.navi').toggle();
  			$('.next').toggle();
  			$('.prev').toggle();
		});		
	});
}















