function formatText(index, panel) {
	  return index + "";
    }

$(function () {   
	
	$('img').error(function () {
		var altt = $(this).attr('src');
		$(this).unbind('error').attr('title', altt);
		$(this).unbind('error').attr('src', '/img/broken.gif');
	});

	$('li:last-child, .two-col .col:last-child, .three-col .col:last-child, .four-col .col:last-child, tr:last-child, td:last-child').addClass('last');
	$('li:first-child, .two-col .col:first-child, .three-col .col:first-child, .four-col .col:first-child').addClass('first');
	
	$('tr:even').addClass('even');
	
	$('#nav li a').each(function(index) {
	    if($(this).text().length > 23) {
			$(this).parent().addClass('large');
		}
	});
	
	$('#nav li.large.active').addClass('large-active');
	
	$('.blank').click(function() {
		window.open($(this).attr('href'));
		return false;
	});

	$(".homepage .block").click(function(){
		window.location=$(this).find("a").attr("href");
	});

	$(".hpzoom div").hover(function() {
		$(this).css({'z-index' : '0'}); /*Add a higher z-index value so this image stays on top*/ 
		$(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
			.animate({
				marginLeft: '-250px',/* The next 4 lines will vertically align this image */ 
				marginTop: '-250px', 
				top: '50%',
				left: '50%',
				width: '500px', /* Set new width */
				height: '500px', /* Set new height */
				padding: '0px'
			}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */
	
		} , function() {
		$(this).css({'z-index' : '0'}); /* Set z-index back to 0 */
		$(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
			.animate({
				marginTop: '0', /* Set alignment back to default */
				marginLeft: '0',
				top: '0%',
				left: '0%',
				width: '375px', /* Set width back to default */
				height: '375px', /* Set height back to default */
				padding: '0'
			}, 400);
	});

	
	$(".lightbox-gallery").fancybox({
		'width'				: 867,
		'height'			: 520,
		'padding'           : 7,
		'overlayOpacity'    : 0.5,
		'overlayColor'      : '#000',
		'scrolling'         : 'no',
		'autoScale'         : false,
		'type'				: 'iframe',
		'centerOnScroll'    : true     
	});

	$(".popup").fancybox({
		'padding'           : 20,
		'overlayOpacity'    : 0.5,
		'overlayColor'      : '#000',
		'scrolling'         : 'no',
		'autoScale'         : true,
		'centerOnScroll'    : true     
	});
	
    $('.slider').anythingSlider({
        easing: "easeInOutExpo",     
        autoPlay: false,             
        delay: 3000,                 
        startStopped: true,          
        animationTime: 600,          
        hashTags: true,              
        buildNavigation: true,       
		pauseOnHover: true,          
		startText: "Go",             
     stopText: "Stop",               
     navigationFormatter: formatText 
    });
    
    $("#slide-jump").click(function(){
        $('.slider').anythingSlider(4);
    });

	loader();

	/* ------------ CHECK LIENS ET IMAGES */
	/*$('img').each(function(){
		$(this).wrap('<span></span>');
		var html = $(this).parent().html();
		var alt = html.match( /alt=/ );
		if(alt==null) {
			$(this).css('border','2px dotted #0FF'); //pas de alt
		} else {
			$('img[alt=""]').css('border','5px solid #0F0'); //alt vide
		}
	});
	/*$('a').each(function(){
		$(this).wrap('<span></span>');
		var html = $(this).parent().html();
		var title = html.match( /title=/ );
		if(title==null) {
			$(this).css({'border-top':'2px dotted #9F0', 'border-bottom':'2px dotted #9F0'}); //pas de title
		} else {
			$('img[title=""]').css('border','2px solid #0F0'); //title vide ??
		}
	});*/
});

/* ------------ SLIDESHOW */
var j = 0;

function loader(){
	
	var img = new Image();
	$(img).load(function(){
		var el = $("li:eq("+j+")", "#superslideshow");
		$(el).html(this);
		if(j<$("#superslideshow .images li").length){
			j++;
			if(j==$("#superslideshow .images li").length-1){
				slideShow();
			}
			loader();
		}
	}).attr('src',$("#superslideshow li:eq("+j+") img").attr('src'));
}

function slideShow() {
	$('#superslideshow .images li').hide();
	$('#superslideshow li:first').fadeIn("slow");
	interval = setInterval('gallery()',4000);
	$('.home_slide #links a:first').addClass('current');
}

var interval;

function gallery() {
	var current = $('#superslideshow li.show');
	$('#superslideshow li').fadeOut(1000);
	$('#superslideshow li').removeClass('show');
	var next = ((current.next().length) ? ((current.next().hasClass('show'))? $('#superslideshow li:first') :current.next()) : $('#superslideshow li:first'));
	next.fadeIn(1000);
	next.addClass('show');

	var currentit = $('.homepage #title span.show');
	$('.homepage #title span.last').fadeOut(1000);
	$('.homepage #title span').removeClass('show');
	var nextit = ((currentit.next().length) ? ((currentit.next().hasClass('show'))? $('#title span:first') :currentit.next()) : $('#title span:first'));
	nextit.fadeIn(1000);
	nextit.addClass('show');
}


