Core = {};

Core.Common = {
	initialize: function(){

		$('#header .content .menu ul li.active').corner("top 5px");
		
		$('#header .content .menu ul li ul li').hover(function(){
			$(this).addClass('on');
			$(this).parent().show();
		}, function(){
			$(this).removeClass('on');
		});
		
		//More links
		$(".link_arrow_more").toggle(function(){
			$(this).addClass('on');
			$(this).next('.block_more').slideDown();
		}, function(){
			$(this).removeClass('on');
			$(this).next('.block_more').slideUp();
		});
		
		$('#header .content .menu ul li.main').hover(function(){
			$(this).addClass('on').corner("top 5px");
			$(this).children('ul').show();
		}, function(){
			$(this).removeClass('on');
			$(this).children('ul').hide();
		});
	},
	homeCarousel: function(){
		
		
		$("#carousel_home_container").css('display','block');
		$("#carousel_home_container").jcarousel({
	        scroll: 1,
			visible: 3,
			start:0,
			auto: 7,
			wrap: 'circular',
			animation: 'slow',
	        initCallback: mycarousel_initCallback,
	        // This tells jCarousel NOT to autobuild prev/next buttons
	        buttonNextHTML: null,
	        buttonPrevHTML: null
	    });
		
		$("#news .content .col_middle").css('display','block');
		
		$("#news .content .col_middle ul").liScroll();
		
	}	
}	

Core.History = {
	initialize: function(){
		$("#carousel_history_container").jcarousel({
	        scroll: 1,
			visible: 1,
			wrap: 'circular',
	        initCallback: mycarousel_initCallback,
	        // This tells jCarousel NOT to autobuild prev/next buttons
	        buttonNextHTML: null,
	        buttonPrevHTML: null
	    });
	

		 $("#carousel_history_container2").jcarousel({
		     scroll: 1,
		 	visible: 2,
		 	wrap: 'circular',
		     initCallback: mycarousel_initCallback2,
		     // This tells jCarousel NOT to autobuild prev/next buttons
		     buttonNextHTML: null,
		     buttonPrevHTML: null
		 });

	},
	zoomIt: function(urlZoom){
		Lightbox.open('/zoom/?src='+encodeURIComponent(urlZoom));
	}
}

Core.Team = {
	initialize: function(){
		$("#top_content_team .content .row .content h2").click(function(){
			
			if($(this).hasClass('on')){
				$("#top_content_team .content .row .content h2").next('ul').hide();
				$(this).removeClass('on');
			}else{
				$("#top_content_team .content .row .content h2").next('ul').hide();
				$("#top_content_team .content .row .content h2").removeClass('on')
				$(this).next('ul').show();
				$(this).addClass('on');
			}
			
		});
	},
	initialize2: function(){
		$("#carousel_management_carousel").jcarousel({
	        scroll: 1,
			visible: 1,
	        initCallback: mycarousel_initCallback,
	        // This tells jCarousel NOT to autobuild prev/next buttons
	        buttonNextHTML: null,
	        buttonPrevHTML: null
	    });
	
		$("#carousel_management_carouse2").jcarousel({
	        scroll: 4,
			visible: 4,
	        initCallback: Core.Team.mycarousel_initCallback2,
	        // This tells jCarousel NOT to autobuild prev/next buttons
	        buttonNextHTML: null,
	        buttonPrevHTML: null
	    });
		
	},
	mycarousel_initCallback2: function(carousel){

	    $('#mycarousel-next2').bind('click', function() {
	        carousel.next();
	        return false;
	    });

	    $('#mycarousel-prev2').bind('click', function() {
	        carousel.prev();
	        return false;
	    });
	}
}

Core.Glossary = {
	initialize: function(){
		$("#definition").simplyScroll({
				className: 'vert',
				horizontal: false,
				frameRate: 50,
				speed: 8
			});

			$('#top_content_glossary .content .col_left .alphabet a').click(function(){
				$('#top_content_glossary .content .col_left .alphabet a').removeClass('on');
				$(this).addClass('on');
			});

		$("#top_content_glossary .content .col_left .item").click(function(){
			$("#top_content_glossary .content .col_left .item").removeClass("on");
			$(this).addClass('on');
			$(".definition").hide();
			$("#"+$(this).attr("id")+"-word").show();
			return false;
		});

		$("#0").trigger('click');
		
		$("#diaporama").diaporama({
	        animationSpeed: "slow",
	        delay:8
	    });
	}
}

Core.References = {
	initialize: function(idmoveto, urlZoom){
		$("#references").simplyScroll({
				className: 'scrollreferences',
				horizontal: false,
				idmoveto: idmoveto
			});		

		$("#top_content_references .content .col_left .item a").click(function(){
			$("#top_content_references .content .col_left .item").removeClass("on");
			$(this).parent().addClass('on');
			//$(".description").hide();
			//$("#"+$(this).attr("id")+"-word").show();
			
			$("#top_content_references .content .col_right").load($(this).attr('href')+'?layout=ajaxlayout&view=referenceajax');
			
		});
		
		$("#carousel_references").jcarousel({
		     scroll: 1,
		 	 visible: 6,
		     initCallback: Core.References.mycarousel_initCallback,
		     // This tells jCarousel NOT to autobuild prev/next buttons
		     buttonNextHTML: null,
		     buttonPrevHTML: null
		 });
		
		$("#top_content_references .content .col_right .description .main .mission .select").toggle(function(){
			$(this).next().show();
			return false;
		},function(){
			$(this).next().hide();
			return false;
		});
		
		$("#top_content_references .content .col_right .description .case-study h2").toggle(function(){
			$(this).addClass('on');
			$(this).next().show();
			return false;
		},function(){
			$(this).removeClass('on');
			$(this).next().hide();
			return false;
		});
		
		Core.References.urlZoom = urlZoom;
	},
	urlGallery: null,
	urlZoom: null,
	changePicture: function(url, urlZoom){
		Core.References.urlZoom = urlZoom;
		Core.References.urlGallery = url;
		$("#picture").attr('src', Core.References.urlGallery);
		
		return false;
	},
	zoomIt: function(){
		

		
	
		
		Lightbox.open('/zoom/?src='+encodeURIComponent(Core.References.urlZoom));
	},
	mycarousel_initCallback: function(carousel){

	    $('#mycarousel-next').bind('click', function() {
	        carousel.next();
	        return false;
	    });

	    $('#mycarousel-prev').bind('click', function() {
	        carousel.prev();
	        return false;
	    });
	},
	ajaxLoad: function(urlZoom){
		$("#carousel_references").jcarousel({
		     scroll: 1,
		 	 visible: 6,
		     initCallback: Core.References.mycarousel_initCallback,
		     // This tells jCarousel NOT to autobuild prev/next buttons
		     buttonNextHTML: null,
		     buttonPrevHTML: null
		 });
		
		$("#top_content_references .content .col_right .description .main .mission .select").toggle(function(){
			$(this).next().show();
			return false;
		},function(){
			$(this).next().hide();
			return false;
		});

		$("#top_content_references .content .col_right .description .case-study h2").toggle(function(){
			$(this).addClass('on');
			$(this).next().show();
			return false;
		},function(){
			$(this).removeClass('on');
			$(this).next().hide();
			return false;
		});

		Core.References.urlZoom = urlZoom;
	}
}

Core.Contact = {
	
	initialize: function(){
		$("#top_content_contact .content .col_left .mission .select").toggle(function(){
			$(this).next().show();
			return false;
		},function(){
			$(this).next().hide();
			return false;
		});
		
		
		
		$("#top_content_contact .content .col_left .mission .box-missions ul li a").click(function(){
			
			city = $(this).attr('class');
			$('.content .city').addClass('hide');
			$('#'+city).removeClass('hide');
			
			
		});
		
		
		
		
		
		
		
	}
	
}

Core.GlossaryWord = {
	initialize: function(idtriggered){
		$("#definition").simplyScroll({
				className: 'vert',
				horizontal: false
			});


		$("#"+idtriggered).addClass('on');
		
		$("#diaporama").diaporama({
	        animationSpeed: "slow",
	        delay:8
	    });
	}
}

Core.Booklet = {
	initialize: function(){
		$('#booklet-form').validate({
			messages: {
				email: 'Ce champ est obligatoire',
				lastname: 'Ce champ est obligatoire',
				company: 'Ce champ est obligatoire'
			}
		});		
	}
}

Core.Recrutment = {
	initialize: function(){
		$("#top_content_recrutment .content .col_right ul li").hover(function(){
			$(this).addClass('on');
		},function(){
			$(this).removeClass('on');
		})
		
		
	},
	vacanciesInitialize: function(){
		$("#top_content_recrutment .content .col_left h2").click(function(){
			
			if($(this).hasClass('on')){
				$("#top_content_recrutment .content .col_left h2").next('ul').hide();
				$(this).removeClass('on');
			}else{
				$("#top_content_recrutment .content .col_left h2").next('ul').hide();
				$("#top_content_recrutment .content .col_left h2").removeClass('on')
				$(this).next('ul').show();
				$(this).addClass('on');
			}
			
		});
	},
	applyInitialize: function(){
		$("#top_content_recrutment_apply .content .col_left form .files .attach").click(function(){
			$(this).next().show();
		});
		
		$("#top_content_recrutment_apply .content .col_left form .select").toggle(function(){
			$(this).next().show();
			return false;
		},function(){
			$(this).next().hide();
			return false;
		});
		
		$("#top_content_recrutment_apply .content .col_left form input[name=position]").click(function(){
			$("#top_content_recrutment_apply .content .col_left form .select").trigger('click');
		});
		
	}
	
}

Core.Methodology = {
	firstLoad: true,
	currentItem: 0,
	profession: null,
	nbItem: 0,
	last: false,
	carousel: null,
	initialize: function(nbItem){
		Core.Methodology.nbItem = nbItem;	
		$("#carousel_methodology").jcarousel({
		     scroll: 1,
		 	 visible: 7,
		     initCallback: Core.Methodology.mycarousel_initCallback_methodology,
		     // This tells jCarousel NOT to autobuild prev/next buttons
		     buttonNextHTML: null,
		     buttonPrevHTML: null,
			 itemLoadCallback: {
			 	onBeforeAnimation: Core.Methodology.callback1,
			 	onAfterAnimation: Core.Methodology.callback2
			}
		 });
		
		
		$(".jcarousel-control a").click(function(){
			$("#top_content_methodology_occupant .content .row .menu ul li").removeClass('on');
			$(this).parent().addClass('on');
		});
		
		$("#top_content_methodology_occupant .content .row .submenu ul li").click(function(){
			Core.Methodology.selectItem($(this).attr('id'));

			Core.Methodology.carousel.scroll(jQuery.jcarousel.intval(Core.Methodology.cursor_begin));

			if(Core.Methodology.nbItem == Core.Methodology.currentItem && Core.Methodology.last == false){
				Core.Methodology.last = true;
				$("#top_content_methodology_occupant .content .row .submenu ul").animate({left: '-=50'},100, function() {});
			}else if(Core.Methodology.nbItem != Core.Methodology.currentItem && Core.Methodology.last == true){
				Core.Methodology.last = false;
				$("#top_content_methodology_occupant .content .row .submenu ul").animate({left: '+=50'},100, function() {});
			}
		});
		
		
	},
	callback1: function(carousel){
		if(Core.Methodology.firstLoad == false)
		{
			Core.Methodology.selectItem($("#top_content_methodology_occupant .content .row .submenu ul").children().eq(Core.Methodology.currentItem).attr('id'));
		}
	},
	callback2: function(carousel){
		if(Core.Methodology.firstLoad == true)
		{
			Core.Methodology.firstLoad = false;
			if($.address.value() != '/'){
				$("#"+$.address.value()+"-trigger").trigger('click');
			}else{
				$("#0-item").fadeIn();
			}	
		}
		
	},
	mycarousel_initCallback_methodology: function(carousel){
		
		Core.Methodology.carousel = carousel;
		
		$('.jcarousel-control a').bind('click', function() {
			Core.Methodology.currentItem = jQuery(this).attr('rel');

	        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('rel')));
	
			if(Core.Methodology.nbItem == Core.Methodology.currentItem && Core.Methodology.last == false){
				Core.Methodology.last = true;
				$("#top_content_methodology_occupant .content .row .submenu ul").animate({left: '-=50'},100, function() {});
			}else if(Core.Methodology.nbItem != Core.Methodology.currentItem && Core.Methodology.last == true){
				Core.Methodology.last = false;
				$("#top_content_methodology_occupant .content .row .submenu ul").animate({left: '+=50'},100, function() {});
			}
			
	        return false;
	    });

	    $('.jcarousel-scroll select').bind('change', function() {
	        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
	        return false;
	    });

	    $('#mycarousel-next').bind('click', function() {
	        carousel.next();
	        return false;
	    });

	    $('#mycarousel-prev').bind('click', function() {
	        carousel.prev();
	        return false;
	    });
	},
	selectItem: function(itemId){
		var classArray = itemId.split('-');
		Core.Methodology.profession = classArray[1];
		Core.Methodology.currentItem = classArray[0];
		
		$("#top_content_methodology_occupant .content .row .menu ul li").removeClass('on');
		$("#top_content_methodology_occupant .content .row .menu ul li."+Core.Methodology.profession).addClass('on');
		
		$("#top_content_methodology_occupant .content .row .submenu ul li").removeClass('lwrw')
																			.removeClass('lwro')
																			.removeClass('loro')
																			.removeClass('lbrw')
																			.removeClass('lwrb')
																			.removeClass('lorb')
																			.removeClass('lbro')
																			.removeClass('lorw').addClass('lbrb');

		var cursor = 0; var classArrayTemp = ''; var cursorOn = 0; var classOn = false; Core.Methodology.cursor_begin = null;
		$("#top_content_methodology_occupant .content .row .submenu ul").children().each(function(e){
			var thisDom = $(this);			
			
			if(thisDom.hasClass(Core.Methodology.profession))
			{
				if(Core.Methodology.cursor_begin == null)
					Core.Methodology.cursor_begin = cursor;
					
				classOn = true;
				if(cursor == Core.Methodology.currentItem){
					if(cursor == 0)
						thisDom.addClass('lwrw');
					else if(cursorOn == 0){
						thisDom.addClass('lbrw');
					}else{
						thisDom.addClass('lorw');
					}
				}else{
					if(cursor == parseInt(Core.Methodology.currentItem)+1){
						thisDom.addClass('lwro');
					}else{
						if(cursorOn == 0){
							thisDom.addClass('lbro');
						}else{
							thisDom.addClass('loro');
						}
					}
				}
				cursorOn = cursorOn + 1;
			}else{
				if(classOn == true){
					if(cursor == parseInt(Core.Methodology.currentItem)+1)
						thisDom.addClass('lwrb');
					else
						thisDom.addClass('lorb');
				}else
					thisDom.addClass('lbrb');
				classOn = false;
			}
			
			cursor = cursor + 1;
		});
		
		$("#top_content_methodology_occupant .content .row .delieverable .item").hide(0, function(){
			$("#"+Core.Methodology.currentItem+"-item").show();
		});
		
		
	}
}

Core.MethodologyInvestor = {
	firstLoad: true,
	currentItem: 0,
	profession: null,
	initialize: function(profession){
		
		
		$("#top_content_methodology_investor .content .row .submenu ul li").click(function(){
			Core.MethodologyInvestor.selectItem($(this).attr('id'));
		});
		
		if($.address.value() != '/')
			$("#"+$.address.value()+"-trigger").trigger('click');
		else
			Core.MethodologyInvestor.selectItem('0-'+profession);
			
		$(".jcarousel-control li").click(function(){
			$("#"+$(this).children("a").attr("rel")).trigger('click');
		});
	},
	selectItem: function(itemId){

		var classArray = itemId.split('-');
		Core.MethodologyInvestor.profession = classArray[1];
		Core.MethodologyInvestor.currentItem = classArray[0];

		$("#top_content_methodology_investor .content .row .menu ul li").removeClass('on');
		$("#top_content_methodology_investor .content .row .menu ul li."+Core.MethodologyInvestor.profession).addClass('on');

		$("#top_content_methodology_investor .content .row .submenu ul li").removeClass('w')
																			.removeClass('b')
																			.removeClass('o').addClass('b');

		var cursor = 0; var classArrayTemp = ''; var cursorOn = 0; var classOn = false;
		$("#top_content_methodology_investor .content .row .submenu ul").children().each(function(e){
			var thisDom = $(this);			

			if(thisDom.hasClass(Core.MethodologyInvestor.profession))
			{
				if(cursor == Core.MethodologyInvestor.currentItem){
					thisDom.addClass('w');
				}else{
					thisDom.addClass('o');
				}
			}else{
				thisDom.addClass('b');
			}
			
			cursor = cursor + 1;
		});		
		
		
		$("#top_content_methodology_investor .content .row .delieverable .item").hide(0, function(){
			$("#"+Core.MethodologyInvestor.currentItem+"-item").show();
		});		
	}
}


$().ready(function() {
	Core.Common.initialize();
});


/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
function mycarousel_initCallback(carousel) {
    $('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('rel')));
        return false;
    });
 
    $('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });
 
    $('#mycarousel-next').bind('click', function() {
		//$.sound.play('/wav/click.wav');
        carousel.next();
        return false;
    });
 
    $('#mycarousel-prev').bind('click', function() {
		//$.sound.play('/wav/click.wav');
        carousel.prev();
        return false;
    });
};

/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
function mycarousel_initCallback2(carousel) {
    $('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('rel')));
        return false;
    });
 
    $('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });
 
    $('#mycarousel-next2').bind('click', function() {
        carousel.next();
        return false;
    });
 
    $('#mycarousel-prev2').bind('click', function() {
        carousel.prev();
        return false;
    });
};




