// JavaScript Document


var current_news = 0;
var current_guide = 0;
var block_opacity = 0.5;
var state_block = new Array();

function init_blocks(){

	$("#txt-top-right").fadeTo(200,block_opacity);
	$("#tab-top-right a").fadeTo(200,block_opacity);

	$("#txt-bottom-right").fadeTo(200,block_opacity);
	$("#tab-bottom-right a").fadeTo(200,block_opacity);

	$("#txt-bottom-left").fadeTo(200,block_opacity);
	$("#tab-bottom-left a").fadeTo(200,block_opacity);
}


function display_block(_id,_action){

	if(_action == true){
		$("#txt-"+_id).stop(true,true).fadeTo(300,1);
		$("#tab-"+_id+" a").stop(true,true).fadeTo(300,1);
	}

	if(_action == false){
		$("#txt-"+_id).fadeTo(300,block_opacity);
		$("#tab-"+_id+" a").fadeTo(300,block_opacity);
	}
}

function display_tab(_y,_x,_id){

	if($("#"+_y+"-"+_x+"-"+_id).css('display') == "none"){

		var old_id = 1;
		if(_id==1){ old_id = 2; }

		// toggle de l'onglet
		$("#lnk-"+_y+"-"+_x+"-"+old_id).removeClass('tab-'+_x+'-active');
		$("#lnk-"+_y+"-"+_x+"-"+old_id).addClass('tab-'+_x+'-passive');

		$("#lnk-"+_y+"-"+_x+"-"+_id).removeClass('tab-'+_x+'-passive');
		$("#lnk-"+_y+"-"+_x+"-"+_id).addClass('tab-'+_x+'-active');

		// toggle du contenu
		$("#"+_y+"-"+_x+"-"+old_id).css('display','none');
		$("#"+_y+"-"+_x+"-"+_id).css('display','block');
	}
}

$(document).ready(function(){

	$('#lnk-top-right-1').click(function(){ display_tab("top","right",1); });
	$('#lnk-top-right-2').click(function(){ display_tab("top","right",2); });
	$('#lnk-bottom-right-1').click(function(){ display_tab("bottom","right",1); });
	$('#lnk-bottom-right-2').click(function(){ display_tab("bottom","right",2); });
	$('#lnk-bottom-left-1').click(function(){ display_tab("bottom","left",1); });
	$('#lnk-bottom-left-2').click(function(){ display_tab("bottom","left",2); });

	$('#home-actus-left').click(function(){ current_news = display_carousel("left",".home-actus-slider",".home-actus-slide", 1, 365,current_news); });
	$('#home-actus-right').click(function(){ current_news = display_carousel("right",".home-actus-slider",".home-actus-slide", 1, 365,current_news); });

	$('#home-guide-left').click(function(){ current_guide = display_carousel("left",".home-guide-slider",".home-guide-slide", 2, 365,current_guide); });
	$('#home-guide-right').click(function(){ current_guide = display_carousel("right",".home-guide-slider",".home-guide-slide", 2, 365,current_guide); });

	init_blocks();

	$("#top-right").mouseenter(function(){ display_block('top-right',true); });
	$("#bottom-right").mouseenter(function(){ display_block('bottom-right',true); });
	$("#bottom-left").mouseenter(function(){ display_block('bottom-left',true); });
	$("#top-right").mouseleave(function(){
		if ($('#top-right-1').css('display') == 'none') {
			display_block('top-right',false);
		} else {
			display_block('top-right',true);
		}
	});
	$("#bottom-right").mouseleave(function(){ display_block('bottom-right',false); });
	$("#bottom-left").mouseleave(function(){ display_block('bottom-left',false); });


});
