$(document).ready(function(){
    //gestion des onglets 1er niveau (fermer 1er label au chargement)
		$('div.label').hover(function(){
			$.cookie("InteraktingActive", $(this).attr('id'));
		});
		//initialisation accordion
		initPage($.cookie("InteraktingActive"));
		$('#logo a').click(function(){$.cookie("InteraktingActive", null);});
		
		//affichage du contenu
		$('.button a').click(function(){
			$('.slide div.data').css('height','auto');
			var myButton = $(this);
			$('.button a').removeClass('active');
			$(this).addClass('active');
			$('div.button').removeClass('active');
			$(this).parent('div.button').addClass('active');

			$('.action .button a').animate({width:'155px'}, 5, function(){});
			if (myButton.parents().parent().hasClass("action")) $(this).animate({width:'180px'}, 200, function(){});
			
			$('.label').hide();
			//$('.label').slideUp('fast');
			myButton.parents('.inner .visuel:first').fadeOut('fast', function() {
					myButton.parents('.inner .visuel:first').html($('#'+myButton.attr('rel')+' .visuel').html());
			});
			myButton.parents('.inner .visuel:first').fadeIn('fast');
			$('.subsection').hide();
			//$('.subsection').slideUp(300);
			$('#'+$(this).attr('rel')).show();
			//$('#'+$(this).attr('rel')).delay(10).slideDown('fast');
		});
	
	// navigation gauche
    $('#navigation a').click(function(){
			globalCloser();
			var indexOpen = $(this).attr("name");
			$.cookie("InteraktingActive", 'label'+indexOpen);
			$(".slide").accordion('activate', parseInt(indexOpen-1));
    });
		
	// footer
		$('.footer-bloc h4 a').click(function(){
			globalCloser();
			var indexOpen = $(this).attr("name");
			$.cookie("InteraktingActive", 'label'+indexOpen);
			$(".slide").accordion('activate', parseInt(indexOpen-1));
    });
    $('.footer-bloc .button a').click(function(){
			globalCloser();
			var indexOpen = $(this).attr("name");
			$(".slide").accordion('activate', parseInt(indexOpen-1));
			$.cookie("InteraktingActive", 'label'+indexOpen);
			var indexSection = $(this).attr("rel");console.log(indexSection);
			if (indexSection!="") {
				$('.label').hide();
				//$('.label').slideUp('fast');
				$('#'+indexSection).show();
			//$('#'+indexSection).slideDown('fast');
			}
    });
	
	// boutton fermer subcontent
    $('.close').click(function(){
		globalCloser();
    });

	// bouton fermer dans les subsections
    $('.close').hide();
    $('.subsection').hover(function(){
        $('.close').fadeIn(100);
    }, function(){
        $('.close').fadeOut(100);
    });
	
	
	positionContentImg();
	
	//accordion
	$( ".accordion" ).accordion({ autoHeight: true });
	//jScrolltabs();

	
});


function positionContentImg(){
	$('#classic-content .bloc .visuel').addClass('float-'+$('#classic-content .bloc .visuel img').attr('align'));
	$('#classic-content .bloc .visuel img').removeAttr('align');
}

// retablissement du visuel d'origine dans le premier onglet
function callBack(){
	$('div.ui-accordion-content .inner .visuel:first').html($('div.ui-accordion-content .subsection:first .visuel').html());
	$('.button a').removeClass('active');
	$('div.button').removeClass('active');
}
//fermeture des onglets
function globalCloser(){
		$('div.ui-state-active').hide();
			$('.subsection').slideUp('fast');
			//$('div.label:not(.ui-state-active)').slideDown('slow');
			$('div.label:not(.ui-state-active)').show();
			$('div.ui-accordion-content-active').animate({
					height:$('.ui-accordion-content-active .inner').height()+'px'
			});
			$('.action .button a').animate({
					width:'155px'
			}, 5, function(){});
		callBack();
}

//intialisation de la page
function initPage(isActive){
	if(isActive==null){
		$('.label:first').hide();
		$(".slide").accordion({
			event: 'mouseover',
			header: 'div.label',
			active: 0,
			fillSpace: false,
			changestart : function(){
				$('div.ui-state-default').height('62px');
				$('div.ui-state-default').slideDown('fast');
				if($('div.ui-accordion-content-active').prev('div.ui-state-active')){
					$('div.ui-accordion-content-active').prev('div.ui-state-active').slideUp('fast');
				}
			}
		});
	} else {
		var numActive = parseInt(isActive.substr((isActive.length-1), 1))-1;
		//console.log(isActive +'---'+numActive);
		$('#'+isActive).slideUp('fast');
		//console.log('#'+isActive);
		$(".slide").accordion({
			event: 'mouseover',
			header: 'div.label',
			active: numActive,
			fillSpace: false,
			changestart : function(){
				$('div.ui-state-default').height('62px');
				$('div.ui-state-default').slideDown('fast');
				if($('div.ui-accordion-content-active').prev('div.ui-state-active')){
					$('div.ui-accordion-content-active').prev('div.ui-state-active').slideUp('fast');
				}
			}
		});
	}
	callBack();
}
/*
function jScrolltabs(){
//jquery scrolltabs
	if(($.browser.msie && $.browser.version.substr(0,1)<=6)){
		$('.scrollabletab > ul > li').addClass('ieTabs');
			$('.scrollabletab > ul > li a').click(function(){
				$('.scrollabletab > ul > li').removeClass('ieTabsActive');
				$(this).parent('li').addClass('ieTabsActive');
				var tabToOpen = $(this).attr('href');
				$('.scrollabletabcontent').hide();
				$(tabToOpen).show();
				return false;
			});
		$('.scrollabletab .scrollabletabcontent').addClass('ieTabsContent');
		$('.scrollabletabcontent').hide();
		$('.scrollabletabcontent:first').show();
		$('.scrollabletab > ul > li:first').addClass('ieTabsActive');
	} else {
		//scrolling tabs
		var $tabs= jQuery('.scrollabletab').tabs().scrollabletab(
			{
				'closable':false, //Default false
				'animationSpeed':50, //Default 100
				'loadLastTab':false, //Default false
				'resizable':false, //Default false
				'resizeHandles':'e,s,se', //Default 'e,s,se'
				'easing':'easeInOutExpo' //Default 'swing'
			});
		//Hack IE
		if($.browser.msie){
			$('.scrollabletab ul li a').hide();
			$('.scrollabletab ul li a').show();
		}
	}
}*/

//fonction move map on mousemove
/*function scrollMap(){	
	var imgMap = new Image();
	imgMap.src = $('#mapPresence .mover img').attr('src');
	var offset = $('#mapPresence .mover').offset();
	var xImg = ($('#mapPresence').css('height').substring(0, ($('#mapPresence').css('height').length)-2)-imgMap.height);
	var yImg = ($('#mapPresence').css('width').substring(0, ($('#mapPresence').css('width').length)-2)-imgMap.width);
	var topMover = Math.round((imgMap.height-($('#mapPresence').css('height').substring(0, ($('#mapPresence').css('height').length)-2)))/($('#mapPresence').css('height').substring(0, ($('#mapPresence').css('height').length)-2))) * (-1);
	var leftMover = Math.round((imgMap.width-($('#mapPresence').css('width').substring(0, ($('#mapPresence').css('width').length)-2)))/($('#mapPresence').css('width').substring(0, ($('#mapPresence').css('width').length)-2))) * (-1);
	$('#mapPresence .mover').css({width: imgMap.width+'px', height: imgMap.height+'px', top: topMover+'px', left: leftMover+'px'});
}*/
