﻿/*
	\\\\---------------------------------------------
	//// 	Default javascript SHARED functions based on jquery
	\\\\ 	2008 © Coded by : Damien Virot - Sogoa
	////---------------------------------------------
*/


jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.07
		}, settings);		
		return this.each(function(){
				var $strip = jQuery(this);
				$strip.addClass("newsticker")
				var stripWidth = 0;
				var $mask = $strip.wrap("<div class='mask'></div>");
				var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
				var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
				$strip.find("li").each(function(i){
				stripWidth += jQuery(this, i).width();
				});
				$strip.width(stripWidth);			
				var defTiming = stripWidth/settings.travelocity;
				var totalTravel = stripWidth+containerWidth;								
				function scrollnews(spazio, tempo){
				$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				scrollnews(totalTravel, defTiming);				
				$strip.hover(function(){
				jQuery(this).stop();
				},
				function(){
				var offset = jQuery(this).offset();
				var residualSpace = offset.left + stripWidth;
				var residualTime = residualSpace/settings.travelocity;
				scrollnews(residualSpace, residualTime);
				});			
		});	
};


// Put all your code in your document ready area
jQuery(document).ready(function($){

	$('#main-menu a').hover( function() {
		if ($(this).hasClass("m1")) { 
			$(this).animate({backgroundColor:'#92117E'},400);
			$('.first').animate({backgroundColor:'#92117E'},400);
		}
		if ($(this).hasClass("m2") || $(this).hasClass("m3")) { 
			$(this).animate({backgroundColor:'#92117E'},400);
		}
		if ($(this).hasClass("m4")) { 
			$(this).animate({backgroundColor:'#DB0720'},400);
			$('#main-menu').animate({backgroundColor:'#DB0720'},400);
		}
	},function() {
		$(this).animate({backgroundColor:'#C280B0'},300);
		if ($(this).hasClass("m1")) { $('.first').animate({backgroundColor:'#C280B0'},300); }
		if ($(this).hasClass("m4")) { $('#main-menu').animate({backgroundColor:'#C280B0'},300); }
	});
	
	/*$('#main-menu a').hover( function() {
		$('#section-introduction .container').hide();
		$('#'+$(this).attr('rel')).show();
	},function() {
		$('#'+$(this).attr('rel')).hide();
		$('#section-introduction .container').show();
	});*/
	
	$('#main-menu a').hover( function() {
		$('.logo-intro:eq(0)').css('height','1px');
		$('#'+$(this).attr('rel')).show();
	},function() {
		$('#'+$(this).attr('rel')).hide();
		$('.logo-intro:eq(0)').css('height','150px');
	});
	
	$('#main-menu a').each( function() {
		if($('#intro-logo').size()>0 && $(this).hasClass('sct'+$('#intro-logo').metadata().sct)) {
			if ($(this).hasClass("m1")) { 
				$(this).css({backgroundColor:'#92117E'});
				$('.first').css({backgroundColor:'#92117E'});
			}
			if ($(this).hasClass("m2") || $(this).hasClass("m3")) { 
				$(this).css({backgroundColor:'#92117E'});
			}
			if ($(this).hasClass("m4")) { 
				$(this).css({backgroundColor:'#DB0720'});
				$('#main-menu').css({backgroundColor:'#DB0720'});
			}
		}
	});
	
	if($('#bottom-menu a').size()==1) {
		$('#bottom-menu a').hide();
	}
	
	$('.mainbottom').each( function() {
		$('a:eq(0)',this).addClass('on');
	});
	
	$('img.backme').each( function() {
		var url = $(this).attr('src');
		$(this).hide();
		$(this).parent().css({backgroundImage:'url('+url+')',backgroundRepeat:'no-repeat',backgroundPosition:'right bottom'});
	});
	
	/*$('#submenu a').hoverIntent( function() {
		$('#photo-unik img').hide();
		$('img.'+$(this).attr('rel')).show();
	},function() {
		//$('img.first').show();
		//$('#photo-unik .abs').fadeOut();
	});
	
	$('.pager a').click( function() {
		var myparent = $(this).parent().parent();
		myparent.find('.pager a').css('background','none');
		var eqn = new Number($(this).text())-1;
		myparent.find('.pages:visible').fadeOut(500, function() {
			myparent.find('.pages:eq('+eqn+')').fadeIn();
		});
		myparent.find('.pager a:eq('+eqn+')').css('background-color','#CCCCCC');
	});*/
	
	$('.pager a, .pagerimgs a').click( function() {
		var eqn = new Number($('.allpages .pages').size()-1);
		if($(this).attr('rel')=="prev") {
			$('.pages:visible').hide().prev('.pages').show();
			if($('.pages:visible').metadata().poz<eqn) { $(this).next('a').show(); }
			if($('.pages:visible').metadata().poz==0) { $(this).hide(); }
		}
		if($(this).attr('rel')=="next") {
			$('.pages:visible').hide().next('.pages').show();
			if($('.pages:visible').metadata().poz>0) { $(this).prev('a').show(); }
			if($('.pages:visible').metadata().poz==eqn) { $(this).hide(); }
		}
	});

	if($('#relative2').size()>0) {
		$('#reftitle').html('<a href="#" style="display:block;color:#000000;font-size:9px;font-weight:normal;"><span>références suivantes >>></span><span style="display:none;"><<< références précédentes</span></a>');
		$('#reftitle a').click( function() {
			$('#relative1,#relative2,#reftitle a span').toggle();
		});
	}

	var myrefs = new Number($('.refs a').size());
	if(myrefs>0) {
		
		var multitop = 0;
		var j = 0;
		var ctrlend = myrefs-1;
		for(i=0;i<myrefs;i++) {
			//if(j==4) { var multitop = multitop+1; var j = 0; }
			var what = i+1; //var lft = 110*j; var tp = 110*multitop;
			$('.ref'+what).fadeIn({duration: 200, queue: "global"});
			//var j = j+1;
		}
	}
	
	$('.refs .photo .relative a').hoverIntent( function() {
		$(this).css('z-index','2').animate({backgroundColor:'#000000'},200);
		$('#reftitle').css({borderBottom:'1px #000 solid',height:'19px'}).text($('img',this).attr('alt')+$('img',this).metadata().data);
	}, function() {
		$(this).animate({backgroundColor:'#D6BEBE'},200);
		$('.refs .photo .relative a').css('z-index','1');
		$('#reftitle').css({border:'none',height:'20px'}).text(' ');
		if($('#relative2').size()>0) {
			if($('#relative2:visible').size()>0) {
				$('#reftitle').html('<a href="#" style="display:block;color:#000000;font-size:9px;font-weight:normal;"><span style="display:none;">références suivantes >>></span><span><<< références précédentes</span></a>');
			}else{
				$('#reftitle').html('<a href="#" style="display:block;color:#000000;font-size:9px;font-weight:normal;"><span>références suivantes >>></span><span style="display:none;"><<< références précédentes</span></a>');
			}
			$('#reftitle a').click( function() {
				$('#relative1,#relative2,#reftitle a span').toggle();
			});
		}
	});
	
	$('#data-unik-histoire .allpages').css('height','350px');
	
	$('.refs .photo .relative a').click( function() {
		$('#data-unik-references').append('<div id="infosref" class="spaced" style="display:none;width:430px; height:350px; overflow:hidden; position:absolute; top:0; right:0; background:#D6BEBE;z-index:6;padding:10px;"><a href="#" class="clsref" style="display:block;margin:5px 0 15px;color:#000000;text-align:center;font-size:9px;">fermer et retourner aux références</a><img src="'+$('.hvr',this).attr("src")+'" class="image_left" alt="" /><div><p><span style="font-size:14px;font-weight:bold;color:#92117E;">'+$('img',this).attr('alt')+'</span><br /><span style="color:#000">'+$('img',this).metadata().data.substr(2,100)+'</span></p>'+$(this).next('.refinfos').html()+'</div></div>');
		$('#infosref').fadeIn();
		$('.clsref').click( function() {
			$('#infosref').fadeOut(500, function() { $(this).remove(); } );
		});
	});
	
	$('#names').liScroll();
	
	$('.formshow').click( function() {
		$('#formcontact').show();
	});
	
});
