// Parametres défilement
var inc = 300;
var dur = 800;
var resize = 0;

// Initialisation page d'accueil
var iniHome = function(){
	getTwitters('tweet', {
		id: '226551162',
		count: 1,
		enableLinks: true,
		ignoreReplies: true,
		clearContents: true,
		template: '%text%'
	});

	if(!jQuery.browser.msie) {
		$('div.homeFoot a').unbind("mouseover,mouseout").mouseover(function() {
			$(this).children('img').rotate({animateTo:360, duration:500});
		}).mouseout(function() { 
			$(this).children('img').rotate({animateTo:0, duration:500});
		});	
	}

	$.backstretch("img/bg_main.jpg");	
	Grid();
}

// Variables pour le défilement
var GetVariable = function(){
	$entry = $("#entry");
	
	if( $entry.children('.pane1').length == 0 ){	
	
		$pane1 = $('<div class="intro-pane pane1" />').css({backgroundColor: '#d1dc61'}); 
		$pane2 = $('<div class="intro-pane pane2" />').css({backgroundColor: '#c54e56'});
		$pane3 = $('<div class="intro-pane pane3" />').css({backgroundColor: '#000'});
		$preroll = $('#preroll');
		$wrapper = $('#wrapper');
		$body = $('body');
		
		$pane1.prependTo($entry);
		$pane2.prependTo($entry);
		$pane3.prependTo($entry);
	
	}
	
	//alert( $entry.html() );
	
	$winH = $(window).height();	
};

// Défilement vers le bas
var goToRef = function() {
	GetVariable();
	
	$wrapper.css('top',$winH);
	
	var delay = 0;		
			
	$preroll.animate({top:-$winH} ,dur, "easeInExpo" );
	delay += inc;
	$.doTimeout(delay, function(){ $pane1.animate({top: -$winH}, dur, "easeInExpo"); });
	delay += inc;
	$.doTimeout(delay, function(){ $pane2.animate({top: -$winH}, dur, "easeInExpo"); });	

	delay += inc*2;
	$.doTimeout(delay, function(){ 
		$pane3.animate({top: -$winH}, dur, "easeInOutExpo");			
		$("#wrapper").animate({top: 0}, dur, "easeInOutExpo", function(){
			$("#wrapper a").fadeIn();
//			$entry.detach();
			$entry.hide();
			$wrapper.css({overflow: 'auto', height:'auto', position: 'static'});
			$('html, body').scrollTo(0);	
			iniRealisation();
		}); 
	});
};

// Défilement vers le haut - Retour accueil
var goToHome = function(){	

	GetVariable();
	var delay = 0;
	
	closeShadow();
	
	$pane1.css({ top: $winH });
	$pane2.css({ top: $winH });
	$pane3.css({ top: $winH });
	$preroll.css({ top: $winH });
	
//	alert($winH);	
	
	$entry.show();
	
	$pane2.animate({ top: 0}, { duration:dur, easing: "easeInExpo"});

	delay += inc;
	$.doTimeout(delay, function(){ $pane1.animate({top: 0}, { duration:dur, easing: "easeInExpo"}); });
	
	delay += inc*2;
	$.doTimeout(delay, function(){ 
		$wrapper.css({ overflow: 'hidden', height: $winH + 'px', position: 'fixed', top: $winH});
		$pane3.animate({top: 0}, dur, "easeInOutExpo");
		$preroll.animate({top: '0px'}, dur, "easeInOutExpo", function(){
			$("#menu").css('position','absolute');
			$('#menu ul.nav li a').removeClass('selected');
			$('#menu ul.nav li.reference a').addClass('selected');
			$.address.value("");																  
		});
//		ActionHome();
	});
	
	
}



// Affichage de la liste des realisations
var iniRealisation = function(){
	$("#menu").css('position','fixed').css("left","-1px");
	$('.tip').unbind().tipsy({gravity: 'n', fade: true});

	$("#wrapper").css('position','static');
	
	$('li.realisation').unbind().mouseover(function() { 	
		$(this).find("p.hover span").html($(this).find('a').html());
		$(this).find("p.hover").stop(true, true).animate({'bottom':'0px'});
	}).mouseout(function() { 
		$(this).find("p.hover").stop(true, true).animate({'bottom':'-50px'});
	});
	
	$('a#logo').unbind().click(function(e){
		e.preventDefault();
		goToHome();
	});
	
}




/*
var GetPage = function(page){
	alert("GetPage : "+page);
	var vir = page.lastIndexOf(',');
	var pt = page.lastIndexOf('.');
	var nb = page.substring(vir+1,pt);
	
	
	if(isNaN(nb)){
		url = page;
		
	}else{
		url = 'realisation.php';
	}
	
	//Grid();
	
	$("#menu").css('position','fixed');
	
	$.ajax({
		type: "POST",
		data:'act=AJAX&id='+parseInt(nb),
		url: url,
		success: function(retour){
			Shadow(retour);
			return false;
		}
	});
	
	return false;
	
}
*/




