/*
	Conception et developpement par www.wilhemarnoldy.fr
*/

/*
	Console
*/


function console(str) {
	$('flashconsole').set('html','Flash feedback' + str).highlight("#333333");
}

/*
	Variables generales
*/

//sidebar
var sidebarmenu;
var sidebarmenu2;
var sidebar;
var sidebar2;

//scrollspy
var minHeader = 600;
var minMenu = 1890;


var anchorsPaddingTop = 200;
var portfolioTempAnchorPaddingTop = 0; 
var anchorsCenterPadding = false; 
var thumbnailDarker = 0.10;
var openingDuration = 1200; 
var closingDuration = 600; 
var scrollingDuration = 700; 

// portfolio
var loader;
var busy = false;
var btnclose = 'FALSE';

// set blocs + taille ecran
var scnWid,scnHei, tHei, maxBlocHei, anchorsPaddingTop, clearsHei;
var maxHeiBlocsContent = 390;

var scroll;
var scroll_load;
	
	
//ios
var bgnoflashwrapper;

window.addEvent('domready', function(){
	/*
		Préchargement
	*/

	bgnoflashwrapper = $('bgnoflash-wrapper');
	
	var header = $('header');
	
	var headerline = $('header-line');
	var footer = $('credits-line');
	
	var loadingline = $('loading-line');
	var fadertop = $('fader-top');
	var faderbottom = $('fader-bottom');
	
	var cflash = $('c-flash');	
	
	/*
		Mobile ajustements
	*/
	
	// Get the HTML tag > to set css hack
	var htmlTag = document.id(document.documentElement);
	// Add the browser name class
	htmlTag.addClass(Browser.name);
	// Add the browser name + version class
	htmlTag.addClass(Browser.name + Browser.version);
	
	if(Browser.Platform.name == "ios") {
		htmlTag.addClass("mobile ios"); // Two classes
	//	alert('ios');	
	}	
	
	if(Browser.Device.name == "iphone") {
		htmlTag.addClass("iphone"); // Two classes	
	//	alert('iphone');	
		var metaArray = document.getElementsByName('viewport');
		for (var i=0; i<metaArray.length; i++) {
			metaArray[i].setAttribute('content','width=device-width, height=device-height, initial-scale=0.3, user-scalable=yes, minimum-scale=0.3, maximum-scale=0.3');
		}
	}

	if(Browser.Device.name == "ipad") {
		htmlTag.addClass("ipad"); // Two classes		
	//	alert('ipad');	
		var metaArray = document.getElementsByName('viewport');
		for (var i=0; i<metaArray.length; i++) {
			metaArray[i].setAttribute('content','width=device-width, initial-scale=0.7, user-scalable=yes, minimum-scale=0.7, maximum-scale=0.7');
		}
	}
	
	//alert(Browser.name + Browser.version);
	
	
	


	if ($('sidebar-menu'))
		sidebarmenu = $('sidebar-menu');
		sidebarmenu2 = $('sidebar-menu2');
		sidebarmenu.store('_portfolioTempAnchorPaddingTop', portfolioTempAnchorPaddingTop);
	
	/*
		Gestion des smooth scrolls
	*/
	
	
	 var mySmoothScroll =  new Fx.SmoothScroll({ duration: 800, transition: Fx.Transitions.Quint.easeInOut,wheelStops: true }, window); //700 milliseconds to get there 


	/*
	var mySmoothScroll = new Fx.SmoothScroll({
    	links: '.smoothAnchors',
   	 	wheelStops: false
	});
	*/
	
	/*
		Bien placer le texte intro.	
	*/
	
	if (self.innerHeight) // all except Explorer
	{
		scnWid = self.innerWidth;
		scnHei = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
	{
		scnWid = document.documentElement.clientWidth;
		scnHei = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		scnWid = document.body.clientWidth;
		scnHei = document.body.clientHeight;
	}

	
	if( $('a-idx') ){	
		var anchor = $('a-idx');
		var text = $('t-idx');
		var status = $('status-idx');
		
		tHei = text.getSize().y;
		var toMove = scnHei/2 - tHei/2;
		anchor.setStyle('padding-top', toMove + 'px');
		status.set('html', 'Please wait while loading...');
		status.fade('in');
	}	


	/*
		Bien placer les anchors et clear
	*/	

	var theAnchors = $$('.anchor');
	theAnchors.each(function(element,index) { 
		if (anchorsCenterPadding == true ) {
			anchorsPaddingTop = scnHei/2 - maxHeiBlocsContent/2;
			anchorsPaddingTop = Math.max(100,anchorsPaddingTop);
		}
		element.setStyle('padding-top', anchorsPaddingTop + 'px');
	});
	
	/*
		Bien placer le sidebar
	*/	
	
	if( $('sidebar-menu') ) { 
		sidebarmenu.setStyle('padding-top', anchorsPaddingTop-100 + 'px');
		sidebarmenu2.setStyle('padding-top', anchorsPaddingTop-100 + 'px');
	};


	var theClears = $$('.clear');
	theClears.each(function(element,index) { 
		element.setStyle('height', scnHei + 'px');		
	});
	
		
	/*
		Scroll side du menu portfolio
	*/
	
	if ($('c-slide-port')) {
		var port = new Fx.Slide('c-slide-port').hide(); //creates new Fx.Slide object from grid div
	}


	if ( $('sidebar-menu') ) {
		sidebar = new ScrollSidebar('sidebar-menu',{
			offsets: {
				x: 0,
				y: 100-15
			}
		});
		sidebar2 = new ScrollSidebar('sidebar-menu2',{
			offsets: {
				x: 0,
				y: 100-15
			}
		});
	}
	
	
	
	/*
		Definir Flashbackground
	*/
	
	if ($('myFlashBackground')) {
		// If this isn't an iOS mobile platform...
		if( Browser.Platform.ios || Browser.Platform.android || Browser.Plugins.Flash == false || Browser.Plugins.Flash.version == '0') {
			var flashBackground = null;	
			loadnoflashIndexImages();
	    	hideBgnoflashImages();
	    	bgnoflashwrapper.getElementById('bgnoflash').setStyle('display', 'block');
		} else {
			var flashBackground = swfobject.getObjectById('myFlashBackground');
		}
	}

	/*
		slider la page
	*/
	
	var theSmoothAnchors = $$('.smoothAnchors');
	
	var FFShowTimeOut;
	var FFChangeTimeOut;
	
	theSmoothAnchors.each(function(element,index) { 
	    var content = element.get('title').split('::'); 
	    
	 	// 	element.store('link:anchor', content[0]); 
	  	//  element.store('link:gal', content[1]); 

					var scroll = new Fx.Scroll(window, { 
						wait: true, 
						wheelStops: false,
						duration: 700, 
						transition: Fx.Transitions.Quint.easeOut,
						onStart: function(){
				            //$('console').set('html','Scroll start').highlight("#333333");
							if( flashBackground != null )
								flashBackground.hideFlowers();
							else 
								bgnoflashwrapper.setStyle('opacity',0);
//								bgnoflashwrapper.fade('out');
				        },
				        onComplete: function(){
				            //$('console').set('html','Scroll complete').highlight("#333333");

							FFShowTimeOut = null; 
							FFShowTimeOut = showFlowers.delay(400);
							
							function showFlowers() {
								if( flashBackground != null ) {
									if ( content[0] != 'a-por' && content[0] != 'a-idx') {
						            	//$('console').set('html','show flowers').highlight("#333333");
										flashBackground.showFlowers();
									}
								} else {
									if ( content[0] != 'a-por') {
										bgnoflashwrapper.fade('in');
									} else {
										bgnoflashwrapper.fade('out');
									}
								}
							}
							
							sidebar.replacePosition($(content[0]).getPosition().y);
							sidebar2.replacePosition($(content[0]).getPosition().y);
							placeNavigationForIos($(content[0]).getPosition());

				        }
					});
	    
	    if ( $(content[0]) ) {
			element.addEvents({
				click:function() {

					if (content[0] == 'a-idx' ) {
						if( flashBackground != null ) {
							flashBackground.showPicture();
						} else {
							hideBgnoflashImages();
							bgnoflashwrapper.getElementById('bgnoflash').setStyle('display', 'block');
						}
					} else {
											
							this.getParent('ul').getChildren().each(function(el) { if ( busy == false) el.set('class',''); });
								
								$('sidebar-menu2').getElement('ul').getChildren().each(function(el) { el.set('class',''); });
								$('c-slide-port').getChildren().each(function(el) { if ( busy == false) el.set('class',''); });
			
			
								if ( busy == false) this.getParent().toggleClass('act');
								
								$('sidebar-menu2').getElement('ul').getChildren().each(function(el) { 
									if(el.getElement('a').get('title') == content[0] ) el.set('class','act'); //port
									//if(el.getElement('a').get('title') == content[0]+'::'+content[1]) el.set('class','act'); //rub
								});
								$('c-slide-port').getChildren().each(function(el) { 
									//if(el.getElement('a').get('title') == content[0]) el.set('class','act'); //port
									if(el.getElement('a').get('title') == content[0]+'::'+content[1] && busy == false) el.set('class','act'); //rub
								});
					
								
								if ( content[0] == 'a-por' && content[1] == null ) { 
									port.slideOut(); 
									$('blocs').empty();
									$('m-portfolio').setStyle('display','block');
									
									portfolioTempAnchorPaddingTop = 0 ;
									sidebarmenu.store('_portfolioTempAnchorPaddingTop', portfolioTempAnchorPaddingTop);
									
									
									// Je cache les fleurs.
									// If this isn't an iOS mobile platform...
									if( flashBackground != null )
										flashBackground.hideFlowers();
									else 
										bgnoflashwrapper.fade('out');
										//hideBgnoflashImages();
										//bgnoflashwrapper.setStyle('opacity',0);
				
								} else if (content[0] != 'a-por' && content[1] == null) {
									
									port.slideOut(); // Refermer le portfolio
									$('blocs').empty(); // On decharge les blocs si on navigue en dehors du portfolio.
									busy = false;
									//$('m-portfolio').setStyle('display','block');
									portfolioTempAnchorPaddingTop = 0 ;
									sidebarmenu.store('_portfolioTempAnchorPaddingTop', portfolioTempAnchorPaddingTop);

									// Je charge les fleurs. 
									//FFChangeTimeOut = null; 
									//FFChangeTimeOut = ChangeFlowers.delay(800);
										
									//function ChangeFlowers() {
										
									// If this isn't an iOS mobile platform...
									if( flashBackground != null) {
										
								        //$('console').set('html','change flowers').highlight("#333333");
										
										switch (content[0]) {
										    case "a-bio" :
												flashBackground.changeFlowers(1);
										    	break; 
										    case "a-cli" :
												flashBackground.changeFlowers(2);
										    	break; 
										    case "a-sto" :
												flashBackground.changeFlowers(3);
										    	break; 
										   	case "a-con" :
												flashBackground.changeFlowers(4);
										    	break; 
										}
										
									} else { // fin if ios

								        //$('console').set('html','change html flowers').highlight("#333333");
										
										switch (content[0]) {
										    case "a-bio" :
										    	hideBgnoflashImages();
											 	bgnoflashwrapper.getElementById('bgnoflash'+1).setStyle('display', 'block');
										    	break; 
										    case "a-cli" :
										    	hideBgnoflashImages();
											 	bgnoflashwrapper.getElementById('bgnoflash'+2).setStyle('display', 'block');
										    	break; 
										    case "a-sto" :
										    	hideBgnoflashImages();
											 	bgnoflashwrapper.getElementById('bgnoflash'+3).setStyle('display', 'block');
										    	break; 
										   	case "a-con" :
										    	hideBgnoflashImages();
											 	bgnoflashwrapper.getElementById('bgnoflash'+4).setStyle('display', 'block');
										    	break;
										} 

									}
									//}
			
									
								}
								
								if( content[1] != null ) {
									//alert("load portfolio " + content[1])
									
									port.slideIn(); 
									
									if ( busy == false) loadPortfolio(content[1]);
									$('m-portfolio').setStyle('display','none');
								}
					}
					
					
					//window.scrollTo(0,0);
					//scroll.toElement(content[0]);
					scroll.start(0, $(content[0]).getPosition().y);
				}
			});
		} else { 
			console('Pas de balises <a> correspondante pour '+content[0]);
			element.addEvents({
				click:function() {
					scroll.start(0, 0);
				}
			});
		}
	}); 
		
	/*	
		Scroll Spy
	*/	

	if ($('c-flash')) {	
				
		var ss = new ScrollSpy({ 
		    min: minHeader, 
		    onEnter: function() { 
		        header.fade('in');
		    }, 
		    onLeave: function() { 
		        header.fade('out');
		    }, 
		    container: window
		});
		
		var ss2 = new ScrollSpy({ 
		    min: minMenu, 
		    onEnter: function() { 
		        $('logotype-light').fade('out');
		        sidebarmenu.getElement('ul').fade('in');
		        sidebarmenu2.getElement('ul').fade('in');
		    }, 
		    onLeave: function() { 
		        $('logotype-light').fade('in');
		        sidebarmenu.getElement('ul').fade('out');
		        sidebarmenu2.getElement('ul').fade('out');
		    }, 
		    container: window
		});
		
	} 

	if(Browser.Platform.ios || Browser.Platform.android) {
		// Change styling of the TOP element's position
		headerline.setStyles({ 
		  	position: "absolute", 
		  	top: "auto" 
		});
		
		footer.setStyles({ 
		  	position: "absolute", 
		  	bottom: "auto"
		});

		loadingline.setStyles({ 
		  	position: "absolute", 
		  	top: "auto"
		});

		fadertop.setStyles({ 
		  	position: "absolute", 
		  	top: "auto",
	 		left: "0"
		});

		faderbottom.setStyles({ 
		  	position: "absolute", 
		  	bottom: "auto",
	 		left: "0"
		});
		
		cflash.setStyles({ 
		  	position: "absolute", 
		  	top: "auto" 
		});

		
		// Add a scroll event to...
		ss.addEvent("scroll",function(position) {
			placeNavigationForIos(position);
		});
		
		ss2.addEvent("scroll",function(position) {
			//placeNavigationForIos(position);
		});
		
		placeNavigationForIos({ x: '0', y: '0' });	
	}
	
	/*
		Voir function
	*/	
	

	/*
		Admin panel 
	*/

			
	$$('#b-admin, #admin-area-open').each(function(item) {
			$('admin-area-open').setStyle('display','none');
			
			item.addEvent('click', function(e) {

				if ($('b-admin').hasClass('hidden')){
					$('admin-area').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('height', '150px');
					$('credits-line').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('bottom', '152px');
					$('fader-bottom').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('bottom', '150px');
					$('admin-area-open').setStyle('display','block');
					$('b-admin').removeClass('hidden').addClass('visible');
				}
				else {
					$('admin-area').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('height', '0px');
					$('credits-line').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('bottom', '0px');
					$('fader-bottom').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('bottom', '0px');
					$('admin-area-open').setStyle('display','none');
					$('b-admin').removeClass('visible').addClass('hidden');
				}
			});
	});

	/*
		Fin
	*/

	// Verification si pas d'erreur JS
	//alert("Pas d'erreur/")
});



window.addEvent('load', function(){
	
	/*
		On load
	*/
	
	var bgnoflashwrapper = $('bgnoflash-wrapper');


	if($('loading-line')) $('loading-line').set('tween', {duration: 1500, transition: Fx.Transitions.Sine.easeOut}).tween('width', 0);
	
	if (!$('c-flash')) {
        $('header').fade('in');
        $('logotype-light').fade('out');
        
        if ($('sidebar-menu'))  sidebarmenu.getElement('ul').fade('in');
        if ($('sidebar-menu2')) sidebarmenu2.getElement('ul').fade('out');
	}
	
	//120711
	//alert('test : ' + $$('span.tx-loginboxmacmade-pi1-loggedUser').length);
	
	if ( $$('span.tx-loginboxmacmade-pi1-loggedUser').length != 0 ) {

			var timeOutFn;
					
				if ($('b-admin').hasClass('hidden')){
					$('admin-area').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('height', '150px');
					$('credits-line').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('bottom', '152px');
					$('fader-bottom').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('bottom', '150px');
					$('admin-area-open').setStyle('display','block');
					$('b-admin').removeClass('hidden').addClass('visible');
				}
				
			$clear(timeOutFn);
			timeOutFn = unShowAdminPanel.delay(1000);

	}

	/*
		Repositionner si il y a une ancre OU sinon remettre en haut.
	*/
	var scroll_load = new Fx.Scroll(window, { 
							wait: true, 
							duration: 1000, 
							wheelStops: false,
							transition: Fx.Transitions.Quad.easeInOut,
							onStart: function(){
					        },
					        onComplete: function(){
								sidebar.replacePosition($(anchorsHash).getPosition().y);
								sidebar2.replacePosition($(anchorsHash).getPosition().y);
								placeNavigationForIos($(anchorsHash).getPosition());
					        }
					});


	var anchorsHash = window.location.hash.substring(1); // the hash
	if(anchorsHash) {
		window.scrollTo(0,0);
		scroll_load.start(0, $(anchorsHash).getPosition().y);
	} else {
		// repositionner	
		anchorsHash='a-idx';
		window.scrollTo(0,0);
		scroll_load.start(0, $(anchorsHash).getPosition().y);
	}
	
	/*
			Gestion index loading 	
	*/
	if ($('myFlashBackground')) {
		// If this isn't an iOS mobile platform...
		if( Browser.Platform.ios || Browser.Platform.android || Browser.Plugins.Flash == false || Browser.Plugins.Flash.version == '0') {
			var flashBackground = null;	
		} else {
			var flashBackground = swfobject.getObjectById('myFlashBackground');
		}
	}

	
	if( $('a-idx') ){	
		var text = $('t-idx');
		var status = $('status-idx');
		
		text.fade('in');
		
		//status.fade('out').chain(function() {
		status.get('tween').start('opacity',0).chain(function() {
			
			status.set('html', '<a title="a-men" class="smoothAnchors">Enter</a>');
			status.fade('in');
			var content = status.getElement('a').get('title');
	    
		    if ( $(content) ) {
				status.getElement('a').addEvents({
					click:function() {
						
						window.scrollTo(0,0);
						var scroll = new Fx.Scroll(window, { 
							wait: false, 
							duration: 1000, 
							transition: Fx.Transitions.Quint.easeInOut,
							wheelStops: false,
							onStart: function(){
					        },
					        onComplete: function(){
								sidebar.replacePosition($(content).getPosition().y);
								sidebar2.replacePosition($(content).getPosition().y);
								placeNavigationForIos($(content).getPosition());
					        }
						});

						scroll.start(0, $(content).getPosition().y);
				
						//if ($('myFlashBackground'))
						if( flashBackground != null )
							flashBackground.hidePicture();
						else 
							bgnoflashwrapper.fade('out');

						
					}
				});
		    }

		});
	}	
	
	
});

function hideBgnoflashImages() {
	bgnoflashwrapper.getElements('img').each(function(element, index) {
		element.setStyle('display', 'none');
	});
}

function loadnoflashIndexImages() {
	random_num = (Math.round((Math.random()*indeximages.length)+1))
	var img = new Element('img',{src:indeximages[random_num], 'alt':'Background', 'id':'bgnoflash'}).injectInside(bgnoflashwrapper);
}

function unShowAdminPanel() {	
	if ($('b-admin').hasClass('visible')){
		$('admin-area').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('height', '0px');
		$('credits-line').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('bottom', '0px');
		$('fader-bottom').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('bottom', '0px');
		$('admin-area-open').setStyle('display','none');
		$('b-admin').removeClass('visible').addClass('hidden');
	}
}

function placeNavigationForIos(position,px,py) {
		
	var bgnoflashwrapper = $('bgnoflash-wrapper');
	
	var header = $('header');
	
	var headerline = $('header-line');
	var footer = $('credits-line');
	
	var loadingline = $('loading-line');
	var fadertop = $('fader-top');
	var faderbottom = $('fader-bottom');
	
	var cflash = $('c-flash');
	
//	alert(position)
//	alert(px)
//	alert(py)
	
	if ( position != null ) {
		var py = position.y;
	} else {
		var py = py;
	}

	if(Browser.Platform.ios || Browser.Platform.android) {

    	/*if ($('header').getStyle('opacity') != '1' ) $('header').fade('in');*/
    	//alert(position.y);
    	/*
    	
	    	if (position.y > minHeader)
				header.fade('in');
	    	else
				header.fade('out');
	
	
	    	if (position.y > minMenu) {
				$('logotype-light').fade('out');
				sidebarmenu.getElement('ul').fade('in');
				sidebarmenu2.getElement('ul').fade('in');
	    	} else {
				$('logotype-light').fade('in');
				sidebarmenu.getElement('ul').fade('out');
				sidebarmenu2.getElement('ul').fade('out');
	    	}
	
		    headerline.setStyle("top",(position.y + 0) + "px");
		    footer.setStyle("top",(position.y + window.innerHeight - footer.getSize().y) + "px");
	
		    loadingline.setStyle("top",(position.y + 0) + "px");
		    fadertop.setStyle("top",(position.y + 0) + "px");
		    faderbottom.setStyle("top",(position.y + window.innerHeight - faderbottom.getSize().y) + "px");
	
		    cflash.setStyle("top",(position.y + 0) + "px");
	
		    bgnoflashwrapper.setStyle("height",(window.innerHeight + 0) + "px");
		    
*/
	    	if (py > minHeader)
				header.fade('in');
	    	else
				header.fade('out');
	
	
	    	if (py > minMenu) {
				$('logotype-light').fade('out');
				sidebarmenu.getElement('ul').fade('in');
				sidebarmenu2.getElement('ul').fade('in');
	    	} else {
				$('logotype-light').fade('in');
				sidebarmenu.getElement('ul').fade('out');
				sidebarmenu2.getElement('ul').fade('out');
	    	}
	
		    headerline.setStyle("top",(py + 0) + "px");
		    footer.setStyle("top",(py + window.innerHeight - footer.getSize().y) + "px");
	
		    loadingline.setStyle("top",(py + 0) + "px");
		    fadertop.setStyle("top",(py + 0) + "px");
		    faderbottom.setStyle("top",(py + window.innerHeight - faderbottom.getSize().y) + "px");
	
		    cflash.setStyle("top",(py + 0) + "px");
	
		    bgnoflashwrapper.setStyle("height",(window.innerHeight + 0) + "px");


	}	
}


function loadPortfolio(rub) {

	
	/*
		Gestion Portfolio
	*/
	
	//var images = ['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg'];
	//var imagesf1 = ['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg'];
	//var imagesf2 = ['1.jpg','2.jpg','3.jpg'];
	
	/*var rubarray = new Array();
	var rubarray = ['f1', 'f2', 'st', 'pr', 'tr', 'pu'];
	
	var images = new Array();
	images.include(rubarray);
	//images[0] = ['1.jpg::The title of photography;;Epson (2009)','2.jpg::The title 2;;The client 2','3.jpg::The title (photo 3);;The client 3','4.jpg::The title;;The client','5.jpg::The title;;The client','6.jpg::The title;;The client','7.jpg::The title;;The client','8.jpg::The title;;The client']; // f1

	images[0] = ['1.jpg,1-2.jpg::The title of photography;;Epson (2009)','2.jpg,2-2.jpg::The title 2;;The client 2','3.jpg,3-2.jpg::The title (photo 3);;The client 3','4.jpg::The title;;The client','5.jpg::The title;;The client','6.jpg::The title;;The client','3.jpg,3-2.jpg::The title (photo 3);;The client 3','4.jpg::The title;;The client','5.jpg::The title;;The client']; // f1 single / double / full

	images[1] = ['1.jpg,1-2.jpg::The title;;The client','3.jpg::The title;;The client','4.jpg::The title;;The client','5.jpg::The title;;The client','6.jpg,6-2jpg::The title;;The client']; // f2
	
	images[2] = ['1.jpg,1-2.jpg::The title;;The client','2.jpg::Flower;;The client']; // st
	images[3] = ['1.jpg::The title;;The client', '2.jpg::The title;;The client']; // pr
	images[4] = ['1.jpg::The title;;The client', '2.jpg::The title;;The client', '3.jpg::The title;;The client']; // tr
	images[5] = ['1.jpg::The title;;The client']; // pu
	
*/


	if (busy == false ) {		
		/* preloading */
//		var imagesDir = 'photos/407s820d/';
		var imagesDir = '';
		var imagesstore = [];
		var textsstore = [];
		var loadingindex = 0;
		var renderindex = 0;
		
	//	var query = query.substr(query.length, -3);
	//	var images = ['1.jpg','2.jpg','3.jpg','4.jpg'];
	
		var holder = $('blocs');
		holder.empty();
		
		//images.each(function(img,i){ images[i] = imagesDir + rub + '/' + img; }); //add dir to images
		
		var arrayindex = rubarray.indexOf(rub); // retrouver l'index a partir de la rubrique.
		
		//alert("index?" + arrayindex);
		
		images[arrayindex].each(function(imgdata,i){ 
			//alert(i);
			
			var imgdataarray = imgdata.split('::'); // Splitter image et txt
			var img = imgdataarray[0].split(','); // Splitter images si plusieurs
			//imagesstore.push(imagesDir + rub + '/' + img[0]); 
			imagesstore.push(imagesDir + img[0]); 
			textsstore.push(imgdataarray[1]); // recup text
			if (img[1]) { // si on a une 2e image
				//imagesstore.push(imagesDir + rub + '/' + img[1]);
				imagesstore.push(imagesDir + img[1]);
				textsstore.push("DOUBLE"); // infos DOUBLE
			}// Store the double sided
			
		});

		var progressTemplate = 'Loading image {x} of ' + imagesstore.length;
		
		var updateProgress = function(num) {
			progress.set('text',progressTemplate.replace('{x}',num));
		};
		
		var progress = $('progress');
		updateProgress('0');
		progress.fade('in');
		
		var slides = [];
		
//		alert(loader);

		loader = null;
		busy = true; 
		
		loader = new Asset.images(imagesstore, {
			onload: function(loadingindex,index) { 
				//busy = true; 
				//alert("busy ok"); 
			},
			onabort: function(loadingindex,index) { 
				progress.set('text','Abort!');
				//alert("Abort");
			},
			onerror: function(loadingindex,index){
				progress.set('text','Error!');
				//alert("Error");
			},
			onProgress: function(loadingindex,index) {
				//alert("index:" + index + "li: " + loadingindex);
//				loadingindex++;
//				updateProgress(index + 1);
				updateProgress(loadingindex);
//				var percLoaded = (index+1)/imagesstore.length*100;
				var percLoaded = (loadingindex)/imagesstore.length*100;
				//if(window.console && window.console.firebug) window.console.log(percLoaded);
				if($('loading-line')) $('loading-line').set('tween', {duration: 1000, transition: Fx.Transitions.Sine.easeOut}).tween('width', (document.body.clientWidth/100)*percLoaded);	

				if (textsstore[loadingindex] != "DOUBLE") {
					var globaldiv = new Element('div', {'class': 'grid_4 bloc close'});
					var loadiv = new Element('div', {'class': 'loader'}).injectInside(globaldiv);
					globaldiv.inject(holder);
					slides.push(globaldiv);
				} else {
					//alert("une double image");	
				}
				
			},
			onComplete: function() {
				/* 
					Put images into div 
				*/
				if($('loading-line')) $('loading-line').set('tween', {duration: 400, transition: Fx.Transitions.Sine.easeOut}).tween('width', 0);
								
				imagesstore.each(function(im, index) {
						if (textsstore[index] != "DOUBLE") {
							var txt = textsstore[index].split(';;');						
							slides[renderindex].empty(); // supprimer le loading
							var guidiv = new Element('div', {'class': 'guillotine'}).injectInside(slides[renderindex]);
							var imgdiv = new Element('div', {'class': 'image'}).injectInside(slides[renderindex]);
							var btndiv = new Element('div', {'class': 'btn_zoom'}).injectInside(slides[renderindex]);


							btndiv.addEvents({
								click:function() {
									//	alert("closebtn");	
								},
								'mouseenter':function() {
									btnclose = "TRUE";
								},
								'mouseleave':function() {
									btnclose = "FALSE";
								}
							});
							
							var previousbtndiv = new Element('div', {'class': 'btn_previous'}).injectInside(slides[renderindex]);
							var nextbtndiv = new Element('div', {'class': 'btn_next'}).injectInside(slides[renderindex]);
							var desc = new Element('p').injectInside(guidiv);
														
							var img = new Element('img',{src:im, 'alt':'Copyright Mittongtare studio.', title:'Copyright Mittongtare studio.'}).injectInside(imgdiv);
							
							desc.set('html', '<strong>' + txt[0] + '</strong><br />', txt[1] + '<br />', '<span>' + (index+1) + ' of ' + imagesstore.length + '</span>');
							renderindex++;
						} else {
							var img = new Element('img',{src:im, 'class':'double', 'alt':'Copyright Mittongtare studio.', title:'Copyright Mittongtare studio.'}).injectInside(slides[renderindex-1].getElement('.image'));
						}

            	});

				progress.set('text','Images loaded.');
				setBlocs();
								
				/*
					Show Blocs
				*/
				
				var showInterval = 100;
				var index = 0;
					
				var start = function() {
						
						var element = slides[index];
						var theImage = element.getElement('.image');
						theImage.set('tween', {duration: 1000, transition: Fx.Transitions.Quint.easeInOut}).tween('margin-top', '-50%');			    	
						
						if ( index < slides.length-1 ) { ++index; 	/*if(window.console && window.console.firebug){console.log(index)}*/ }
						else { $clear(period); /*if(window.console && window.console.firebug){console.log('stop');}*/ progress.fade('out'); busy = false; }
						
				}
						
				var period = start.periodical(showInterval);
				
				/* 
					start the show 
				*/
				start();
				
			}
		});
	
	
		//alert(loader);
	} else {
		progress.set('text','Busy!');
		//alert('busy');
	} // if busy
	
} //fin load portfolio


/*
	Gestion des bloc photos
*/

function setBlocs () {

	var theBlocs = $$('.bloc');
//	var startDimensions = 200;
	var startDimensions = 130; // Bloc start dimensions
	var blocContainer = $('c-blocs');
	var onViewingPic = false; 
	var onMouseClick = false; 
	var zone = '';
	var currentBloc = null ;
	var btnzone = 200;
	var timeOutFn;

	/*
		Event sur body
	*/

	if( Browser.Platform.ios || Browser.Platform.android ) {
		var myswipe = new MooSwipe(blocContainer, {
			tolerance:20,
		    onSwipeLeft: function() {
		        // Code to execute on left swipe
	//	        alert('left');
				zone = 'NEXT';
				currentBloc.fireEvent('click');
		    },
		    onSwipeRight: function() {
		        // Code to execute on right swipe
	//	        alert('right');
				zone = 'PREVIOUS';								
				currentBloc.fireEvent('click');
		    },
		    onSwipe: function(direction) {
		        // Code to execute on any swipe
		    }
		});
	}


	blocContainer.addEvents({
			    'mouseenter': function(e) {
				    new Event(e).preventDefault();
				    if ( onViewingPic == true ) {
						onMouseClick = false;
				    }
				   	e.stop();
			    },
			    'mouseleave': function(e) {
				    new Event(e).preventDefault();
					if( Browser.Platform.ios || Browser.Platform.android ) {
//						alert('ios');
					} else {
					    if ( onViewingPic == true && onMouseClick == false) {
								zone = '';
					    }
					}
				   	e.stop();
			    },
			    'mousemove': function(e) {
//				    new Event(e).preventDefault();
					if( Browser.Platform.ios || Browser.Platform.android ) {
//						alert('ios');
					} else {
					    if ( onViewingPic == true ) {
	//						if ( e.client.x < scnWid/2 - btnzone) {
							if ( e.client.x - blocContainer.getPosition().x < btnzone) {
								currentBloc.getElement('.btn_previous').setStyle('background-position', '0 -35px');
								if (zone == 'CENTER' || zone == '') {
									zone = 'PREVIOUS';								
									if (currentBloc.getElement('.btn_previous').getStyle('width') == '41px')
										currentBloc.getElement('.btn_previous').set('tween', {duration: 600, transition: Fx.Transitions.Quint.easeInOut}).tween('background-position', '-41px -35px');						
									/*myCurrentBlocBtnPreviousTween = new Fx.Tween(currentBloc.getElement('.btn_previous'), {
										property: 'background-position',
										duration: 800, 
										transition: Fx.Transitions.Quint.easeInOut
									}).start('-41px -35px');*/
								
								
									}
	//						} else if ( e.client.x > scnWid/2 + btnzone) {
							} else if ( e.client.x - blocContainer.getPosition().x > blocContainer.getSize().x - btnzone) {
								currentBloc.getElement('.btn_next').setStyle('background-position', '0 -35px');
								if (zone == 'CENTER' || zone == '') {
									zone = 'NEXT';
									if (currentBloc.getElement('.btn_next').getStyle('width') == '41px')
										currentBloc.getElement('.btn_next').set('tween', {duration: 600, transition: Fx.Transitions.Quint.easeInOut}).tween('background-position', '-41px -35px');
									/*myCurrentBlocBtnNextTween = new Fx.Tween(currentBloc.getElement('.btn_next'), {
										property: 'background-position',
										duration: 800, 
										transition: Fx.Transitions.Quint.easeInOut
									}).start('-41px -35px');*/
	
									}
							} else {
								zone = 'CENTER';
	
								var Ptween = currentBloc.getElement('.btn_previous').retrieve('tween');
	       						if (Ptween && currentBloc.getElement('.btn_previous').getStyle('width') == '41px') Ptween.cancel();
	       						
								var Ntween = currentBloc.getElement('.btn_next').retrieve('tween');
	       						if (Ntween && currentBloc.getElement('.btn_next').getStyle('width') == '41px') Ntween.cancel();
	       						
								//currentBloc.getElement('.btn_previous').cancel();
								//currentBloc.getElement('.btn_next').cancel();
								//currentBloc.getElement('.btn_previous').set('tween', {duration: 200, transition: Fx.Transitions.Quint.easeInOut}).tween('background-position', '0 0');						
								//currentBloc.getElement('.btn_next').set('tween', {duration: 200, transition: Fx.Transitions.Quint.easeInOut}).tween('background-position', '0 0');
	
								currentBloc.getElement('.btn_previous').setStyle('background-position', '0 0');
								currentBloc.getElement('.btn_next').setStyle('background-position', '0 0');
								//$clear(timeOutFn);
								//timeOutFn = unShowBtns.delay(810);
							}
							//$('progress').set('text','x : '+e.client.x + zone + ' / ' + currentBloc.getElement('.btn_previous').getStyle('background-position') + ' / ' + currentBloc.getElement('.btn_next').getStyle('background-position') + " / " + currentBloc.getElement('.btn_next').retrieve('tween'));
							/*if(window.console && window.console.firebug) window.console.log("total = " + (e.client.x - blocContainer.getPosition().x) + " < ou > " + btnzone 
							+ " x (client) : " +e.client.x + " x (page) :  " +e.page.x + zone 
							+ " / " + currentBloc.getElement('.btn_previous').getStyle('background-position') 
							+ " / " + currentBloc.getElement('.btn_next').getStyle('background-position') 
							+ " / " + currentBloc.getElement('.btn_next').retrieve('tween')
							+ ' / onViewingPic = ' + onViewingPic
							+ ' / zone ' + zone
							+ ' / onMouseClick = ' + onMouseClick 
							+ ' / Bloc size x' + blocContainer.getSize().x 
							+ ' / element class ' + currentBloc.hasClass('open') 
							);*/
					   	}// fin viewing
					} // fin ios
				    e.stop();
			    },
			    
				'click': function(e) {
//				    new Event(e).preventDefault();

				  /*  if ( onViewingPic == true && onMouseClick == false ) {
						onMouseClick = true;
						alert('container true');
				    } else {
						onMouseClick = false;
						alert('container false');
				    }*/
				    
					if( Browser.Platform.ios || Browser.Platform.android ) {

						zone = '';

						/*alert("total = " + (e.client.x - blocContainer.getPosition().x) + " < ou > " + btnzone 
						+ " x (client) : " +e.client.x + " x (page) :  " +e.page.x + zone 
						+ " / " + currentBloc.getElement('.btn_previous').getStyle('background-position') 
						+ " / " + currentBloc.getElement('.btn_next').getStyle('background-position') 
						+ " / " + currentBloc.getElement('.btn_next').retrieve('tween')
						+ ' / onViewingPic = ' + onViewingPic
						+ ' / zone ' + zone
						+ ' / onMouseClick = ' + onMouseClick 
						+ ' / Bloc size x' + blocContainer.getSize().x 
						+ ' / element class ' + currentBloc.hasClass('open') 
						);*/



					   // if ( onViewingPic == true ) {
							if ( e.client.x - blocContainer.getPosition().x < btnzone) {
								zone = 'PREVIOUS';								
							} else if ( e.client.x - blocContainer.getPosition().x > blocContainer.getSize().x - btnzone) {
								zone = 'NEXT';
							} else {
								zone = 'CENTER';
							}
					 //  	} // fin if viewving
					   	
					   //	alert(zone);
					} // fin ios
					
					
				    if ( zone != '' ) {
						onMouseClick = true;
				    }

				    e.stop();


				} // fin click
	}); // fin each bloc container
	

	theBlocs.each(function(element, index) {
		
			var theGuillotine = element.getElement('.guillotine');
			var theDesc = theGuillotine.getElement('p');
			var theImage = element.getElement('.image');
			var theBtn = element.getElement('.btn_zoom');

			var timeOutFn;
			var bloc_over = false;
			var bloc_open = false;

			element.addEvents({
			    /*'mousemove': function(e) {
				    new Event(e).preventDefault();
				    if ( element.hasClass('close') || element.hasClass('') ) {
				    } else {
						$('progress').set('text','x : '+e.client.x);
				   	}
				    e.stop();
			    },*/
			    'keydown': function() {
			   	    /*alert(event.key);   //Returns the lowercase letter pressed.
    				alert(event.shift); //Returns true if the key pressed is shift.
    				if (event.key == 's' && event.control) alert('Document saved.'); //Executes if the user hits Ctr+S.
    				*/
				},
			    'mouseenter': function() {
				   // new Event(e).preventDefault();

				    if ( element.hasClass('close') || element.hasClass('') ) {
						theBtn.setStyle('background-position', '0 -30px');

					    theImage.set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('margin-top', '-60%');
					    theDesc.set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('margin-top', '0');
						theGuillotine.set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('background-position', '0 -30px');
	
						bloc_over=true;
						
				    } else {
						theBtn.setStyle('background-position', '0 -60px');
						/*
							NEXT AND PREVIOUS 
						*/
						/*$('progress').get('tween').start('opacity',1).chain(function() {
							$('hl').highlight('#F0F');
						});*/
						//currentBloc.getElement('.btn_previous').setStyle('width', '41px');
	    				if(element.getPrevious())
							element.getElement('.btn_previous').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('width', '41px');
						//currentBloc.getElement('.btn_next').setStyle('width', '41px');
	    				if(element.getNext())
							element.getElement('.btn_next').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('width', '41px');

				    }
//					$clear(timeOutFn);
			    },
			    'mouseleave': function() {
	//			    new Event(e).preventDefault();

				    if ( element.hasClass('close') ) {
						theBtn.setStyle('background-position', '0 0');
	
					    theImage.set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('margin-top', '-50%');
					    theDesc.set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('margin-top', '-270px');
						theGuillotine.set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('background-position', '0 -540px');
	
						bloc_over=false;
				    } else {
						theBtn.setStyle('background-position', '0 -90px');
						/*
							NEXT AND PREVIOUS 
						*/
					//	$('progress').fade('out');
						//currentBloc.getElement('.btn_previous').setStyle('width', '0');
						element.getElement('.btn_previous').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('width', '0');
						//currentBloc.getElement('.btn_next').setStyle('width', '0');
						element.getElement('.btn_next').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('width', '0');
					 }

// Mettre la class dans et bloc_open dans le bloc.


//					timeOutFn = myBlocOverFct.delay(410);
			    },
			    click: function() {
			    	var storeBtnClose = btnclose;
			    	//alert(storeBtnClose);
			    	/*
			    		lien deja visité
			    	*/
			    	/*if(!element.getElement('.visited'))
				    	var img = new Element('img',{src:'design/view.gif', 'alt':'visited', 'class':'visited', title:'visited'}).injectInside(element);*/

					element.setStyle('margin-right','670px');
				    element.setStyle('clear', 'both');
			    	
//				    new Event(e).preventDefault();

					$('hl').highlight('#FF0');
			
			    	var img = theImage.getElement('img');
			    	var iWid = img.getSize().x;
			    	var iHei = img.getSize().y;
				    
				    if ( element.hasClass('close') ) {
				    	currentBloc = element;

				    	onViewingPic = true;
						onMouseClick = false;
				    	
				    	/*
				    		Add Event on body
				    	*/
				    			
				    	$(document.body).addEvent('click',function(e) {
							//if(window.console && window.console.firebug) window.console.log(" click ! " + onMouseClick + currentBloc.get('class') );
							
							if ( onViewingPic == true && onMouseClick == false ) {
								zone = '';
								currentBloc.fireEvent('click');
								window.console.log(zone + " / " + onMouseClick);
							}
						});

				    

				    	//element.setStyle('clear', 'both');
						
						/*
							Check Other elmts
						*/
				    	theBlocs.each(function(elementRec, index) {
				    		// Ferme les elements ouverts
				    		

				    		
				    		if (elementRec.hasClass('open')) {
				    			elementRec.bloc_open = false;
								if (elementRec.hasClass('open'))
									elementRec.removeClass('open').addClass('close');
								else
									elementRec.addClass('close');
												    			
							    var myFx = new Fx.Morph(elementRec, {duration: closingDuration, transition: Fx.Transitions.Quint.easeOut}).start({
								    'height': startDimensions,
								    'width': startDimensions
								});
							    var myFx2 = new Fx.Morph(elementRec.getElement('.image'), {duration: closingDuration, transition: Fx.Transitions.Quint.easeOut}).start({
								    'margin-top': '-50%',
								    'margin-left': '-50%'
								}).chain(function () {
				    				//elementRec.setStyle('margin-right','5px'); // reduit
				    				
									elementRec.getElement('.guillotine').fade(1);
									elementRec.getElement('.btn_zoom').setStyle('background-position', '0 -90px');
								    elementRec.getElement('p').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('margin-top', '-270px');
									elementRec.getElement('.guillotine').setStyle('background-position', '0 -540px');
									elementRec.getElement('.btn_previous').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('width', '0');
									elementRec.getElement('.btn_next').set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('width', '0');
									
									elementRec.setStyle('margin-right','5px');
									elementRec.setStyle('clear','none');

								});
				    		} 
				    		// Fade de l'ensemble des elmts
				    		if ( element != elementRec ) elementRec.fade(thumbnailDarker);
				    		// Sinon on affiche lelmts 
				    		else element.fade(1);	
				    		//if ( !element.hasClass('open')  ) elementRec.fade(.3);	
				    	});
				    								
						theGuillotine.fade(0);
						
						bloc_open = true;
						
						if (element.hasClass('close'))
							element.removeClass('close').addClass('open');
						else
							element.addClass('open');
						
						element.fireEvent('mouseenter');

					    var myFx = new Fx.Morph(element, {duration: openingDuration, transition: Fx.Transitions.Quint.easeOut}).start({
						   // 'height': iHei + 10,
						    'height': iHei + 10,
						    'width': 830
						});
					    var myFx2 = new Fx.Morph(theImage, {duration: openingDuration, transition: Fx.Transitions.Quint.easeOut}).start({
						    'margin-top': '0',
						    'margin-left': '0',
						    'margin':'0'
						}).chain(function () {

								//Decaller les menus
							//portfolioTempAnchorPaddingTop2 = element.getPosition().y - (window.innerHeight/2 - iHei/2);	
							//portfolioTempAnchorPaddingTop = -100;		
						//	portfolioTempAnchorPaddingTop = anchorsPaddingTop - (window.innerHeight/2 - iHei/2);
														
							portfolioTempAnchorPaddingTop = 0;							
						//	alert('here 1 ' +  portfolioTempAnchorPaddingTop + '/ ' + portfolioTempAnchorPaddingTop);
							sidebarmenu.store('_portfolioTempAnchorPaddingTop', portfolioTempAnchorPaddingTop);
							// ne sert plus
							
							sidebar.replacePosition(element.getPosition().y - anchorsPaddingTop);
							sidebar2.replacePosition(element.getPosition().y - anchorsPaddingTop);
							// Ajout 200911
						//	alert("here 8");
						// replace nav for ios
					//	placeNavigationForIos(0,element.getPosition().y - anchorsPaddingTop);
					//	placeNavigationForIos($(anchorsHash).getPosition());
					//	placeNavigationForIos({ x: '0', y: '0' });	
					//	placeNavigationForIos({x:0, y:element.getPosition().y - anchorsPaddingTop});
					//	placeNavigationForIos(element.getPosition());
						placeNavigationForIos(null,0,element.getPosition().y - anchorsPaddingTop - 40);
							
								// Recentrer le bloc 
							var scroll = new Fx.Scroll(window, { wait: false, duration: scrollingDuration, transition: Fx.Transitions.Quad.easeInOut });
							scroll.start(0, element.getPosition().y - (window.innerHeight/2 - iHei/2));



						// Modif 120711 : ne plus cacher le logotype
				        //$('header').fade('out');
							
								// Alpha du second menu
							//$('sidebar-menu2').getElement('ul').fade('0');
							
							theBtn.setStyle('background-position', '0 -60px');
						});
						
						
	
				    } else {
						onViewingPic=false;
						
						/*
							Remove Event on body
						*/
						
						$(document.body).removeEvents('click');

	
				    	var nextBlocToLoad;
				    	theBlocs.each(function(elementRec, index) {
				    		if ( element != elementRec ) {
				    		/*	if ( zone == 'PREVIOUS')
				    				nextBlocToLoad = theBlocs.getPrevious().fade(0);
				    			if ( zone == 'NEXT')
				    				nextBlocToLoad = elementRec.getNext().fade(0);*/
				    		}
				    		
				    		
				    		/*if (elementRec.hasClass('open')) {
				    			elementRec.bloc_open = false;
							    var myFx = new Fx.Morph(elementRec, {duration: 400, transition: Fx.Transitions.Quint.easeOut}).start({
								    'height': startDimensions,
								    'width': startDimensions
								});
							    var myFx2 = new Fx.Morph(elementRec.getElement('.image'), {duration: 400, transition: Fx.Transitions.Quint.easeOut}).start({
								    'margin-top': '-50%',
								    'margin-left': '-50%'
								}).chain(function () {
									elementRec.getElement('.guillotine').fade(1);
									elementRec.getElement('.btn_zoom').setStyle('background-position', '0 -90px');
								});
				    		} */

				    		elementRec.fade(1);	
				    	});

						bloc_open = false;

						element.fireEvent('mouseleave'); /* Contrairement a l'ouverture, on propage l'event avt de changer de class */
						
						if (element.hasClass('open'))
							element.removeClass('open').addClass('close');
						else
							element.addClass('close');


					    var myFx = new Fx.Morph(element, {duration: closingDuration, transition: Fx.Transitions.Quint.easeOut}).start({
						    'height': startDimensions,
						    'width': startDimensions
						});
					    var myFx2 = new Fx.Morph(theImage, {duration: closingDuration, transition: Fx.Transitions.Quint.easeOut}).start({
						    'margin-top': '-50%',
						    'margin-left': '-50%'
						}).chain(function () {
							
							element.setStyle('margin-right','5px');
				    		element.setStyle('clear', 'none');

							
							if (zone == 'CENTER' || zone == '' || storeBtnClose == 'TRUE') {
								/*
									Refermer
								*/
								
									//Decaller les menus
								portfolioTempAnchorPaddingTop = 0;							
								//portfolioTempAnchorPaddingTop = anchorsPaddingTop - (window.innerHeight/2 - iHei/2);							
								//alert('here');
								sidebarmenu.store('_portfolioTempAnchorPaddingTop', portfolioTempAnchorPaddingTop);
								// ne sert plus

							sidebar.replacePosition(element.getParent().getPosition().y - anchorsPaddingTop);
							sidebar2.replacePosition(element.getParent().getPosition().y - anchorsPaddingTop);
						
						//IOS 200911

						placeNavigationForIos(null,0,element.getParent().getPosition().y - anchorsPaddingTop);
								
									// Replacer sur l'ancre
								var scroll = new Fx.Scroll(window, { wait: false, duration: scrollingDuration, transition: Fx.Transitions.Quad.easeInOut });
								scroll.start(0, element.getParent().getPosition().y-anchorsPaddingTop);

								// replace nav for ios
								$('header').fade('in');
		
									// Alpha du second menu
								//$('sidebar-menu2').getElement('ul').fade('1');
							}
							
							theGuillotine.fade(1);
							theDesc.set('tween', {duration: 400, transition: Fx.Transitions.Quint.easeOut}).tween('margin-top', '-270px');
							theGuillotine.setStyle('background-position', '0 -540px');

							theBtn.setStyle('background-position', '0 -90px');
							
							//$('progress').set('text','click on zone : ' + zone);
							$('hl').highlight('#F00');
							
						//	element.getNext().fireEvent('mouseenter');
						
									/*
										Precedent
									*/
				    	
				    			if ( zone == 'PREVIOUS' && storeBtnClose == 'FALSE')
				    				if(element.getPrevious())
										element.getPrevious().fireEvent('click');
									/*
										Suivant
									*/

				    			if ( zone == 'NEXT' && storeBtnClose == 'FALSE')
				    				if(element.getNext()) {
										element.getNext().fireEvent('click');
									} else {
										// si derniere > replacer sur ancre + menu
										portfolioTempAnchorPaddingTop = 0;							
										sidebarmenu.store('_portfolioTempAnchorPaddingTop', portfolioTempAnchorPaddingTop);
										var scroll = new Fx.Scroll(window, { wait: false, duration: scrollingDuration, transition: Fx.Transitions.Quad.easeInOut });
										scroll.start(0, element.getParent().getPosition().y-anchorsPaddingTop);

										// replace nav for ios
										$('header').fade('in');

									}
									
									
							//if (zone == 'PREVIOUS' || zone == 'NEXT' ) //nextBlocToLoad.fireEvent('click'); 
								//nextBlocToLoad.fade('0');
						});
				    }

			    }
			});
		});
	} // Fin function setBlocs


