$(function() { 
	
	$("a.spip_out").attr("target", "_blank");
	
	$("#documents_portfolio a").fancybox();

	$(".texte_article a").each(function() {
		var url = $(this).attr('href');
		var extension = url.substr(url.length-3, url.length);
		if(extension == "pdf") { $(this).attr("target", "_blank"); } 
	});
	
	if($("#documents_portfolio_diapo").length > 0) {
		$('#documents_portfolio_diapo').innerfade({ timeout: 3000, speed: "slow", type: 'random', containerheight: $('#documents_portfolio_diapo').css("height") });
	}
	
	
	
	
	
	
	
	if( $('#blockfocushome').length ) {

		//$.browser.msie && $.browser.version == 7
		var ie6 = (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("MSIE 6.0") != -1);
		var ie7 = (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("MSIE 7.0") != -1);
		
		if( !($.browser.msie && $.browser.version == 7) ) {
			$('a#bt_prec, a#bt_suiv').hover(function() {
				$(this).stop().animate({opacity: 0.6});
			}, function() {
				$(this).stop().animate({opacity: 1});
			});
		}
		
		$('div#blockfocushome ul li div.zone_txt').css('opacity', 0.8);
		
		$('div#blockfocushome ul li.cliquable').click(function() {
			var lien = $(this).find('a').attr('href');
			window.location = lien;
		});
		$('div#blockfocushome ul li.cliquable').hover(function() {
			$(this).find('div.zone_txt').animate({ marginTop: '400px' }, 400);
		}, function() {
			$(this).find('div.zone_txt').animate({ marginTop: '331px' }, 200);
		});
		
		var mrg = 0;
		var wli = 649;

		$("#blockfocushome ul").css("width", ($('#blockfocushome ul li').length)*wli);
		var wprog = $("#blockfocushome ul").css("width");
		wprog = parseInt(wprog.replace(/px/, ''));
		var eslid = 1;
		var butee = -1;
		var mlmin = -(wprog-wli*eslid);
		var d = 1000;

		$("a#bt_prec").click(function() {
			clearInterval(loopy);
			mrg += wli*eslid;
			if( butee>0 ) butee=0;
			
			if( mrg>=0 ){ butee--; mrg = 0; }
			
			if( butee>=-1 ){
				$("#blockfocushome ul").animate({marginLeft: mrg+"px"}, d);
			}
			return false;
		});

		$("a#bt_suiv").click(function() {
			clearInterval(loopy);
			mrg -= wli*eslid;
			if( butee<0 ) butee=0;
			if( mrg <= mlmin ){ butee++; mrg = mlmin; }
			if( butee>1 ){
				butee=-1;
				mrg = 0;
				$("#blockfocushome ul").animate({marginLeft: mrg+"px"}, d*($('#blockfocushome ul li').length));
			}
			else {
				$("#blockfocushome ul").animate({marginLeft: mrg+"px"}, d);
			}

			return false;
		});


		function auto_rotation() {
			mrg -= wli*eslid;
			if( butee<0 ) butee=0;
			if( mrg <= mlmin ){ butee++; mrg = mlmin; }
			if( butee>1 ){
				butee=-1;
				mrg = 0;
				$("#blockfocushome ul").animate({marginLeft: mrg+"px"}, d*($('#blockfocushome ul li').length));
			}
			else {
				$("#blockfocushome ul").animate({marginLeft: mrg+"px"}, d);
			}
		}
		loopy = window.setInterval(auto_rotation, 4900);


	}
});

