/* Extends jQuery
------------------------------------------ */
$.isIE = $.browser.msie;
$.isIE6 = $.browser.msie && $.browser.version <= 6;
$.maxArr = function(arr){
	return arr.sort(function(a,b){ return b-a; })[0];
};
$.ajaxSetup({ cache: false });

/* Fix IE selectors
------------------------------------------ */
if( $.isIE ){
	$('.col > .box:last-child').css({ borderBottom: 0 });
	$('.box > :last-child, .bloc > :last-child').css({ marginBottom: 0 });
	$('#navigation ul li:last-child a').css({ borderRight: 0 });
};
if( $.isIE6 ){
	//$('.col:first-child').css({ borderLeft: 0 });
	$('.b-news').hover(
		function(){ $(this).css({ backgroundColor: '#E7ECF2' }); },
		function(){ $(this).css({ backgroundColor: 'transparent' }); }
	);
	$('#sub-nav ul li:first-child a').css({ borderLeft: 0 });
	$('.col:not(:first-child)').css({ borderLeft: '10px solid #E4EFEF' });
	$('.col > .box:first-child').css({ borderTop: '10px solid #E4EFEF' });
	$('.list.order li:first-child, .title + .list-x, .box + .list-x').css({ borderTop: 0 });
	$('.tab-content > *').css({ display: 'none' });
	$('.tab-content > :first-child').css({ display: 'block' });
	$('#navigation > li').addClass('lv1');
	$('.list li:first-child h3').css({ borderTop: 0 });
	$('#navigation ul li:first-child a').css({ borderLeft: 0 });
	$('.flash:not(.b-title)').addClass('flash-object');
};




/* Navigation
------------------------------------------ */
(function($){
	var nav = $(document.getElementById('navigation'));
	$('> li',nav).mouseover(function(){
		$('> li.active-state',nav).removeClass('active-state').addClass('default-state');
		$(this).removeClass('default-state').addClass('active-state');
	});
})(jQuery);
/*
ANCIEN COMPORTEMENT
(function($){
	var nav = $('#navigation'), index = $('> li',nav).index($('> li.current',nav));
	nav.hover(
		function(){},
		function(){ nav.find('> li:eq(' + index + ')').removeClass('default-state').addClass('active-state'); }
	).find('> li').hover(
		function(){
			nav.find('> li.active-state').removeClass('active-state').addClass('default-state');
			$(this).removeClass('default-state').addClass('active-state');
		},
		function(){ $(this).removeClass('active-state').addClass('default-state'); }
	);
})(jQuery);
*/


/* Tabs (onglets)
------------------------------------------ */
$.fn.tabs = function(){
	return this.each(function(){
		// Vars
		var _this = $(this),
			__ = {
				content : $('+ .tab-content',_this),
				type: (_this.hasClass('ajax')) ? 'ajax' : 'noajax'
			};
		// Functions
		var switchTab = function(index){
			$('li.on',_this).removeClass('on');
			$('li:eq(' + index + ')',_this).addClass('on');
		};
		
		// Core
		$('li',_this).click(function(){
			if( !$(this).hasClass('on') && !$(this).hasClass('off') ){
				var LI = this,
					index = $('li',_this).index(this);
				if(__.type == 'noajax'){
					$('> *',__.content).css({ display: 'none' });
					$('> *:eq(' + index + ')',__.content).css({ display: 'block' });
					switchTab(index);
				}
				if(__.type == 'ajax'){
					var url = $('a',LI).attr('href');
					__.content.empty().addClass('tab-loading');
					$.ajax({
						url: url,
						success: function(html){
							__.content.append(html).removeClass('tab-loading');
							switchTab(index);
						},
						error: function(){
							__.content.append('Désolé, une erreur est survenue.').removeClass('tab-loading');
						}
					});
				}
			}
			return false;
		});
	});
};
$('.tab, #prog-tv-nav').tabs();



