/*—~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ M A I N.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

var mainClass = {

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ VARIABLES.
	cacheImage: [],
	formNotificationDuration: 2000,	
	menuSlideDuration: 150,
	linkCurrent: false,
	firstRun: true,
	//rubric1Password: false,
	//rubric2Password: false,
	pressPassword: false,

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INITIALIZE.
	initialize: function() {	
		jQuery.fx.off = false;
		// Ajax.
		$.ajaxSetup({
			url: 'frontHtml.php',
			type: 'POST',
			dataType: 'json',
			async: true,
			cache: false
		});
		// Init.
		this.userMobile();
		this.pageBuild();
		this.pageInit();
		this.menuInit();
		this.googleAnalyticsInit();
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GOOGLE ANALYTICS.
	googleAnalyticsInit: function() {
		var apiHost = (('https:' == document.location.protocol) ? 'https://ssl.' : 'http://www.');
		$.getScript(apiHost + 'google-analytics.com/ga.js', function() {
			var pageTracker = _gat._getTracker('UA-28208238-1');
			pageTracker._initData();
			pageTracker._trackPageview();
		});
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DETECT MOBILE DEVICES.
	userMobile: function() {
		var userAgent = navigator.userAgent.toLowerCase();
		if ((userAgent.search(/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris/i) != -1) || (userAgent.search(/kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)|plucker|pocket|psp/i) != -1) || (userAgent.search(/symbian|treo|up.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i) != -1))
			this.isMobile = true;
		else if ($.browser.msie && parseInt($.browser.version)<9)
			this.isMobile = true;
		else
			this.isMobile = false;
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PRELOAD IMAGES.
	preLoadImage: function() {
		var argsCount = arguments.length;
		for (var i=argsCount; i--;) {
			var imgObj = document.createElement('img');
			imgObj.src = arguments[i];
			mainClass.cacheImage.push(imgObj);
		}
	},



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ L I N K S.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LINKS — DEEP LINKING.
	linkDeep: function() {
		$.address.state('/').init(function() {
			linkObj = $('#splashLanguageList a, #headerLogo, #headerMenuList a, #restrictedList a').die().live('click', function(e) {
				mainClass.linkFrom = $(this).closest('ul').attr('id');
			}).address();
		})
		.change(function(e) {
			var rubricFrame = $('#rubricFrame');
			var hrefPath = ($.address.state() + decodeURI(e.path.replace($('base').attr('href'),''))).replace(/\/\//,'/');
			//console.log($.address.state() + ' | ' + e.path + ' | ' + hrefPath);
			if (hrefPath != '/') {
				rubricFrame.oneTime(10000, 'rubricDelay', function() {
					rubricFrame.html('Loading…');
				});
				postObj = $.extend({
						xhrAct: 'getBodyHtml',
						urlrewriting: hrefPath
					},
					($.cookie('rubric1Password') ? {rubric1Password: $.cookie('rubric1Password')} : {}),
					($.cookie('rubric2Password') ? {rubric2Password: $.cookie('rubric2Password')} : {})
				);
				$.ajax({
					data: postObj,				
					cache: true,
					beforeSend: function() {
						document.title = 'Loading…';
					},
					success: function(jsonObj, textStatus, xhrObj) {
						rubricFrame.stopTime('rubricDelay');
						document.title = jsonObj.title;
						//~~~ Splash page link.
						if (mainClass.linkFrom == 'splashLanguageList') {
							$('body').css('overflow', 'hidden');
							rubricFrame.html(jsonObj.page);
							if (jsonObj.header)
								$('#headerMenuList').replaceWith(jsonObj.header);
							if (jsonObj.footer) {
								$('#footerMenuList').replaceWith(jsonObj.footer);
								$('#footerContent h6').text(jsonObj.footer2);
								$('#footerContainer').html(jsonObj.footerContainer);
								mainClass.pageBuildFooter();
								mainClass.menuInit();
							}
							mainClass.pageInit();
							$('#splashFrame').removeClass('show').animate({top:'-'+$('#splashFrame').height()+'px'}, {duration:'slow', easing:'easeInQuart', complete:function() {
								$(this).hide();
								$('#headerFrame, #bodyFrame').show().animate({top:'0px'}, {duration:'slow', easing:'easeOutQuint', complete:function() {
									$('body').css('overflow', 'visible');
								}});
								$('#footerFrame').show().animate({bottom:'0px'}, {duration:'slow'});
								$('#siteBackground-1, #siteBackground-2, #creditFrame').fadeTo('slow',1);
							}});
						}
						//~~~ Header menu link.
						else if (mainClass.linkFrom!='splashLanguageList' && !mainClass.firstRun) {
							// menu.
							$('#headerMenuList a').each(function() {
								if ($(this).hasClass('selected'))
									$(this).removeClass('selected').trigger('mouseleave');
								else if ($(this).data('id') == jsonObj.rubricId)
									$(this).trigger('mouseenter').addClass('selected');
							});
							/*linkObj.each(function() {
								if ($(this).hasClass('selected'))
									$(this).removeClass('selected');
								else if ($(this).data('id') == jsonObj.rubricId)
									$(this).addClass('selected');
							});*/
							// rubric.				
							rubricFrame.animate({top:'-'+(rubricFrame.height()+parseInt(rubricFrame.css('marginTop')))+'px'}, {duration:'normal', easing:'easeInQuad', complete:function() {
								$(this).html(jsonObj.page);
								mainClass.positionFooter();
								mainClass.pageInit();
							}})
							.animate({top:($(window).height())+'px'}, {duration:0})
							.animate({top:'0px'}, {duration:'normal', easing:'easeOutQuint'});
						}
						mainClass.firstRun = false;
					},
					error: function(xhrObj, textStatus, errorThrown) {
						rubricFrame.stopTime('rubricDelay');
						document.title = '404 Page not found';
						rubricFrame.fadeTo(20,1).html('<h1>404 Page not found</h1>\r<p>La page ne peut être trouvée.</p>\r');
					}
				});
			}
			//~~~ Back to splash-page.
			else {
				$('body').css('overflow', 'hidden');
				$('#siteBackground-1, #siteBackground-2, #creditFrame').fadeTo('slow',0);
				mainClass.isMobile ? $('#footerFrame').hide() : $('#footerFrame').animate({bottom:'-'+$('#footerFrame').outerHeight()+'px'}, {duration:'slow'});
				$('#headerFrame, #bodyFrame').show().animate({top:$('#splashFrame').height()+'px'}, {duration:'slow', easing:'easeInQuint', complete:function() {	
					$('#headerMenuList, #footerMenuList').find('.selected').removeClass('selected').trigger('mouseleave');
					$(this).hide();
					mainClass.pageOffset();
					$('#splashFrame').addClass('show').show().animate({top:'0px'}, {duration:'slow', easing:'easeOutQuart', complete:function() {
						//$('body').css('overflow', 'visible');
					}});
				}})
			}
		});
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LINKS — EXTERNAL.
	linkExternal: function() {
		$('a[href^=http]').each(function(i) {
			if (!$(this).attr('href').match($('base').attr('href')))
				$(this).attr('target', '_blank');
		});
	},



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ H E A D E R   M E N U.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MENU — INIT.
	menuInit: function() {
		
		//~~~ Header Menu.
		$('#headerMenuList a').removeAttr('title');
		$('#headerMenuList a').unbind().bind({
			mouseenter: function(e) {
				if (!$(this).hasClass('selected')) {
					$(this).stop(true,true).animate({color:'#c19d4a'}, {duration:'normal', easing:'easeOutQuad'});
				}
			},
			mouseleave: function(e) {
				if (!$(this).hasClass('selected')) {
					$(this).stop(true,true).animate({color:'#af081a'}, {duration:'normal', easing:'easeInQuad'});
				}
			}
		});

		//~~~ Footer Menu.
		$('#footerMenuList a').unbind().bind({
			click: function(e) {
				e.preventDefault();
				var tagObj = this;
				if (!$('#footerContainer').hasClass('opened')) {
					$('#mainFrame').width($(window).width()).height($(window).height());
					$(tagObj).addClass('selected');
					$('.footerRubricFrame').width($(window).width() - parseInt($('.footerRubricFrame').css('paddingLeft')) - parseInt($('.footerRubricFrame').css('paddingRight')));
					$('#footerContainer').show().toggleClass('opened').animate({height:$(window).height()}, {duration:'normal', easing:'easeOutQuad', complete:function() {
						$('#footerContainer a.close').fadeIn('fast');
						$('.footerRubricFrame[data-id="'+$(tagObj).attr('data-id')+'"]').fadeIn(500, 'easeOutQuad', function() {
							mainClass.formLayout();
						});
						//$('body').css('overflow', 'hidden');
						$('#headerFrame, #bodyFrame, #siteBackground-1, #siteBackground-2, #creditFrame').hide();
						mainClass.formLayout();
						$('*[id$="Notification"]').fadeOut(0);
					}});
					$('#footerContent, #footerContent a').animate({color:'#ffffff', backgroundColor:'#af081a'}, {duration:'fast', easing:'easeOutQuad'});
				}
				else {
					if (!$(tagObj).hasClass('selected')) {
						$('#footerMenuList a').removeClass('selected');
						$(tagObj).addClass('selected');
						$('.footerRubricFrame:visible').fadeOut('fast', function() {
							$('.footerRubricFrame[data-id="'+$(tagObj).attr('data-id')+'"]').fadeIn('fast', 'easeOutQuad');
							mainClass.formLayout();
							$('*[id$="Notification"]').fadeOut(0);
						});
					}
				}
			}
		});
		$('#footerContainer a.close').unbind().bind({
			click: function(e) {
				e.preventDefault();	
				var tagObj = this;
				if ($('#footerContainer').hasClass('opened')) {
					$('#mainFrame').width('').height('');
					$('#footerMenuList a').removeClass('selected');
					$('#headerFrame, #bodyFrame, #siteBackground-1, #siteBackground-2, #creditFrame').show();
					$('#footerContainer a.close').fadeOut('fast');
					$('#footerContainer').toggleClass('opened').animate({height:'0px'}, {duration:'normal', easing:'easeInQuad', complete:function() {
						$(this).hide();
						/*$('body').css('overflow', 'auto');*/
					}});
					$('.footerRubricFrame').fadeOut(300, 'easeInQuad');
					$('#footerContent, #footerContent a').delay(250).animate({color:'#af081a', backgroundColor:'transparent'}, {duration:'fast', easing:'easeInQuad'});
					$('#footerMenuList a').delay(350).animate({backgroundPosition:'0px 0px'}, {duration:0});
				}
			}
		});
	},



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ P A G E.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PAGE — BUILD.
	pageBuild: function() {		
		//~~~ Dumb ass iPatch…
		//if (navigator.platform=='iPad' || navigator.platform=='iPhone' || navigator.platform=='iPod')
		//	$('.siteBorder, #siteBackground-1, #siteBackground-2, #headerFrame, #footerFrame, #footerContainer, #creditFrame').css({position:'static'});

		if ($.browser.msie)
			$('#creditFrame').remove();

		//~~~ Overlay.
		$('<div>').attr('id','overlayFrame').appendTo($('#mainFrame'));
		$('#overlayFrame').fadeOut(0);

		//~~~ Site.
		$('<div>').attr('id','siteBackground-1').prependTo($('#siteFrame'));
		$('<div>').attr('id','siteBackground-2').appendTo($('#siteFrame'));

		//~~~ Footer.
		this.pageBuildFooter();
		
		//~~~ Splash.
		if ($('#splashFrame').is('*')) {
			if ($('#splashFrame').hasClass('show')) {
				$('#headerFrame, #bodyFrame, #footerFrame').hide();
				$('#splashLogo h1, #splashBaseline, #splashLanguageList').hide();
				$('#splashLanguageList').hide();
				$('#siteBackground-1, #siteBackground-2, #creditFrame').fadeTo(0,0);
				$('#headerFrame, #bodyFrame').css({top:$(window).height()+'px'});
				//$('#footerFrame').css({bottom:'-'+$('#footerFrame').outerHeight()+'px'});
			}
			//
			$('#splashFrame h1').hide();
			//
			for (i=1; i<=3; i++)
				$('<img>').attr('id','splashLogoElement'+i).attr('src','images/splashLogo-el'+i+'.png').hide().appendTo($('#splashLogo'));
			(function splashElementShow(tagObj) {
				tagObj.eq(0).fadeIn((tagObj.attr('id').replace(/\D+/g,'')==1 ? 1200 : 800), function() {
					if ((tagObj=tagObj.slice(1)).length)
						splashElementShow(tagObj)
					else {
						mainClass.pageOffset();
						$('#splashBaseline').fadeIn(400, function() {
							$('#splashLanguageList').fadeIn(400);
						});
					}
				});
			})($('#splashFrame img'));
			//
			if ($('#splashFrame').hasClass('hide')) {
				$('#splashFrame').hide().css({top:'-'+$('#splashFrame').height()+'px'});
			}
		}
	},
	
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PAGE — BUILD — FOOTER.
	pageBuildFooter: function() {
		mainClass.formLayout();
		$('<a>').addClass('close').fadeOut(0).appendTo($('#footerContainer'));
		$('#footerContainer').removeClass('opened').height(0).hide();
		$('.footerRubricFrame').css({display:'none'});
		//$('.footerRubricFrame').css({opcaity:0.5});
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PAGE — INIT.
	pageInit: function() {
		//~~~ Site.
		if ($('#bodyFrame').is('div')) {
			this.slideboxesInit();			
			// Slide-show.
			$('.imageSlider').nivoSlider({
				effect: 'fade',
				slices: 4,
				boxCols: 4,
				boxRows: 2,
        animSpeed: 500,
				pauseTime: 2000,
				directionNav: false,
				directionNavHide: false,
				controlNav: false,
        keyboardNav: false,
        pauseOnHover: true,
				captionOpacity: 0.8
			});
			// Galleries.
			/*$('.imageSlider, #pressissueList ul').each(function(i) {
				$('a', this).touchGallery();
			});*/
			$('.imageSlider, #pressissueList ul').each(function(i) {
				$('a', this).photoSwipe({
					backButtonHideEnabled: true,
					captionAndToolbarFlipPosition: true,
					captionAndToolbarShowEmptyCaptions: false,
					enableMouseWheel: true,
					loop: true,
					nextPreviousSlideSpeed: 400,
					slideSpeed: 400/*,
					slideTimingFunction:*/
				});
			});
			// Browse button.
			$('#browseBack').hover(
				function () {
					$(this).stop(true,true).animate({backgroundPosition:'0px -34px'}, {duration:'fast'});
				},
				function () {
					$(this).stop(true,true).animate({backgroundPosition:'0px 0px'}, {duration:'fast'});
				}
			);
			if (!mainClass.isMobile)
				$('#browseBack').address();
			//
			/*if (mainClass.rubricPassword) {
				$('#rubricSigninForm').hide();
				$('#restrictedList').show();
			}
			else
				$('ul#restrictedList').fadeOut(0);*/
			//
			if (!mainClass.isMobile)
				$('ul#expositionList a').address();
			$("a[rel^='prettyPhoto']").prettyPhoto({
				social_tools: false,
				slideshow: false,
				default_width: $(window).width() / 1.5,
				default_height: $(window).height() / 1.5,
				theme: 'pp_default',
				opacity: 1,
				horizontal_padding: 1,
				modal: false,
				deeplinking: false,
				markup: '\
					<div class="pp_pic_holder"> \
						<div class="ppt">&nbsp;</div> \
						<div class="pp_top"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
						<div class="pp_content_container"> \
							<div class="pp_left"> \
							<div class="pp_right"> \
								<div class="pp_content"> \
									<div class="pp_loaderIcon"></div> \
									<div class="pp_fade"> \
										<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
										<div class="pp_hoverContainer"> \
											<a class="pp_next" href="#">next</a> \
											<a class="pp_previous" href="#">previous</a> \
										</div> \
										<div id="pp_full_res"></div> \
										<div class="pp_details"> \
											<div class="pp_nav"> \
												<a href="#" class="pp_arrow_previous">Previous</a> \
												<p class="currentTextHolder">0/0</p> \
												<a href="#" class="pp_arrow_next">Next</a> \
											</div> \
											<p class="pp_description"></p> \
											{pp_social} \
											<a class="pp_close" href="#">Close</a> \
										</div> \
									</div> \
								</div> \
							</div> \
							</div> \
						</div> \
						<div class="pp_bottom"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
					</div> \
					<div class="pp_overlay"></div>',
			gallery_markup: '<div class="pp_gallery"> \
								<a href="#" class="pp_arrow_previous">Previous</a> \
								<div> \
									<ul> \
										{gallery} \
									</ul> \
								</div> \
								<a href="#" class="pp_arrow_next">Next</a> \
							</div>'
			});
			// Press publications.
			$('#pressissueList ul').each(function(i) {
				$('li', this).not(':first').hide();
			});
			$('#pressissueList img').hover(
				function () {
					$(this).stop(true,true).fadeTo('fast', 0.7);
				},
				function () {
					$(this).stop(true,true).fadeTo('fast', 1);
				}
			);
		}
		//~~~ External links.
		this.linkExternal();
		//~~~ Page Offset.
		this.pageOffset();
		//~~~ Forms.
		this.formInit();		
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PAGE — POSITIONNING.
	pageOffset: function() {

		//~~~ Splash.
		if ($('#splashFrame').is('div')) {
			if (!$('#splashFrame').is(':visible') && mainClass.isMobile) {
				//$('#mainFrame').width($(window).width()).height($(window).height());
			}
			else {
				$('#mainFrame').width($(window).width()).height($(window).height());
				$('#splashLogo').center({shiftY:-50});
				$('#splashLanguageList').center({shiftY:220});
			}
		}

		//~~~ Site.
		if ($('#bodyFrame').is('div')) {
			$('#rubricFrame').css('min-height', $(window).height() - parseInt($('#rubricFrame').css('marginTop')) - parseInt($('#bodyFrame').css('paddingBottom')) - 10);
		}

		//~~~ Footer.
		$('.footerRubricFrame').width($('#footerContainer').outerWidth(true) - parseInt($('.footerRubricFrame').css('paddingLeft')) - parseInt($('.footerRubricFrame').css('paddingRight')));
		if ($('#footerContainer').hasClass('opened'))
			$('#footerContainer').height($(window).height());

		//~~~ Form.	
		this.formLayout();
		
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PAGE — SCROLL.
	pageScroll: function() {
		if (empty(mainClass.rubricScrollTo)) {
			var rubricUrlrewriting = '';
			var mainFrameScrollTop = ($('body').scrollTop() > 0) ? $('body').scrollTop() : $('html').scrollTop();
			$('.rubricFrame').each(function(i) {
				if (($(this).offset().top - parseInt($(this).css('marginTop')) - $(window).height()/2) < mainFrameScrollTop)
					rubricUrlrewriting = $(this).data('urlrewriting');
			});
			if (rubricUrlrewriting != window.location.hash) {
				mainClass.rubricScrollTo = false;
				window.location.hash = rubricUrlrewriting;
			}
		}
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PAGE — HASH CHANGE.
	pageHash: function() {
		if (window.location.hash) {
			var hashCurrent = window.location.hash.replace(/#/gi, '');
			if (!$('a[data-urlrewriting="'+hashCurrent+'"]').hasClass('selected')) {
				$('#headerMenuList, #footerMenuList').find('.selected').removeClass('selected').trigger('mouseleave');
				$('a[data-urlrewriting="'+hashCurrent+'"]').trigger('mouseenter').addClass('selected');
			}
			if (mainClass.rubricScrollTo !== false) {
				$.scrollTo($('.rubricFrame[data-urlrewriting="'+hashCurrent+'"]'), {
					duration: mainClass.rubricScrollTo,
					easing: 'easeInOutExpo',
					margin: true,
					onAfter: function() {
						mainClass.rubricScrollTo = false;
					}
				});
			}
		}
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SLIDE BOXES.
	slideboxesInit: function() {
		$('.slideBox').slideUp(1).prevAll('.slideTrigger').bind('click', function(e) {
			if (!$(this).hasClass('slideCurrent'))
				$('.slideOpened', $('#contentFrame')).removeClass('slideCurrent').nextAll('.slideBox').first().slideToggle(600, 'easeInOutExpo', function() {
					$(this).prevAll('.slideTrigger').first().toggleClass('slideOpened');
					mainClass.pageOffset();
				});
			$(this).toggleClass('slideCurrent').nextAll('.slideBox').first().slideToggle(600, 'easeInOutExpo', function() {
				$(this).prevAll('.slideTrigger').first().toggleClass('slideOpened');
				mainClass.pageOffset();
			});
		});
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ STYLES.
	styleSwitch: function(styleName) {
		$('link[@rel*=style][title]').each(function(i) {
			this.disabled = true;
			if ($(this).attr('title') == styleName)
				this.disabled = false;
		});
	},



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ P R E S S.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	pressInit: function() {
		this.pressPassword = $('#presskitSigninFormPassword').val();
		$('#presskitImageList a').live('click', function(e) {
			e.preventDefault();
			window.location.href = $('base').attr('href') + $(this).attr('href').replace($('base').attr('href'),'').replace(/\/[a-z0-9\-\.\_]*$/g,'') + '/' + mainClass.pressPassword + '/' + $(this).attr('rel');
		});
	},



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ F O R M S.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FORM — INIT.
	formInit: function() {
		//
		this.formLayout();
		this.formFieldLabel();
		//
		$('label[for$="Hello"], input[id$="Hello"]').hide().val('');
		$('form[id$="Form"]').data('busy', false);
		// Submit event.
		$('*[id$="Notification"]').fadeOut(0);
		$('form[id$="Form"]').bind('submit', function(e) {
			e.preventDefault();
			var tagObj = this;
			// Spam & Multiple clicks prevent.
			if (empty($('input[id$="Hello"]', tagObj).val()) && !$(tagObj).data('busy')) {	
				$(tagObj).data('busy', true);
				//
				// Restricted rubric #1 : “Entre-Nous”.
				if ($(tagObj).attr('id') == 'rubric1SigninForm') {
					$(tagObj).removeData('formError');
					if (empty($('#rubric1SigninPassword').val())) {
						mainClass.formNotification(tagObj, $(tagObj).data('error'), mainClass.formNotificationDuration);
						$(tagObj).data('formError', true);
						$(tagObj).data('busy', false);
						return false;
					}
					if (!$(tagObj).data('formError')) {
						mainClass.formNotification(tagObj, $(tagObj).data('loading'));
						$('#rubric1SigninPassword').val($('#rubric1SigninPassword').val().toLowerCase());
						$.ajax({
							data: $(tagObj).serialize()+'&urlrewriting='+encodeURIComponent($('#headerMenuList-6').attr('href').replace($('base').attr('href'),'')),
							success: function(jsonObj) {
								if (jsonObj.page) {
									$(tagObj).data('busy', false);
									$.cookie('rubric1Password', $('#rubric1SigninPassword').val(), {path:'/'});
									$(tagObj).fadeOut('normal', function() {
										$(tagObj).closest('div').find('div[id$="Notification"]').hide();
										$(tagObj).replaceWith(jsonObj.page).fadeIn('normal');
									});
								}
								else {
									$(tagObj).data('busy', false);
									mainClass.formNotification(tagObj, $(tagObj).data('error'), mainClass.formNotificationDuration);
								}
							},
							error: function() {
								$(tagObj).data('busy', false);
								mainClass.formNotification(tagObj, $(tagObj).data('error'), mainClass.formNotificationDuration);
							}
						});
					}
				}
				//
				// Restricted rubric #2 : "Very Private".
				if ($(tagObj).attr('id') == 'rubric2SigninForm') {
					$(tagObj).removeData('formError');
					if (empty($('#rubric2SigninPassword').val())) {
						mainClass.formNotification(tagObj, $(tagObj).data('error'), mainClass.formNotificationDuration);
						$(tagObj).data('formError', true);
						$(tagObj).data('busy', false);
						return false;
					}
					if (!$(tagObj).data('formError')) {
						mainClass.formNotification(tagObj, $(tagObj).data('loading'));
						$('#rubric2SigninPassword').val($('#rubric2SigninPassword').val().toLowerCase());
						$.ajax({
							data: $(tagObj).serialize()+'&urlrewriting='+encodeURIComponent($('#headerMenuList-65').attr('href').replace($('base').attr('href'),'')),
							success: function(jsonObj) {
								if (jsonObj.page) {
									$(tagObj).data('busy', false);
									$.cookie('rubric2Password', $('#rubric2SigninPassword').val(), {path:'/'});
									$(tagObj).fadeOut('normal', function() {
										$(tagObj).closest('div').find('div[id$="Notification"]').hide();
										$(tagObj).replaceWith(jsonObj.page).fadeIn('normal');
										mainClass.pageInit();
									});
								}
								else {
									$(tagObj).data('busy', false);
									mainClass.formNotification(tagObj, $(tagObj).data('error'), mainClass.formNotificationDuration);
								}
							},
							error: function() {
								$(tagObj).data('busy', false);
								mainClass.formNotification(tagObj, $(tagObj).data('error'), mainClass.formNotificationDuration);
							}
						});
					}
				}
				//
				// Press kit. 
				else if ($(tagObj).attr('id') == 'presskitSigninForm') {
					if (empty($('#presskitSigninFormPassword').val())) {
						mainClass.formNotification(tagObj, $(tagObj).data('error'), mainClass.formNotificationDuration);
						$(tagObj).data('formError', true);
						$(tagObj).data('busy', false);
						return false;
					}
					if (!$(tagObj).data('formError')) {
						mainClass.formNotification(tagObj, $(tagObj).data('loading'));
						$('#presskitSigninFormPassword').val($('#presskitSigninFormPassword').val().toLowerCase());
						$.ajax({
							data: $(tagObj).serialize()+'&urlrewriting='+$('#footerMenuList-7').attr('href').replace($('base').attr('href'),''),
							success: function(jsonObj) {
								$(tagObj).data('busy', false);
								if (jsonObj.footer) {
									mainClass.pressInit();
									$('#footerRubricFrame-7').html(jsonObj.footer);
									//$('#footerRubricFrame-7').replaceWith(jsonObj.footer);
									//mainClass.pageInit();
								}
								else {
									$(tagObj).data('busy', false);
									mainClass.formNotification(tagObj, $(tagObj).data('error'), mainClass.formNotificationDuration);
								}
							},
							error: function() {
								$(tagObj).data('busy', false);
								mainClass.formNotification(tagObj, $(tagObj).data('error'), mainClass.formNotificationDuration);
							}
						});
					}
				}
				//
				// Basic form with a submit button.
				else if ($('input[type="submit"]', tagObj).is('*')) {
					mainClass.formFieldRequired(tagObj);
					if (!$(tagObj).data('formError') && $('input[id$="Email"]', tagObj).is('*') && !emailCheck($('input[id$="Email"]', tagObj).val())) {
						mainClass.formNotification(tagObj, $(tagObj).data('invalid').replace(/\*/g, '"'+trim($('input[id$="Email"]', tagObj).prev('label').text().replace(/[:*]+/g,''))+'"'), mainClass.formNotificationDuration);
						$(tagObj).data('formError', true);
						$(tagObj).data('busy', false);
					}
					if (!$(tagObj).data('formError')) {
						mainClass.formNotification(tagObj, $(tagObj).data('loading'));
						$.ajax({
							data: $(tagObj).serialize(),
							success: function(jsonObj) {
								$(tagObj).data('busy', false);
								if (jsonObj.responseSuccess) {
									mainClass.formNotification(tagObj, ((jsonObj.responseSuccess=='true') ? $(tagObj).data('success') : jsonObj.responseSuccess), mainClass.formNotificationDuration);
									mainClass.formFieldEmpty(tagObj);
								}
								else if (jsonObj.responseError) {
									mainClass.formNotification(tagObj, ((jsonObj.responseError=='true') ? $(tagObj).data('error') : jsonObj.responseError), mainClass.formNotificationDuration);
								}
							},
							error: function() {
								$(tagObj).data('busy', false);
								mainClass.formNotification(tagObj, $(tagObj).data('error'), mainClass.formNotificationDuration);
							}
						});
					}
				}
			}
		});
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SIZING.
	formLayout: function() {
		// Sizing.
		$(':input.fit').each(function(i) {
			if ($(this).is('select') || $(this).is(':submit'))
				$(this).width($(this).closest('form').width());
			else if ($(this).attr('id') == 'newsletterFormEmail')
				$(this).width(Math.floor($(this).closest('form').width() - ($(this).outerWidth(true) - $(this).width()) - $('#newsletterFormSubmit').outerWidth(true)) - 1);
			else if ($(this).attr('id') == 'presskitSigninFormPassword')
				$(this).width(Math.floor($(this).closest('form').width() - ($(this).outerWidth(true) - $(this).width()) - $('#presskitSigninFormSubmit').outerWidth(true)) - 1);
			else 
				$(this).width(Math.floor($(this).closest('form').width()));
		});

	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FIELDS — LABEL.
	formFieldLabel: function(inputObj) {
		var inputObj = (inputObj) ? inputObj : $(':input[data-value]');
		inputObj.each(function() {		
			$(this).bind({
				focus: function() {
					if ($(this).val() == $(this).data('value'))
						$(this).removeClass('empty').val('');
					if ($(this).hasClass('password')) {
						$(this).hide();
						$(this).next().show().focus();
					}
				},
				change: function() {
					if (empty($(this).val()))
						$(this).addClass('empty');
					else
						$(this).removeClass('empty');
				},
				blur: function() {
					if (empty($(this).val())) {
						$(this).addClass('empty');
						if (!$(this).is('select'))
							$(this).val($(this).data('value'));
						else
							$('option', this).first().text($(this).data('value'));
					}
				}
			});
			$(this).trigger('blur');
		});
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FIELDS — EMPTY.
	formFieldEmpty: function(tagObj) {
		if ($(tagObj).is('*')) {
			$(tagObj).find(':input').each(function() {
				switch(this.type) {
					case 'password':
					case 'select-multiple':
					case 'select-one':
					case 'text':
					case 'textarea':
						($(this).data('value')) ? $(this).val('').trigger('blur') : $(this).val(''); break;
					case 'checkbox':
						if ($(this).hasClass('switch')) $(this).trigger('switch');
						else this.checked = false;
						break;
					case 'radio':
						this.checked = false; break;
				}
			});
		}
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FORM — REQUIRED FIELDS.
	formFieldRequired: function(tagObj) {
		$(tagObj).removeData('formError');
		$(':input:visible', tagObj).each(function(i) {
			if ($(this).hasClass('required') && (empty($(this).val()) || ($(this).val() == $(this).data('value')))) {
				if ($(tagObj).data('required'))
					mainClass.formNotification(tagObj, $(tagObj).data('required').replace(/[:*]+/g, '“'+trim($(this).attr('data-value').replace(/[:*]+/g,'')+'”')), mainClass.formNotificationDuration);
				else
					mainClass.formNotification(tagObj, 'Le champs “'+trim($(this).attr('data-value').replace(/[:*]+/g,''))+'” est requis.', mainClass.formNotificationDuration);
				$(tagObj).data('formError', true);
				$(tagObj).data('busy', false);
				return false;
			}
		});
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FORM — NOTIFICATION HIGHLIGHT.
	formNotification: function(tagObj, str, time) {
		notificationObj = $(tagObj).closest('div').find('div[id$="Notification"]');
		notificationObj.text(str).fadeIn('normal');
		if (time) {
			notificationObj.delay(time).fadeOut('normal');
		}
	},
	
	positionFooter: function() {
		if (this.isMobile)
			$('#footerFrame').css({position:'absolute', top:($('#bodyFrame').outerHeight()-$('#footerFrame').outerHeight()+2)+'px'});
		//$('#splashFrame').hasClass('show') ? $('#footerFrame').hide() : $('#footerFrame').show();
	}

}



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ O N   D O M   R E A D Y.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EVENTS — WINDOW.
jQuery(window).bind({
	resize: function(e) {
		mainClass.pageOffset();
		mainClass.positionFooter();
	},
	scroll: function(e) {
		mainClass.positionFooter();
	}
});

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EVENTS — DOCUMENT.
jQuery(document).ready(function() {
	mainClass.initialize();
	mainClass.positionFooter();
});

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DEEP LINKING.
if (!userMobile()) {
	mainClass.linkDeep();
}

/*
(function(window, $, PhotoSwipe) {
}(window, window.jQuery, window.Code.PhotoSwipe));
*/

/*—~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
