$(document).ready(function(){
					
		/***************************/
		/* Taget _blank W3C valide */	
		/***************************/
		$(".targetBlank").click(function(){
			lien = $(this).attr('href');
			window.open(lien, '_blank');
			return false;
		})		
		/*******************/
		/* SET BODY HEIGHT */	
		/*******************/
		var resetHeight = function(e){
			$("#wrapper").css("height","100px"); 
			//alert($("body").height())
		}

		/********************************/
		/* WEBSITE add2cart CONSTRUCTOR */	
		/********************************/
		$(".portfolioSource > div > img").click(function(){
			//$('#items').html('<img src="images/ajax-loader.gif" width="220" height="19" class="loader" />');
			var project = $(this).parent().attr('id').substr(0,9)
			$.add2cart(project, 'cart', showProject);
		})
		
		var showProject = function(){
			$(this).hide()
			var project = $(this).attr('id').substr(0,9);
			$('#items').load("projets/"+project+".html", function() {
				//$('#footer').animate({ top: ($('#header').height()+135+$('#sitesweb').height()),}, 300, "jswing")
			});
			
		}
		
		/*******************/
		/* MAIN MENU SETUP */	
		/*******************/
		var resetMenu = function(e){
			$("#nav ul li a").each(function(i){
				$(this).removeClass('cat_active');
			})
		}
		var resetMenuLevel2 = function(e){
			$("#nav ul.nav_level2 li a").each(function(i){
				$(this).removeClass('cat_active');
			})
		}

		//---INIT MENU
		//$("#nav ul li:first > a").addClass('cat_active');
		//$("#nav ul li:first .nav_level2").slideDown(300, function(){$("#menu1").next().children().children(':first').addClass('cat_active')})
		
		//---MENU LEVEL2 HIGHLIGHT
		$("#nav ul.nav_level2 li a").click(function(e){
			resetMenuLevel2();
			$(this).addClass('cat_active');
		})
		//---MENU LEVEL1 HIGHLIGHT
		$("#nav > ul > li > a").click(function(e){
			var $menu = $(this);
			resetMenu();
			$(this).addClass('cat_active');
			$("#nav ul.nav_level2").slideUp(300)
			$menu.parent().children().slideDown(350);
			if(e.target.id == 'menu1'){
				$(this).parent().children().children().children().eq(0).addClass('cat_active');
				$('#header').html('')
				$('#header').flash({ src: 'swf/presentation.swf', width: 742, height: 183, wmode: 'transparent'},{version: 6 });
			}
			if(e.target.id == 'menu2'){
				$(this).parent().children().children().children().eq(1).addClass('cat_active');
				$('#header').html('')
				$('#header').flash({ src: 'swf/sitesweb.swf', width: 742, height: 183, wmode: 'transparent'},{version: 6 });
			}
			if(e.target.id == 'menu3'){
				$(this).parent().children().children().children().eq(2).addClass('cat_active');
				$('#header').html('')
				$('#header').flash({ src: 'swf/clients.swf', width: 742, height: 183, wmode: 'transparent'},{version: 6 });
			}
			if(e.target.id == 'menu4'){
				$(this).parent().children().children().children().eq(1).addClass('cat_active');
				$('#header').html('')
				$('#header').flash({ src: 'swf/contact.swf', width: 742, height: 183, wmode: 'transparent'},{version: 6 });
			}
		});

		$("#nav > ul > li > ul > li > a").click(function(e){
			pageId = e.target.hash;
			page = e.target.hash.substr(1);
			//header manager
			$('#header').html('')
			$('#header').flash({ src: 'swf/'+page+'.swf', width: 742, height: 183, wmode: 'transparent'},{version: 6 });
		});

		/*FOR TEXT-LINK*/
		$("a.intern").click(function(e){
			var hash = e.target.hash.substr(0,1);
			if(hash=="#"){
				pageId = e.target.hash;
				page = e.target.hash.substr(1);
				//Menu manager
				resetMenu()
				resetMenuLevel2();
				$("#nav ul.nav_level2").slideUp(400)
				$("#menu-"+page).parent().parent().parent().children().slideDown(400);
				$("#menu-"+page).parent().parent().parent().children('a').addClass('cat_active');
				$("#menu-"+page).addClass('cat_active');
	
				//header manager
				$('#header').html('')
				$('#header').flash({ src: 'swf/'+page+'.swf', width: 742, height: 183, wmode: 'transparent'},{version: 6 });
			}
			return false;
		});
		
		$(".goTo").click(function(e){
			pageId = $(this).attr('href');
			page = pageId.substr(1);
			//Menu manager
			resetMenu()
			resetMenuLevel2();
			$("#nav ul.nav_level2").slideUp(400)
			$("#menu-"+page).parent().parent().parent().children().slideDown(400);
			$("#menu-"+page).parent().parent().parent().children('a').addClass('cat_active');
			$("#menu-"+page).addClass('cat_active');
			//header manager
			$('#header').html('')
			$('#header').flash({ src: 'swf/'+page+'.swf', width: 742, height: 183, wmode: 'transparent'},{version: 6 });
			return false;
		})
		
		/*********************/
		/* FORM INPUT SPRITE */	
		/*********************/
		$("#form_contact input[type!='submit']").each(function(){
			if(this.value!=''){
				$(this).css('background-position','0 -34px');
			}
			$(this).focus(function(){
				$(this).css('background-position','0 -34px');
			}).blur(function(){
				if(this.value==''){
					$(this).css('backgroundPosition','0 0');
				}
			});
    	});
		$("#form_contact textarea").each(function(){
			if(this.value!=''){
				$(this).css('background-position','0 -90px');
			}
			$(this).focus(function(){
				$(this).css('background-position','0 -90px');
			}).blur(function(){
				if(this.value==''){
					$(this).css('backgroundPosition','0 0');
				}
			});
    	});
		
		/*************/
		/* TABS - CV */	
		/*************/
		$("#explore-nav li a").click(function() {
				// Figure out current list via CSS class
				var curList = $("#explore-nav li a.current").attr("rel");
				// List moving to
				var $newList = $(this);
				// Set outer wrapper height to height of current inner list
				var curListHeight = $("#all-list-wrap").height();
				$("#all-list-wrap").height(curListHeight);
				// Remove highlighting - Add to just-clicked tab
				$("#explore-nav li a").removeClass("current");
				$newList.addClass("current");
				// Figure out ID of new list
				var listID = $newList.attr("rel");
				if (listID != curList) {
					// Fade out current list
					$("#"+curList).fadeOut(150, function() {
						// Fade in new list on callback
						$("#"+listID).fadeIn();
						// Adjust outer wrapper to fit new list snuggly
						var newHeight = $("#"+listID).height();
						$("#all-list-wrap").animate({
							height: newHeight
						});
					});
				}
				// Don't behave like a regular link
				return false;
			});
		/***************/
		/* MAIN SLIDER */
		/***************/
		var $panels = $('#wrapper .scrollContainer > div');
		var $container = $('#wrapper .scrollContainer');
		// if false, we'll float all the panels left and fix the width 
		// of the container
		var horizontal = true;
		
		// float the panels left if we're going horizontal
		if (horizontal) {
		  $panels.css({
			'float' : 'left',
			'position' : 'relative' // IE fix to ensure overflow is hidden
		  });
		  
		  // calculate a new width for the container (so it holds all panels)
		  $container.css('width', $panels[0].offsetWidth * $panels.length);
		}
		// collect the scroll object, at the same time apply the hidden overflow
		// to remove the default scrollbars that will appear
		var $scroll = $('#wrapper .scroll').css('overflow', 'hidden');
		// apply our left + right buttons
		/*
		$scroll
		  .before('<img class="scrollButtons left" src="images/scroll_left.png" />')
		  .after('<img class="scrollButtons right" src="images/scroll_right.png" />');
		*/
		// handle nav selection
		function selectNav() {
		/*
		  $(this)
			.parents('ul:first')
			  .find('a')
				.removeClass('selected')
			  .end()
			.end()
			.addClass('selected');
		*/
		}
		//$('#wrapper #nav').find('a').click(selectNav);
		// go find the navigation link that has this target and select the nav
		function trigger(data) {
		  var el = $('#wrapper #nav').find('a[href$="' + data.id + '"]').get(0);
		  selectNav.call(el);
		}
		function goToTop() {
			$( 'html, body' ).animate( { scrollTop: 0 }, 222 );
		}
		if (window.location.hash) {
		  trigger({ id : window.location.hash.substr(1) });
		} else {
		  $('div#nav a:first').click();
		}
		// offset is used to move to *exactly* the right place, since I'm using
		// padding on my example, I need to subtract the amount of padding to
		// the offset.  Try removing this to get a good idea of the effect
		var offset = parseInt((horizontal ? $container.css('paddingTop') : $container.css('paddingLeft')) || 0) * -1;
		var offset = -1;
		
		var scrollOptions = {
		  target: $scroll, // the element that has the overflow
		  // can be a selector which will be relative to the target
		  start:2,
		  items: $panels,
		  navigation: '#nav a',
		  // selectors are NOT relative to document, i.e. make sure they're unique
		  /*
		  prev: 'img.left', 
		  next: 'img.right',
		  */
		  // allow the scroll effect to run both directions
		  axis: 'xy',
		  onBefore:goToTop,
		  onAfter: trigger, // our final callback
		  offset: offset,
		  // duration of the sliding effect
		  duration: 666,
		  // easing - can be used with the easing plugin: 
		  // http://gsgd.co.uk/sandbox/jquery/easing/
		  easing: 'easeInBack'
		};
		
		scrollOptions.start = 1;
		$('#wrapper').serialScroll(scrollOptions);
		// apply serialScroll to the slider - we chose this plugin because it 
		// supports// the indexed next and previous scroll along with hooking 
		// in to our navigation.
		

		// now apply localScroll to hook any other arbitrary links to trigger 
		// the effect
		/*
		var haut = $('#header').height()+122+$(window.location.hash).height();
		alert(window.location.hash)
		alert(haut)
		*/
		$.localScroll(scrollOptions)
		// finally, if the URL has a hash, move the slider in to position, 
		// setting the duration to 1 because I don't want it to scroll in the
		// very first page load.  We don't always need this, but it ensures
		// the positioning is absolutely spot on when the pages loads.
		/*
		scrollOptions.duration = 1;
		$.localScroll.hash(scrollOptions);
		*/
		/****************************/
		/*FLASH MODAL BANNER PARAMS */
		/****************************/
		$('#yack4 a.nyroModal').nyroModal({width: 720, height: 200});
		$('#yack3 a.nyroModal').nyroModal({width: 720, height: 200});
		$('#yack2 a.nyroModal').nyroModal({width: 720, height: 200});
		$('#yack1 a.nyroModal').nyroModal({width: 728, height: 90});
		$('#lib9 a.nyroModal').nyroModal({width: 160, height: 598});
		$('#lib7 a.nyroModal').nyroModal({width: 385, height: 95});
		$('#lib1 a.nyroModal').nyroModal({width: 600, height: 250});
		$('#lib2 a.nyroModal').nyroModal({width: 183, height: 150});
		$('#lib3 a.nyroModal').nyroModal({width: 190, height: 125});
		$('#lib4 a.nyroModal').nyroModal({width: 250, height: 250});
		$('#lib5 a.nyroModal').nyroModal({width: 250, height: 250});
		$('#lib6 a.nyroModal').nyroModal({width: 385, height: 95});
		$('#lib8 a.nyroModal').nyroModal({width: 385, height: 95});
		$('#animADLE a.nyroModal').nyroModal({width: 640, height: 480});
	
		//RANDOM RENDERING FOR .portfolioSource
		var elements_a_melanger = $('.portfolioSource').children();
		elements_a_melanger.sort(function() { return Math.random() - 0.5;}).parent().append(elements_a_melanger);
		$.add2cart($(".portfolioSource > div:first").attr('id').substr(0,9), 'cart', showProject);
		
		//HEIGHT EQUALIZER
		setHeight('.presentatonStyle')
});

//
var showProject = function(){
	$(this).hide()
	var project = $(this).attr('id').substr(0,9);
	$('#items').load("projets/"+project+".html", function() {
		//$('#footer').animate({ top: ($('#header').height()+135+$('#sitesweb').height()),}, 300, "jswing")
	});
	
}

var maxHeight = 0;
function setHeight(col) {
	col = $(col);
	col.each(function() {
		if($(this).height() > maxHeight) {
			maxHeight = $(this).height();
		}
	});
	col.height(maxHeight);
}
