//****** JS Portefolio || Scripted and Performed by Benoît Dietrich ©******/


//***** Fonction pour faire défiler les photos à l'horizontal

slider = function(flex){

	var slider = flex.children('.slider');
	var largeurCache = flex.width();
	var largeur = 0;
	
	flex.find('a').each(function(){
        largeur+=$(this).width();
    });
	
	var prec = flex.find('.prec');
	var suiv = flex.find('.suiv');
	var saut = largeurCache/2;
	var nbEtapes = Math.ceil(largeur/largeurCache)-2;
	var courant = 0;
			
	prec.find('img').hide();
		
	suiv.hover(function(){
		if(courant<nbEtapes){
			courant++;
			prec.find('img').show();
			slider.animate({
				left: -courant*saut
			}, 500);
			if(courant==nbEtapes){
				suiv.find('img').hide();
			}
		}
	
	});
	
	prec.hover(function(){
		if(courant>0){
			courant--;
			suiv.find('img').show();
			slider.animate({
               	left: courant*-saut
           	},500);
           	if(courant==0){
               prec.find('img').hide();
            }
		}
	});
}

//***** Quand le document est pret :: JQUERY


$(document).ready(function(){


    //**** Faire défiler la navig d'un objet
    
    slider($('#jobicoVideo'));
	slider($('#jobicoPhoto'));
	slider($('#jobicoWeb'));
	slider($('#jobicoGraphisme'));
    
    //**** Desactiver le rechargement de la page
    
    $('.slider a').click(function(e){
        e.preventDefault();
    });
    
    
    //**** AJAX et Ouverture Photo
    
    $('#navPhoto a').click(function(){
        var flex = $(this).attr('title');

        $('.thisImage').html('');
        $('.jobico').css({'width' : '740px'});

        $(this).parent().parent().parent().children('.thisImage').html('<img src="img/ico/photo/'+flex+'_on.jpg" alt="'+flex+'" />')
        $(this).parent().parent().css({'width' : '530px'});
        
        $('#lopenPhoto').load('jobs/photo/'+flex+'/'+flex+'.php');
        $('#lopenWeb').html('');
        $('#lopenGraphisme').html('');
        $('#lopenVideo').html('');
        
        $('title').html('Portefolio de Benoît Dietrich || Photo || '+flex);
    });
    
    
    //**** AJAX et Ouverture Web
    
    $('#navWeb a').click(function(){
       var flex =$(this).attr('title');
        
        $('.thisImage').html('');
        $('.jobico').css({'width' : '740px'});

        $(this).parent().parent().parent().children('.thisImage').html('<img src="img/ico/web/'+flex+'_on.jpg" alt="'+flex+'" />')
        $(this).parent().parent().css({'width' : '530px'});
       
        $('#lopenWeb').load('jobs/web/'+flex+'/'+flex+'.php');
        $('#lopenPhoto').html('');
        $('#lopenGraphisme').html('');
        $('#lopenVideo').html('');
        
        $('title').html('Portefolio de Benoît Dietrich || Interactivité || '+flex);

    });


	//**** AJAX et Ouverture Graphisme

    $('#navGraphisme a').click(function(){
        var flex =$(this).attr('title');
        
        $('.thisImage').html('');
        $('.jobico').css({'width' : '740px'});

        $(this).parent().parent().parent().children('.thisImage').html('<img src="img/ico/graphisme/'+flex+'_on.jpg" alt="'+flex+'" />')
        $(this).parent().parent().css({'width' : '530px'});
       
       
        $('#lopenGraphisme').load('jobs/graphisme/'+flex+'/'+flex+'.php');
        $('#lopenPhoto').html('');
        $('#lopenWeb').html('');
        $('#lopenVideo').html('');
        $('title').html('Portefolio de Benoît Dietrich || Graphisme || '+flex);
    });
    
    
    //**** AJAX et Ouverture Video

    $('#navVideo a').click(function(){
       var flex =$(this).attr('title');
        
        $('.thisImage').html('');
        $('.jobico').css({'width' : '740px'});

        $(this).parent().parent().parent().children('.thisImage').html('<img src="img/ico/video/'+flex+'_on.jpg" alt="'+flex+'" />')
        $(this).parent().parent().css({'width' : '530px'});
        $('#lopenVideo').load('jobs/video/'+flex+'.php');
        $('#lopenPhoto').html('');
        $('#lopenWeb').html('');
        $('#lopenGraphisme').html('');
        
                $('title').html('Portefolio de Benoît Dietrich || Video || '+flex);


    });
    
    
    //***** Navigation HOVER
    
    $('.hideImgNavig').hide();
    $('.jobico a').hover(function(){
        $(this).children('img').hide();
        $(this).children('.hideImgNavig').show();
    }, function(){
        $(this).children('img').show();
        $(this).children('.hideImgNavig').hide();        
    });
    
    
    //**** Web 2.0 HOVEr
    
    $('#profil div a').hover(function(){
        $(this).children('.showImgNavig').hide();
        $(this).children('.hideImgNavig').show();    
    }, function(){
        $(this).children('img').hide();
        $(this).children('.showImgNavig').show();        
    });
    

    //**** Ouvrir le profil
    $('#profil').hide();
    $('#linkProfil img').hover(function(){
        $(this).css({'cursor' : 'pointer'}); 
    });
    $('#linkProfil img:first').click(function(){
       $('#profil').toggle();
    });
    
    
    
    //**** Pour le flash
    
    //pageExterne
    var largeure = $('#flashAnnim').css('width');
    var hauteure = $('#flashAnnim').css('height');
    var laClasse = $('#flashAnnim').attr('class');
    $('#flashAnnim').flash({
        swf: laClasse+'.swf',
        width: largeure,
        height: hauteure
    });


});


