var currentReportage = 0;
var index_reportages_index = 0;
$(function () {
	if($("#alert")) {
		$("#alert").hide().fadeIn();
		setTimeout('closeAlert()', 5000)
	}	
	
	
	
	$("a.blackfx").each(function(i, el){
		if($(el).find("img:first").attr("src") != undefined) {
			var src = $(el).find("img:first").attr("src")
			var src_hover = src.substr(0,src.length-12)
			$("<img />").attr("src", src_hover);
			$(el).hover(
				function() {
					$(this).find("img").attr("src", src_hover) 
				},
				function() {
					$(this).find("img").attr("src", src) 
				}
			)
		}
	})
	$("#photo_description").hide();
	$("#show_rep").click(function() {
		$("#reportage_description").animate({height:'300px'});
		$("#photo_description").slideUp();
	})
	$("#show_photo").click(function() {
		$("#reportage_description").animate({height:"50px"});
		$("#photo_description").slideDown();
	})
	$('.scroll-pane').jScrollPane({scrollbarMargin:20});
})

function changeDescriptionPhoto(desc) {
	if(desc == "") desc = "Aucune description";
	$("#scroll-pane-photo").html(desc)
	if(desc != "Aucune description") {
		$("#reportage_description").animate({height:"50px"});
		$("#photo_description").slideDown("normal", function() {
			$('#scroll-pane-photo').jScrollPane({scrollbarMargin:20});
		});
	} else {
		$("#reportage_description").slideDown("normal", function() {
			$('.scroll-pane').jScrollPane({scrollbarMargin:20});
		});
		$("#photo_description").animate({height:"50px"});
	}
}

function scollReportages(delta) {
	$("#autre_previous").show();
	$("#autre_next").show();
	maxReportage = $(".autre_reportage ul li").length-5
	if(maxReportage < 0) maxReportage = 0
	currentReportage += (delta == "next") ? 1 : -1 ;
	if(currentReportage <= 0) {
		currentReportage = 0;
		$("#autre_previous").hide();
	}
	if(currentReportage >= maxReportage) {
		currentReportage = maxReportage;
		$("#autre_next").hide();
	}
	$('.autre_reportage ul').animate({"marginLeft":"-"+(currentReportage*192)+"px"}, 500);  
}

function closeAlert() {
	$("#alert").fadeOut();
}

function print_r(theObj){
	if(theObj.constructor == Array || theObj.constructor == Object) {
		document.write("<ul>");
		for(var p in theObj){
			if(theObj[p].constructor == Array || theObj[p].constructor == Object) {
				document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
				document.write("<ul>");
				print_r(theObj[p]);
				document.write("</ul>");
			} else {
				document.write("<li>["+p+"] => "+theObj[p]+"</li>");
			}
		}
		document.write("</ul>");
	}
}