//----------------------------------------------------------------
//	INIT
//---------------------------------------------------------------- 
jQuery(document).ready(function($){ 
	/*					
 	//t("jquery ready");
	//cssBgColorRand([$("#header"), $("#nav"), $("#content"), $("#footer")]);
	
	//'piou' title setup
	Cufon.replace('#logo h1', {fontFamily: 'mpl', textShadow: '#fff 1px 1px'});
	

	
//	$("#nav div").each(function (){ $(this).css("background-color", "#"+randHexa()); });
	//---------------------------------------------------
	// nav
	//---------------------------------------------------
	$("#nav div[selected]").addClass('navHover');
	$("#nav div").hover(function() { 
	//	$(this).css('color', '#1599e5');
		$(this).addClass('navHover');
		Cufon.refresh('#nav div');
		//$(this).css("background-color", "#"+randHexa());
	},function(){
		//t($(this).attr("selected"));
		if($(this).attr("selected") !== undefined){
			//has the attribute			
		} else {
			//hasn'tthe attribute
			$(this).removeClass('navHover');
		}
		Cufon.refresh('#nav div');
	});
	// click nav button
	$("#nav div").click(function() {
		var paged = $(this).attr('pageId');
		window.location.href = "?page_id="+paged;
		//t("click: "+paged);
	}).css("cursor","pointer");	

	Cufon.replace('#nav div', {fontFamily: 'mpr', textShadow: '#fff 1px 1px'});
	*/
	
	//content center
/*
	for (var i=0; i<1; i++){
		$('#contentLeft').append("<div class='contentLeftEl' url='"+i+"'><div class='contentLeftElInfo'><div class='title'>title</div><div class='content'> Eleifend ante, quis iaculis tortor nulla at arcu. Nullam diam diam, cursus et malesuada a, interdum id risus. Proin auctor volutpat ligula, non vulputate nisl ultricies sollicitudin. Ut dolor est, pharetra at pretium eget, interdum ac lectus. p </div></div></div>");
		
	}
*/

	$('#contentLeft .contentLeftEl').each(function (){
		var flickrSetId = $(this).attr("flickrSetId");
		//t(flickrSetId);
		if(flickrSetId != ""){
			var thumbArray = thumbFxArray["s"+flickrSetId];
			if(thumbArray != undefined){				
				var divRef = $(this).find(".contentLeftElImage");
				$('<img />')
					.attr('src', thumbArray[0])
					.load(function(){
						divRef.html("");
						divRef.html($(this));
						$(this).css({ opacity: 0 }).fadeTo('slow', 1); 
						var marginTop = -(divRef.parent().height() - $(this).height())/2;
						//console.log($(this).parent().height()+" "+$(this).height()+" "+marginTop);
						$(this).css("margin-top", -marginTop+"px");
						var marginLeft = -(divRef.parent().width() - $(this).width())/2;
						$(this).css("margin-left", -marginLeft+"px");
						
					});
				}
		}
	})
	// mouse move FX
	$('#contentLeft .contentLeftEl').mousemove(function(e) {  	
		var flickrSetId = $(this).attr("flickrSetId");
		//t(flickrSetId);
		if(flickrSetId != ""){
			var thumbArray = thumbFxArray["s"+flickrSetId];
			if(thumbArray != undefined){
				// -40 de marge
				var mouseXPourcent = (e.pageX - $(this).position().left - 40) / $(this).width(); 		 
				if(mouseXPourcent < 0) mouseXPourcent=0;
				if(mouseXPourcent > 1) mouseXPourcent=1;	 
				var imageIndex = Math.round((thumbArray.length-1) * mouseXPourcent);				
				var divRef = $(this).find(".contentLeftElImage");
				//t($(this).attr("thumbArrayImageIndex")+" "+imageIndex);
				//je stock le dernier index pour ne charger la nouvelle image QUE si nouvel index
				if($(this).attr("thumbArrayImageIndex") != imageIndex){
					$(this).attr("thumbArrayImageIndex",imageIndex)
					//t("new :"+thumbArray[imageIndex])
					//référence de image > comme ça le asyncload kill le précédent
					if(asyncLoad["s"+flickrSetId] == undefined){
						asyncLoad["s"+flickrSetId] = $('<img />');
					}
					asyncLoad["s"+flickrSetId]
						.attr('src', thumbArray[imageIndex])
						.load(function(){
							divRef.html("");
							divRef.html($(this));
							var marginTop = -(divRef.parent().height() - $(this).height())/2;
							//console.log($(this).parent().height()+" "+$(this).height()+" "+marginTop);
							$(this).css("margin-top", -marginTop+"px");
							var marginLeft = -(divRef.parent().width() - $(this).width())/2;
							$(this).css("margin-left", -marginLeft+"px");						
					});
				}
			}				
		} else {
			$(this).remove();	
		}
	}); 
	//boucle sur la description du thumb > la place en bas
	$('#contentLeft .contentLeftEl .contentLeftElInfo').each(function (){
		//aligner l'infobox en bas
		var animFrom = "160px";
		$(this).attr("animTo",(150-$(this).height())+"px");
		$(this).attr("animFrom", "160px");
		$(this).css("margin-top", animFrom);
		//$(this).hide();	
	});
	//masonry
	$('#contentLeft').masonry({ columnWidth: 161,
								animate:true,
								animationOptions: {
										duration: 100,
										easing: 'linear',
										queue: false
									}
								});
	// FX hover / out : apprition info
	$('#contentLeft .contentLeftEl').hover(function() {
		var elInfo = $(this).find(".contentLeftElInfo");
		elInfo.animate( { marginTop: elInfo.attr("animTo")}, { duration: 120, easing: 'easeOutQuad' });
	},function(){
 		var elInfo = $(this).find(".contentLeftElInfo");
		elInfo.animate( { marginTop: elInfo.attr("animFrom")}, { duration: 120, easing: 'easeOutQuad' });
	});
	//click
	$('#contentLeft .contentLeftEl').click(function() {
		//t("click: "+$(this).attr("url"));
		window.location.href = "?page_id="+$(this).attr("url");
	}).css("cursor","pointer");	
//	$('#contentLeft .contentLeftEl').corner("round 8px");
	//content right
	$('.contentRightBox').corner("round 4px");
	Cufon.replace('.contentRightBox h2', {fontFamily: 'mpr', textShadow: '#fff 1px 1px'});
	
});



