
jQuery.noConflict();

jQuery(document).ready(function() {

	// Main menu
	jQuery("#main_menu li").children('ul').hide();
	
	jQuery("#main_menu li").each(function() {
		var width = (jQuery(this).width() - 6);
		jQuery("#main_menu li ul li a").css('width', width +'px');
	});
	
	jQuery("#main_menu li").hover(function(){
		jQuery(this).children('ul').show();
		var widthOri = jQuery(this).width();
		var width = (jQuery(this).width() - 6);
		if (width < 100) {
			width = 100;
		}
		jQuery(this).children('ul').css('width', width +'px');
	}, function(){
		jQuery(this).children('ul').hide();
	});
	
	//Custom settings
	var style_in = 'jswing';
	var style_out = 'jswing';
	var speed_in = 300;
	var speed_out = 500;

	//Calculation for corners
	var neg = Math.round(jQuery('#encart_part .qitem').width() / 2) * (-1);
	var pos = neg * (-1);
	var out = pos * 2;

	jQuery('#encart_part .qitem').each(function () {
		//grab the anchor and image path
		url = jQuery(this).find('a').attr('href');
		img = jQuery(this).find('a img').attr('src');

		//remove the image
		jQuery('a img', this).remove();

		//append four corners/divs into it
		jQuery(this).append('<div class="topLeft"></div><div class="topRight"></div><div class="bottomLeft"></div><div class="bottomRight"></div>');

		//set the background image to all the corners
		jQuery(this).children('div').css('background-image','url('+ img + ')');

		//set the position of corners
		jQuery(this).find('div.topLeft').css({top:0, left:0, width:pos , height:pos});
		jQuery(this).find('div.topRight').css({top:0, left:pos, width:pos , height:pos});
		jQuery(this).find('div.bottomLeft').css({bottom:0, left:0, width:pos , height:pos});
		jQuery(this).find('div.bottomRight').css({bottom:0, left:pos, width:pos , height:pos});

	}).hover(function () {
		//animate the position
		jQuery(this).find('div.topLeft').stop(false, true).animate({top:neg, left:neg}, {duration:speed_out, easing:style_out});
		jQuery(this).find('div.topRight').stop(false, true).animate({top:neg, left:out}, {duration:speed_out, easing:style_out});
		jQuery(this).find('div.bottomLeft').stop(false, true).animate({bottom:neg, left:neg}, {duration:speed_out, easing:style_out});
		jQuery(this).find('div.bottomRight').stop(false, true).animate({bottom:neg, left:out}, {duration:speed_out, easing:style_out});
	},

	function () {
		//put corners back to the original position
		jQuery(this).find('div.topLeft').stop(false, true).animate({top:0, left:0}, {duration:speed_in, easing:style_in});
		jQuery(this).find('div.topRight').stop(false, true).animate({top:0, left:pos}, {duration:speed_in, easing:style_in});
		jQuery(this).find('div.bottomLeft').stop(false, true).animate({bottom:0, left:0}, {duration:speed_in, easing:style_in});
		jQuery(this).find('div.bottomRight').stop(false, true).animate({bottom:0, left:pos}, {duration:speed_in, easing:style_in});
	}).click (function () {
		//go to the url
		window.location = jQuery(this).find('a').attr('href');
	});

    //alternate background colors on tables
    jQuery(".agenda table tr:even").addClass("odd");
    jQuery(".agenda table tr td:nth-child(1)").addClass("date");
    jQuery(".agenda table tr td:nth-child(3)").addClass("tarifs");
});
