/////////////////////////////////////////////////////////////////////////////////////////////////// accueil


accueil=new Object();
accueil.init=function(){

	$(".reflect").reflect({
		height : 0.16 ,
		opacity : 0.09
	});
	
	vitesse=7000;
	
	var dec0 = setInterval(function rot() { 
		$('#diap1').innerfade({
			animationtype: 'fade',
			speed: 'slow',
			timeout: vitesse,
			containerheight: '490px'
		});
		
		clearInterval(dec0);
	
	}, (vitesse/3)*1);
	
	var dec1 = setInterval(function rot() { 
		$('#diap2').innerfade({
			animationtype: 'fade',
			speed: 'slow',
			timeout: vitesse,
			containerheight: '490px'
		});
		
		clearInterval(dec1);
	
	}, (vitesse/3)*2);
	
	var dec2 = setInterval(function rot() { 
		$('#diap3').innerfade({
			animationtype: 'fade',
			speed: 'slow',
			timeout: vitesse,
			containerheight: '490px'
		});
		
		clearInterval(dec2);
	
	}, (vitesse/3)*3);

};


/////////////////////////////////////////////////////////////////////////////////////////////////// menu

menu=new Object();
menu.init=function(){
	
	//////////////////////////////////////////////////// actions 
	$("#survol-illustration").fadeTo(0,0);
	$("#survol-illustration").hover(function(){  
  		$("#survol-illustration").stop().fadeTo('normal', 1);
 	}, function(){  
  		$("#survol-illustration").stop().fadeTo('normal', 0);
 	})
	
	$("#survol-print").fadeTo(0,0);
	$("#survol-print").hover(function(){  
  		$("#survol-print").stop().fadeTo('normal', 1);
 	}, function(){  
  		$("#survol-print").stop().fadeTo('normal', 0);
 	})
	
	$("#survol-caricatures").fadeTo(0,0);
	$("#survol-caricatures").hover(function(){  
  		$("#survol-caricatures").stop().fadeTo('normal', 1);
 	}, function(){  
  		$("#survol-caricatures").stop().fadeTo('normal', 0);
 	})
	
};

/////////////////////////////////////////////////////////////////////////////////////////////////// slider

slider=new Object();
slider.init=function(){
	
	num=nombre;
	div=Math.ceil(num/15);
	
	var divParent = document.getElementById('contNav');
	
	
	if(div>1){
		for(i=0;i<div;i++){
		
			// Creation d'une image 
   			var oI = document.createElement('img'); 
   			oI.setAttribute('src', 'images/invisible.gif');
   			oI.setAttribute('onMouseOver', 'this.src="images/indicRoll.png"');
   			oI.setAttribute('onMouseOut',  'this.src="images/indic.png"');
   			oI.setAttribute('id', 'c'+i);
   			oI.setAttribute('class', 'indic');
   			oI.setAttribute('border', '0'); 
			
			// positionnement
   			divParent.appendChild(oI); 
   			
		};
		
		ancien="#c0";
		$(ancien).attr("src","images/indicRoll.png");
		$(ancien).attr("onMouseOver","this.src='images/indicRoll.png'");
		$(ancien).attr("onMouseOut","this.src='images/indicRoll.png'");
		
		for(j=0;j<div;j++){
			
			monImage="#c"+j;
			$(monImage).attr("j",j);
			$(monImage).click(function() {
				
				$(ancien).attr("src","images/indic.png");
				$(ancien).attr("onMouseOver","this.src='images/indicRoll.png'");
				$(ancien).attr("onMouseOut","this.src='images/indic.png'");
				
				ancien="#c"+$(this).attr("j");		
				$(ancien).attr("src","images/indicRoll.png");
				$(ancien).attr("onMouseOver","this.src='images/indicRoll.png'");
				$(ancien).attr("onMouseOut","this.src='images/indicRoll.png'");
				
				rapp=-390*$(this).attr("j");
				$("#slideMiniatures").stop().animate({top: rapp}, 350);
					
			});

		};
	};
		
};

slide=function(n){
	
	rapp=-390*n;
	$("#slideMiniatures").stop().animate({top: rapp}, 350);
	
	$(ancien).attr("src","images/indic.png");
	$(ancien).attr("onMouseOver","this.src='images/indicRoll.png'");
	$(ancien).attr("onMouseOut","this.src='images/indic.png'");
	
	ancien="#c"+n;
	$(ancien).attr("src","images/indicRoll.png");
	$(ancien).attr("onMouseOver","this.src='images/indicRoll.png'");
	$(ancien).attr("onMouseOut","this.src='images/indicRoll.png'");
};

/////////////////////////////////////////////////////////////////////////////////////////////////// viewer

galerie=function(depart){

	loupe = new Image();
	loupe.src = "images/loupeRoll.png";
		
	var settings = { 
    	imgViewerId: "zoneImage",
    	activeClass: "miniActive", 
    	loaderTitle: "Chargement en cours", 
    	loaderImage: "images/ajax-loader.gif",
    	loaderId: "reflect"
	}; 
	
	var thumbLinks = $("#slideMiniatures").find("a"), firstThumbLink = thumbLinks.eq(0);
	
	highlight = function(elt){ 
    	thumbLinks.removeClass(settings.activeClass); 
    	elt.addClass(settings.activeClass);
    };
	
	switcher = function(target){
		thumbLinks.removeClass(settings.activeClass);
		$('#slideMiniatures').find("a[href*="+target+"]").addClass(settings.activeClass);
	};
    
    loader = $(document.createElement("img")).attr({ 
    	alt: settings.loaderTitle, 
    	title: settings.loaderTitle, 
    	src: settings.loaderImage ,
    	id: settings.loaderId
    });
	
	////////////////////////////////////////////////////////// shadow box
	
	Shadowbox.init({
		modal: false,
		displayCounter: true,
		displayNav:true,
		overlayOpacity:0.9
	});
	
	$("#zoneClick").click(function(){
		var selected = $("#zoneLinks").find("a[href*="+actuel+"]");
		selected.click();
	});
	
	////////////////////////////////////////////////////////// initialisation de la premiere image
	
	var contImage = document.getElementById('zoneImage');
	var im = document.createElement('img');
	
	im.setAttribute('src','images/black.png');
	im.setAttribute('id','reflect');
	
	$("#reflect").reflect({height : 0.16 ,opacity : 0.1});
	contImage.appendChild(im);
	
	var imgViewer = $("#"+settings.imgViewerId), bigPic = imgViewer.children("img");
	imgViewer.html(loader);
	
	
	////////////////////////////////////////////////////////////// pour IE qui pige rien à la vie !
	
	if(depart=="ttp://anthonygeoffroy.com/illustration"){
		depart=undefined;
	}else if(depart=="ttp://www.anthonygeoffroy.com/illustration"){
		depart=undefined;
	}else if(depart=="ttp://anthonygeoffroy.com/print"){
		depart=undefined;
	}else if(depart=="ttp://www.anthonygeoffroy.com/print"){
		depart=undefined;
	}else if(depart=="ttp://anthonygeoffroy.com/caricature"){
		depart=undefined;
	}else if(depart=="ttp://www.anthonygeoffroy.com/caricature"){
		depart=undefined;
	}else if(depart==""){
		depart=undefined;
	}
	
	////////////////////////////////////////////////////////// mise en place de la première image	
	if(depart==undefined){
	
		var src= firstThumbLink.attr("href").substr(firstThumbLink.attr("href").lastIndexOf('#')+2);
		
		bigPic.load(function(){imgViewer.html($(this).fadeTo(0.8, 1,function(){$("#reflect").reflect({ height: 0.2, opacity: 0.2 });}));}).attr("src","admin/images/grande/"+src+".jpg");
		
			$.ajax({
			   type: "POST",
			   url: "ajax/contenuFolio.php",
			   data: "url="+src,
			   success: function(data){
					if(data){
						$("div#zoneTexte").html(data);
						$("#reflect").reflect({ height: 0.2, opacity: 0.2 });
					}else{
						alert("Erreur de connection");
					}
			   }
			});
		switcher(src);
		
		actuel=src;
	
	}else{
		
		bigPic.load(function(){ imgViewer.html($(this).fadeTo(0.8, 1,function(){$("#reflect").reflect({ height: 0.2, opacity: 0.2 });})); }).attr("src","admin/images/grande/"+depart+".jpg");
		
			$.ajax({
			   type: "POST",
			   url: "ajax/contenuFolio.php",
			   data: "url="+depart,
			   success: function(data){
					if(data){
						$("div#zoneTexte").html(data);
						$("#reflect").reflect({ height: 0.2, opacity: 0.2 });
					}else{
						alert("Erreur de connection");
					}
			   }
			});
		switcher(depart);
		
		actuel=depart;
		
	};
	
	////////////////////////////////////////////////////////// mise en place de la navigation
	thumbLinks.click(function(e){ 
		var $this = $(this), target = $this.attr("href").substr($this.attr("href").lastIndexOf('#')+2);
		if (bigPic.attr("src") == "admin/images/grande/"+target+".jpg") return ;
		highlight($this);
		$.ajax({
		   type: "POST",
		   url: "ajax/contenuFolio.php",
		   data: "url="+target,
		   success: function(data){
				if(data){
					$("div#zoneTexte").html(data);
				}else{
					alert("Erreur de connection");
				}
		   }
		});
		imgViewer.html(loader);
		bigPic.load(function(){ imgViewer.html($(this).fadeTo(0.8, 1,function(){$("#reflect").reflect({ height: 0.2, opacity: 0.2 });})); }).attr("src","admin/images/grande/"+target+".jpg");
		actuel=target;
	}); 
	
	sw=function(target){
		switcher(target);
		$.ajax({
		   type: "POST",
		   url: "ajax/contenuFolio.php",
		   data: "url="+target,
		   success: function(data){
				if(data){
					$("div#zoneTexte").html(data);
				}else{
					alert("Erreur de connection");
				}
		   }
		});
		imgViewer.html(loader);
		bigPic.load(function(){ imgViewer.html($(this).fadeTo(0.8, 1,function(){$("#reflect").reflect({ height: 0.2, opacity: 0.2 });}));}).attr("src","admin/images/grande/"+target+".jpg");
		actuel=target;
	};
	
	$(window).keydown(function(e){ 
        switch (e.keyCode) { 
            case 37: // flèche gauche 
               $.ajax({
				   type: "POST",
				   url: "ajax/fleches.php",
				   data: "url="+actuel+"&prochain=prev",
				   success: function(data){
						if(data){
							sw(data);
							window.location.href="#/"+data;
						}
				   }
				});
				break; 
            case 39: // flèche droite 
                 $.ajax({
				   type: "POST",
				   url: "ajax/fleches.php",
				   data: "url="+actuel+"&prochain=next",
				   success: function(data){
						if(data){
							sw(data);
							window.location.href="#/"+data;
						}
				   }
				});
				break; 
        } 
    });
	
	
	
};


