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

var mainClass = {

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ VARIABLES.
	cacheImage: [],
	formNotificationDuration: 2000,
	menuSlideDuration: 250,
	slideshowBrowseCount: 0,
	slideshowBrowseCurrent: 1,
	pressPassword: "",

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INITIALIZE.
	initialize: function() {	
		// Ajax.
		$.ajaxSetup({
			url: "frontHtml.php",
			type: "POST",
			dataType: "json",
			async: true,
			cache: false
		});
		this.menuInit();
		this.pageInit();
		// Hash.
		this.googleAnalyticsInit();
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DETECT IE7 BROWSER.
	detectIE7: function() {
		this.isIE7 = ($.browser.msie && ($.browser.version.substr(0, 1) == "7")) ? true : false;
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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-21116102-1");
			pageTracker._initData();
			pageTracker._trackPageview();
		});*/

		/*var _gaq = _gaq || [];
		_gaq.push(['_setAccount', 'UA-7315638-27']);
		_gaq.push(['_trackPageview']);		
		(function() {
			var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
			ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
		})();*/
		
		var apiHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
		$.getScript(apiHost + "google-analytics.com/ga.js", function() {
			var pageTracker = _gat._getTracker("UA-7315638-27");
			pageTracker._initData();
			pageTracker._trackPageview();
		});
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EXPERTA EVOLUTION STATISTIQUES.
	statsInit: function() {
		/*$.ajax({
			url: "http://stats.expertaevolution.fr/phpmyvisites.js",
			dataType: "script",
			type: "GET",
			data: {
				pagename: "home",
				phpmyvisitesSite: 3,
				phpmyvisitesURL: "http://stats.expertaevolution.fr/phpmyvisites.php"
			}
		});*/
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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);
		}
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ROLL-OVER IMAGES.
	rolloverImage: function() {
		$('*[data-rollover]').each(function(i) {
			tagObj = ($(this).is('img')) ? $(this) : $(this).find('img');
			tagObj.each(function(j) {
				var imgSrc = $(this).attr('src');
				var imgPathOver = imgSrc.substring(0, imgSrc.lastIndexOf('_'))+"-over";
				var imgPathOut = imgSrc.substring(0, imgSrc.lastIndexOf('.'));
				var imgExtension = imgSrc.substr(imgSrc.lastIndexOf('.'));
				mainClass.preLoadImage(imgPathOut+imgExtension, imgPathOver+imgExtension);
				$(this).hover(
					function() {
						$(this).attr('src', imgPathOver+imgExtension);
					},
					function() {
						$(this).attr('src', imgPathOut+imgExtension);
					}
				);
			});
		});
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MENU LIST TOKEN.
	listTokenRemove: function() {
		$('li:last-child').each(function(i) {
			if (($(this).css('float') == "left" || $(this).css('float') == "right") && $(this).css('backgroundImage').search(/bullet/i) == -1)
				($(this).css('float') == "right") ? $(this).add($(this).children('a')).css({paddingLeft:"0px"}) : $(this).add($(this).children('a')).css({paddingRight:"0px", backgroundImage:"none"});
		});
		$('li:first-child').each(function(i) {
			if (($(this).css('float') == "left" || $(this).css('float') == "right") && $(this).css('backgroundImage').search(/bullet/i) == -1)
				($(this).css('float') == "right") ? $(this).add($(this).children('a')).css({paddingRight:"0px", backgroundImage:"none"}) : $(this).add($(this).children('a')).css('padding-left', "0px");
		});
		$('ul[data-cols], ol[data-cols]').each(function(i) {
			$('li:nth-child('+$(this).attr('data-cols')+'n)', $(this)).each(function(i) {
				if ($(this).css('backgroundImage').search(/bullet/i) == -1)
					($(this).css('float') == "right") ? $(this).add($(this).children('a')).css({paddingLeft:"0px"}) : $(this).add($(this).children('a')).css({paddingRight:"0px", backgroundImage:"none"});
			});
		});
	},



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

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MENU INIT.
	menuInit: function() {
		this.preLoadImage("/images/headerLogo-over.png");
		$('ul#headerMenuList a').removeAttr('title');
		// Menu.
		$('ul#headerMenuList a').bind('click', function(e) {
			e.preventDefault();
			if ($(this).attr('data-id') != "4") { // playroom.
				$('.selected', $(this).parent('li').parent('ul')).removeClass('selected');
				$('.selected', $('ul#footerMenuList')).removeClass('selected');			
				if (!$(this).next().is('ul')) {
					$(this).addClass('selected');
					if ($('.opened', $('ul#headerMenuList')).is('*') && !$(this).parents('ul').hasClass('menuBranchContent')) {
						$(this).oneTime(mainClass.menuSlideDuration, function() {
							window.location.href = $(this).attr('href');
						});
					}
					else {
						mainClass.menuSlideUp($('.opened', $('ul#headerMenuList')).next());
						$(this).oneTime(mainClass.menuSlideDuration, function() {
							window.location.href = $(this).attr('href');
						});
					}
				}
			}
		});
		// Menu whole roll-out.
		$('ul#headerMenuList').bind('mouseover', function(e) {
			$('ul#headerMenuList').stopTime();
		});
		$('ul#headerMenuList').bind('mouseout', function(e) {
			$('ul#headerMenuList').oneTime(1500, function() {
				mainClass.menuSlideUp($('.opened', $('ul#headerMenuList')).next());
			});
		});
		// Menu level 1.
		$('ul#headerMenuList > li > a').bind('mouseover', function(e) {
			if ($(this).attr('data-id') != "4") { // playroom.
				if ($('.opened', $('ul#headerMenuList')).is('*') && ($(this).attr('id') != $('.opened', $('ul#headerMenuList')).attr('id')))
					mainClass.menuSlideUp(this);
				else if ($(this).next().is('ul')) //else if (!$('*:animated', $('ul#headerMenuList')).is('*') && $(this).next().is('ul'))
					mainClass.menuSlideDown(this);
			}
		});
		// Saloperie pour "Salle de jeu / playroom".
		$('ul#headerMenuList > li > a').bind({
			mouseover: function() {
				if ($(this).attr('data-id') == "4") {
					var overHtml = ($(this).attr('href').match(/fr\//g)) ? "Bientôt" : "Soon";
					$(this).html(overHtml);
				}
			},
			mouseout: function() {
				if ($(this).attr('data-id') == "4") {
					$(this).html($(this).attr('data-title'));
				}
			}
		});		
		// Menu level 2 (sub-menu).
		$('ul#headerMenuList ul').slideUp(0);
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SUB-MENU SLIDE DOWN.
	menuSlideDown: function(clickedObj) {
		$(clickedObj).addClass('opened').next().slideDown(mainClass.menuSlideDuration, "easeInOutQuad");
	},
	
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SUB-MENU SLIDE UP.
	menuSlideUp: function(clickedObj) {
		previousObj = $('.opened', $('ul#headerMenuList'));
		previousObj.removeClass('opened');
		if ($(previousObj).attr('id') != $(clickedObj).attr('id') && $(clickedObj).next().is('ul'))
			$(clickedObj).addClass('opened');
		previousObj.next().slideUp(mainClass.menuSlideDuration, "easeInOutQuad", function() {
			if ($(previousObj).attr('id') != $(clickedObj).attr('id') && $(clickedObj).next().is('ul'))
				mainClass.menuSlideDown(clickedObj);
		});
	},



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ S I D E - M E N U   /   L A N G U A G E - M E N U.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SIDE MENU INIT.
	menuSideInit: function() {
		// Side-menu.
		$('ul#sideMenuList a, ul#footerMenuList a').bind('click', function(e) {
			e.preventDefault();
			$('.selected', $(this).parent('li').parent('ul')).removeClass('selected');
			$(this).addClass('selected');
				window.location.hash = $(this).attr('href').replace($('base').attr('href'),"");
		});
	},



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

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INIT.
	pageInit: function() {
		this.listTokenRemove();
		this.rolloverImage();
		// Links.
		this.linkInit();
		// Home.
		this.homeInit();
		this.slideshowFullInit();
		this.slideboxesInit();
		// Items.
		$('div#itemTitlesFrame').width($('h2#itemTitle').outerWidth(true));
		// Retailers.
		this.retailerMapInit();
		// Press.
		this.pressInit();
		// Issues.
		this.issueInit();
		// Forms.
		this.formInit();
		this.retailerFormInit();
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LINKS.
	linkInit: function() {
		$('a[href^=http]').attr('target', "_blank");
	},

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



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ H O M E.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HOME INIT.
	homeInit: function() {
		// Gallery slideshows.
		/*$('div#homeSlideviewer').slideViewerPro({
			galBorderWidth: 0,
			asTimer: 3500,
			autoslide: true,
			thumbsVis: false,
			shuffle: false
		});*/
		this.slideshowHomeInit();
		// Highlights.
		this.preLoadImage("/images/highlightListOverlay.png");
		$('ul#highlightList a').each(function(i) {
			$(this).bind({
				mouseover: function() {
					$(this).find('div').show();
					$(this).find('img').trigger('mouseenter');
				},
				mouseout: function() {
					$(this).find('div').hide();
					$(this).find('img').trigger('mouseleave');
				}
			});
		});
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SLIDE BOXES.
	slideboxesInit: function() {
		$('*[class$=Slide]').slideUp(0).prev().bind('click', function(e) {
			if (!$(this).hasClass('slideCurrent'))
				$('.slideOpened', $(this).parents('ul, ol')).removeClass('slideCurrent').next().slideToggle(600, "easeInOutExpo", function() {
					$(this).prev().toggleClass('slideOpened');
				});
			$(this).toggleClass('slideCurrent').next().slideToggle(600, "easeInOutExpo", function() {
				$(this).prev().toggleClass('slideOpened');
			});
		});
	},



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ S L I D E - S H O W.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SLIDESHOW – INIT.
	slideshowHomeInit: function() {
		mainClass.slideshowBrowseCount = $('ul[id$=SlideviewerPictures]').find('img').hide().length;
		$('img#slide'+mainClass.slideshowBrowseCurrent).show();
		//
		/*if ($('div[id$=Slideviewer]').attr('data-play')) {
			$(this).everyTime(3500, function() {
				var slideshowBrowseNext = (mainClass.slideshowBrowseCurrent == mainClass.slideshowBrowseCount) ? 1 : (mainClass.slideshowBrowseCurrent + 1);
				var slideshowBrowsePrevious = (mainClass.slideshowBrowseCurrent == 1) ? mainClass.slideshowBrowseCount : (mainClass.slideshowBrowseCurrent - 1);
				mainClass.preLoadImage($('img#slide'+slideshowBrowseNext).attr('src'), $('img#slide'+slideshowBrowsePrevious).attr('src'));
				//
				$('img#slide'+mainClass.slideshowBrowseCurrent).fadeOut(1000);
				$('img#slide'+slideshowBrowseNext).fadeIn(1000);
				mainClass.slideshowBrowseCurrent = slideshowBrowseNext;
			});
		}	*/	
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FULL SCREEN SLIDESHOW – INIT.
	slideshowFullInit: function() {
		// Gallery.
		$('a[rel=slideshow]').colorbox({
			transition: "none",
			opacity: 1,
			overlayClose: true,
			scalePhotos: true,
			scrolling: false,
			slideshow: false,
			slideshowSpeed: 4000,
			previous: $('ul.slideshow, ol.slideshow').attr('data-slideshow_previous'),
			next: $('ul.slideshow, ol.slideshow').attr('data-slideshow_next'),
			close: $('ul.slideshow, ol.slideshow').attr('data-slideshow_close'),
			current: $('ul.slideshow, ol.slideshow').attr('data-slideshow_current'),
			onOpen: function() {
				$('div#cboxOverlay').css('opacity', 0).fadeTo('fast', 1);
				$('#cboxPrevious, #cboxNext').fadeIn(200);
				$('body#mainFrame').css({overflow:"hidden"});
			},
			onClosed: function() {
				$('#cboxPrevious, #cboxNext').fadeOut(200);
				$('body#mainFrame').css({overflow:"visible"});
			},
			onComplete: function() {
				$.colorbox.resize({width:"95%", height:"95%"});
				$('img#cboxPhoto').css('opacity', 0).fadeTo('slow', 1);
				//$('#cboxCurrent, #cboxSlideshow, #cboxClose').hide();		
				$('#cboxCurrent, #cboxSlideshow, #cboxClose').hide();		
				/*if (!$('div#cboxContent').hasClass('hover'))
					$('#cboxCurrent, #cboxSlideshow, #cboxPrevious, #cboxNext, #cboxClose').hide();
				$('div#cboxContent').hover(
					function() {
						$(this).addClass('hover');
						$('#cboxCurrent, #cboxSlideshow, #cboxPrevious, #cboxNext, #cboxClose').fadeIn('fast');						
					},
					function() {
						$(this).removeClass('hover');
						$('#cboxCurrent, #cboxSlideshow, #cboxPrevious, #cboxNext, #cboxClose').fadeOut('fast');
					}
				);*/
			}
		});
		// Thumbs.
		$('li.itemPictoSlideshow a').bind('click', function(e) {
			e.preventDefault();
			$('a[rel=slideshow]').first().trigger('click');
		});
		// Controllers.
		$('#cboxPrevious, #cboxNext').appendTo('body#mainFrame').hide();
	},



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ R E T A I L E R.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MAP – INIT.
	retailerMapInit: function() {
		$('img#retailerMapWorldFrontground').fadeTo(0, 0.01);
		$('img[data-rev]', $('div#retailerRightFrame')).fadeTo(0, 0);
		$('area', $('map#retailerMapWorldAreas')).bind({
			mouseover: function() {
				$('img[data-rev='+$(this).attr('data-rel')+']', $('div#retailerRightFrame')).clearQueue().fadeTo(200, 1);
			},
			mouseout: function() {
				$('img[data-rev='+$(this).attr('data-rel')+']', $('div#retailerRightFrame')).clearQueue().fadeTo(200, 0);
			}
		});
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FORM – INIT.
	retailerFormInit: function() {
		// Init.
		$('ol#retailerList a.disabled').each(function(i) {
			$(this).click(function(e) {
				e.preventDefault();
			});
		});
		if ($('img#retailerMapWorldFrontground').is('*')) {
			$('select#retailerFormCity, label[for="retailerFormCity"], a#retailerFormBack').hide();
			$('span#retailerFormInfos').show();
		}
		else if (isEmpty($('select#retailerFormCountry').val())) {
			$('a#retailerFormBack').show();
			$('select#retailerFormCity, label[for="retailerFormCity"], span#retailerFormInfos').hide();
		}
		else {
			$('select#retailerFormCity, label[for="retailerFormCity"], a#retailerFormBack').show();
			$('span#retailerFormInfos').hide();
		}
		// Selects.
		$('select#retailerFormCountry, select#retailerFormCity').bind('change', function(e) {
			if (!isEmpty($(this).val())) {
				window.location.href = $('base').attr('href') + $(this).val();
			}
		});
		// Back button.
		$('a#retailerFormBack').bind('click', function(e) {
			if (!isEmpty($('select#retailerFormCity').val())) {
				$('select#retailerFormCountry').trigger('change');
			}
			else {
				window.location.href =$('base').attr('href') + $('link[rel=section]').attr('href');
			}
		});
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FORM – INIT.
	retailerListDisplay: function(area, toto) {
		$('div#retailerRightFrame').hide();
		if (area == "continent")
			$('li[data-id_'+area+'='+$(toto).attr('data-id_continent')+']').clone().appendTo('ol#retailerSelectedList').show();
		else
			$('li[data-id_'+area+'='+$('select#retailerForm'+strUcfirst(area)).val()+']').clone().appendTo('ol#retailerSelectedList').show();
		$('ol#retailerList').show();
		$('ol#retailerList a').each(function(i) {
			if (!$(this).attr('href').match(/http/g))
				$(this).addClass('disabled');
			$(this).click(function(e) {
				($(this).attr('href').match(/http/g)) ? $(this).addClass('link').attr('target', "_blank") : e.preventDefault();
			});
		});
	},



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

	pressInit: function() {
		$('ol.pressThumbList a').bind('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');
		});
	},



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I S S U E.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	issueInit: function() {
		$('ol.issueThumbList a').bind('click', function(e) {
			e.preventDefault();
			window.location.href = $('base').attr('href') + $(this).attr('href').replace($('base').attr('href'),"").replace(/\/[a-z0-9\-\.\_]*$/g, "") + "/" + $(this).attr('rel');
		});
	},



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

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FORM – INIT.
	formInit: function() {
		// IE7
		if (this.isIE7) {
			$('input[type=submit]').css({padding:"1px 0px"});
			$('input, textarea, select').bind({
				mouseover: function() {
					$(this).css({border:"1px solid #000000"});
				},
				mouseout: function() {
					$(this).css({border:"1px dotted #000000"});
				},
				focus: function() {
					$(this).css({backgroundColor:"#ffe900", border:"1px solid #000000"});
				},
				blur: function() {
					$(this).css({backgroundColor:"#ffffff", border:"1px dotted #000000"});
				}
			});
		}
		// Hide Spam prevent inputs.
		$('label[for$="Hello"], input[id$="Hello"]').hide();
		$('form[id$="Form"]').data('busy', false);
		// Submit event.
		$('form[id$="Form"]').bind('submit', function(e) {
			e.preventDefault();
			var tagObj = this;
			// Spam & Multiple clicks prevent.
			if (isEmpty($('input[id$="Hello"]', tagObj).val()) && !$(tagObj).data('busy')) {
				$(tagObj).data('busy', true);
				// Press. 
				if ($(tagObj).attr('id') == "pressSigninForm") {
					if (isEmpty($('input#pressSigninFormPassword').val())) {
						mainClass.formNotification(tagObj, $(tagObj).attr('data-error'), mainClass.formNotificationDuration);
						$(tagObj).data('formError', true);
						$(tagObj).data('busy', false);
						return false;
					}
					if (!$(tagObj).data('formError')) {
						mainClass.formNotification(tagObj, $(tagObj).attr('data-loading'));
						$.ajax({
							data: $(tagObj).serialize()+"&urlrewriting="+encodeURIComponent($('link[rel=chapter]').attr('href').replace($('base').attr('href'),"")),
							success: function(jsonObj) {
								$(tagObj).data('busy', false);
								if (jsonObj.pageFrame) {
									mainClass.pressPassword = $('input#pressSigninFormPassword').val();
									$('div#pageFrame').html(jsonObj.pageFrame);
									mainClass.pageInit();
								}
								else {
									mainClass.formNotification(tagObj, $(tagObj).attr('data-error'), mainClass.formNotificationDuration);
								}
							},
							error: function() {
								$(tagObj).data('busy', false);
								mainClass.formNotification(tagObj, $(tagObj).attr('data-error'), mainClass.formNotificationDuration);
							}
						});
					}				
				}
				// 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).attr('data-invalid').replace(/\*/g, "“"+stringTrim( !isEmpty($('input[id$="Email"]',tagObj).prev('label').attr('data-label')) ? ($('input[id$="Email"]',tagObj).prev('label').attr('data-label').replace(/[:*]+/g,"")) : ($('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).attr('data-loading'));
						$.ajax({
							data: $(tagObj).serialize(),
							success: function(jsonObj) {
								$(tagObj).data('busy', false);
								if (jsonObj.responseSuccess) {
									mainClass.formNotification(tagObj, ((jsonObj.responseSuccess=="true") ? $(tagObj).attr('data-success') : jsonObj.responseSuccess), mainClass.formNotificationDuration);
									$('input[type="text"], textarea, select', tagObj).val("");
								}
								else if (jsonObj.responseError) {
									mainClass.formNotification(tagObj, ((jsonObj.responseSuccess=="true") ? $(tagObj).attr('data-error') : jsonObj.responseError), mainClass.formNotificationDuration);
								}
							},
							error: function() {
								$(tagObj).data('busy', false);
								mainClass.formNotification(tagObj, $(tagObj).attr('data-error'), mainClass.formNotificationDuration);
							}
						});
					}
				}
			}
		});
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FORM – REQUIRED FIELDS.
	formFieldRequired: function(tagObj) {
		$(tagObj).data('formError', false);
		$('input, textarea', tagObj).each(function(i) {
			if (($(this).prev('label').attr('data-required') == 1) && isEmpty($(this).val())) {
				mainClass.formNotification(tagObj, $(tagObj).attr('data-required').replace(/\*/g, "“"+stringTrim( !isEmpty($(this).prev('label').attr('data-label')) ? ($(this).prev('label').attr('data-label').replace(/[:*]+/g,"")) : ($(this).prev('label').text().replace(/[:*]+/g,"")) ) +"”"), mainClass.formNotificationDuration);
				$(tagObj).data('formError', true);
				$(tagObj).data('busy', false);
				return false;
			}
		});
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FORM – NOTIFICATION HIGHLIGHT.
	formNotification: function(tagObj, str, time) {
		$('label[id$="Notification"]', tagObj).text(str).fadeTo('normal', 1);
		if (time)
			$('label[id$="Notification"]', tagObj).delay(time).fadeTo('normal', 0);
	}

};



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ O N   D O M   R E A D Y.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
jQuery(document).ready(function() {
	mainClass.initialize();
});

