//
// Initial load animation.
//

function runLoadAnimations() {
	animateInitialMenu();
	animateListMenu();
	animateListLang();
	animateListSociaux();
}

function animateInitialMenu() {
	var debug = false;
	if (debug) {
		$('#page').css('margin-left', '0');
		$('#content').show();
		$('#sidleeTv').show().css('left', '-45px');
		animatingPage = false;
		return;
	}
	
	// Freeze all behaviors (hover, click) until animations are done.
	animatingPage = true;
	$('#page').delay(500).animate({'margin-left': "0"}, 400, function() {
		resizeContentBackground();
		//set
		//$('#sidleeTvClosed,.tvIcon').hide();
		$('#content').delay(400).fadeIn(600, function() {
		    // Replace adel's and nic's code below
		    $('#sidleeTv').show().delay(400).animate({'left': "-45px"}, 600, function() {
				sidleetv.closedToPreview(function(){
				    sidleetv.previewToClosed();
					
					//TODO - use callback to set 'animating' flag after preview closed.
					// Animations are finished, enable behaviors.
					animatingPage = false;
				});
			});

		});
	});
}

//-----------------------------------------
function animateListMenu()
{
	$($('#mainMenu li').get().reverse()).each(function(index,elm){
		//console.log(elm.id+ 'index' + index);
		$(this).find('a').delay(100*index).animate({'top':0},1000,'easeInOutExpo',function(){
			$(this).animate({'color':'#F8F8F8'},'slow').removeClass('opac');
			$(this).next().animate({'paddingRight':190},'slow','easeInOutExpo');
		});	
	});
}

function animateListLang()
{
	$($('#language a').get()).each(function(index,elm){
		$(this).find('img').delay(300*index).animate({'top':0},1000,'easeInOutExpo',function(){});	
	});
}

function animateListSociaux()
{
	$($('.contentIcoSocial').get()).each(function(index,elm){
		$(this).find('a').delay(300*index).animate({'left':15},1000,'easeInOutExpo',function(){});	
	});
}


