
/*======================================================
 
					Document Ready
 
======================================================*/
var currentURL;
var nextPageIndex;

$(document).ready(function() {
	
	// Definit index du projet courant pour recuperer le prochain dans le tableau des  -> getNextProject()
	
	currentURL=window.location;
	for (i=0;i<projects.length;i++) {
		var testURL='http://frederictacer.net/projects/'+projects[i];
		var testURL2='http://www.frederictacer.net/projects/'+projects[i];
		if(currentURL==testURL||currentURL==testURL2) {
			nextPageIndex=i+1;
			if(nextPageIndex==projects.length) {
				nextPageIndex=0;
			}
		}
	}
	
	// Roll Over StudioFredTacer / Index
	
	$("#studio").mouseenter(
		function () {
		   $(this).addClass("invisible");
		   $("#studioHover").removeClass("invisible");
		}
	);
	$("#studioHover").mouseleave(
		function () {
		   $(this).addClass("invisible");
		   $("#studio").removeClass("invisible");
		}
	);

	// Roll Over sur projet Homepage-Archive
	
	$("#projectsRoll img, #isotopeContainer img").each(function () {
		$(this).hover(
			function () {
				$('#random').addClass("invisible");
				$('#imgHover').removeClass("invisible");
				var txt=$(this).next().html();
				$('#imgHover').html(txt);  
			}, 
			function () {
				$('#random').removeClass("invisible");
				$('#imgHover').addClass("invisible");
			}
		);
    });
	
	// Apercu pubications
	
	var cursorX;
	var posY;
	
	$(".imgOverlay").each(function () {
		$(this).hover(
			function () {
				$(this).css({'text-decoration':'underline'});
				var offset=$(this).offset();
				posY=offset.top+20;
				$(document).mousemove(function(e){
					cursorX=e.pageX+20;
					var cursorXrelative=cursorX-$(window).scrollLeft();
					if (cursorXrelative+$('#overlay').width()>$(window).width()) {
						cursorX-=$('#overlay').width()+40;
					}
					$('#overlay').css ({'left':cursorX,'top':posY});
				});
				var visu='<img src=\"'+$(this).find('img').attr('src')+'\">';
				$('#overlay').html(visu);
			}, 
			function () {
				$('#overlay').html('');
				$(document).mousemove(function(e){});
				$(this).css({'text-decoration':'none'});
			}
		);
    });
	
});

/*======================================================
 
				Chargement AJAX d'un slider
 
======================================================*/

function loadSlider (adresse,container) {
	
	// scroll pour caler projet au bord gauche de la fentre

	var posLeft=$(container).offset().left-30;
	$('html, body').stop().animate({scrollLeft: posLeft},500,function(){request();});
	
	// modifie la fenetre de projet

	$(container).animate({width:780,height:580},500);
	$(container).children().animate({opacity:0},500,function(){$(container).children().remove();});

	// gre la taille wrapper projets
	
	var tailleOrigine=$(container).width();
	var difference=(780-tailleOrigine);
	$('#projectsRoll').width(difference+$('#projectsRoll').width());
	
	// retablit RANDOM
	
	$('#random').removeClass("invisible");
	$('#imgHover').addClass("invisible");

	// ajax le slider
	
	function request () {
		$(container).css({'background':'url(css/images/ajax-loader.gif) no-repeat center'})
		$.ajax({
			url:adresse,
			success: function(data) {
				$(container).html(data);
				initSlider(container,true);
			},
			error: function() {
				alert('La requte a ŽchouŽ...');
			}
		});
	}
}

/*======================================================
 
				Random Project
 
======================================================*/

var projects=new Array (
	'2011/pointephemereguide.php',
	'2011/unknownpleasures.php',
	'2011/publicspace.php',
	'2011/lafabrique.php',
	'2011/musiccovers.php',
	'2011/modeetsens.php',
	'2011/burger.php',
	'2011/petitbain.php',
	'2011/takaaaki.php',
	'2011/petitesformes.php',
	'2011/penrose.php',
	'2011/reasemotion.php',
	'2011/raybartokwebsite.php',
	'2011/lacostelive.php',
	'2011/etaumilieu.php',
	'2011/silanewebsite.php',
	'2011/pointephemere.php',
	'2010/opentexts.php',
	'2010/lafabrique.php',
	'2010/stars.php',
	'2010/biennalecatalogue.php',
	'2010/apesdidensemble.php',
	'2010/festindacier.php',
	'2010/typolyrics.php',
	'2010/neurochemie.php',
	'2010/sentimentale.php',
	'2010/juno.php',
	'2009/nopanic.php',
	'2009/ink4.php',
	'2009/icaclassics.php',
	'2009/icaposters.php',
	'2009/icaguide.php',
	'2009/ica.php',
	'2009/cooc.php',
	'2009/danceschool.php',
	'2009/austerlitz.php',
	'2008/gordan.php',
	'2008/guidearchitecture.php',
	'2008/bartok.php',
	'2008/diploma-interface.php',
	'2008/diploma-tactile.php',
	'2008/diploma-ecover.php',
	'2008/diploma-interactivewall.php',
	'2008/raybartok.php',
	'2008/exhaustion.php',
	'2007/globalwarming.php',
	'2007/catoblepas.php',
	'2007/handicap.php'
)

function getRandomProject () {
	var select=Math.round(Math.random()*(projects.length-1));
	var randomURL='http://www.frederictacer.net/projects/'+projects[select];
	if (randomURL==currentURL){
		getRandomUrl();
	}else{
		window.location.href=randomURL;
	}
}

/*======================================================
 
				Scroll Back Home
 
======================================================*/

function scrollBackHome () {
	$('html, body').animate({scrollLeft: 0},1000);
}

/*======================================================
 
				Get Next Project
 
======================================================*/

function getNextProject() {
	window.location.href='http://www.frederictacer.net/projects/'+projects[nextPageIndex];
}

/*======================================================
 
				Slide Share Buttons
 
======================================================*/

function openShareLinks() {
	if ($('#links').css('opacity')==0) {
		$('#links').css({'visibility':'visible'})
		$('#links').animate({'opacity':1},400);
		$('#shareBt').text('Close');
		$('#shareBt').css({'text-decoration':'underline'});
	}else {
		$('#shareBt').text('Share');
		$('#shareBt').css({'text-decoration':'none'});
		$('#links').animate(
			{'opacity':0},
			400,
			function() {
				$('#links').css({'visibility':'hidden'})
			}
		);
	}
}
