$(document).ready(function() { 
	$("#ul-pied-de-page li:first-child").addClass('first');
	$("p:last-child").addClass('last');
	$("div.sous-page:last-child").addClass('last');
	
	jQuery.mediaResize();
	
	if ($('#colonne-gauche').height() < $('#colonne-droite').height()) {
		$('#colonne-gauche').css('height', $('#colonne-droite').height());
	}
	
	//initialize slideshow if any
	if ($('#slideshow').length != 0) {
		var $length = $("#slideshow img").length;
		var $random = Math.floor(Math.random()*$length) + 1;
		$("#slideshow img:nth-child(" + $random + ")").addClass("active");
		setInterval( function() { slideSwitch("slideshow"); }, 4000 );
	}

	
});

//arrière-plan
$(function(){
	var color = $('body').attr('class');	   
	$('#bgimg').attr("src", "/theme/images/bg_" + color + ".jpg");
	$.fn.supersized.options = {  
		startwidth: 1600,  
		startheight: 1000,
		minsize: .50,
		slideshow: 0,
		slideinterval: 2000  
	};
	$('#arriereplan').supersized(); 
});

//sous-menus
$(function () {
	$('div.sousnav').each(function () {
		$(this).parent().eq(0).mouseover(function() {
				var current = $('div.sousnav:eq(0)', this);
				current.show();
				$(this).addClass('ouvert');
		});
		$(this).parent().eq(0).mouseout(function() {
				var current = $('div.sousnav:eq(0)', this);
				current.hide();
				$(this).removeClass('ouvert');
		});
	});
	
	/*
	if ($.browser.msie && $.browser.version.substr(0,1)<8) {
		//do nothing
	}
	else {
		$('div.sousnav a').hover(function () {									   
			$(this).stop(true).animate({paddingLeft: '15px'}, {speed: 100, easing: 'easeOutCubic'});		
		}, function () {
			$(this).stop(true).animate({paddingLeft: '0'}, {speed: 100, easing: 'easeInCubic'});
		});
	};
	*/
});

function highlightMenu(id) {
	$('#' + id).addClass('actif');
}

function slideSwitch(id) {
    var $active = $('#' + id + ' img.active');

    if ( $active.length == 0 ) $active = $('#' + id + ' img:last');

    var $next =  $active.next().length ? $active.next()
        : $('#' + id + ' img:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

