/*----------------------------------------------------------------------------------------------------------------------------------------*/
/*    Author       : Matt lowe (mattlowe@hotmail.com)                                                                                     */
/*    Description  : Interface templates                                                                                                  */
/*    Version      : 1                                                                                                                    */
/*    Dependencies : jquery-1.5.1.min.js                                                                                                  */
/*                   jquery.easing-1.3.min.js                                                                                             */
/*                   jquery.mousewheel-3.0.4.min.js                                                                                       */
/*                   jquery.fancybox-1.3.2.min.js                                                                                         */
/*----------------------------------------------------------------------------------------------------------------------------------------*/


var $j = jQuery.noConflict();

window.height         = $j(window).height();
window.width          = $j(window).width();
window.documentHeight = $j('#wrapper').height();
window.contentWidth   = $j('div#content').width();

window.querystring = location.search.replace( '?', '' ).split( '&' );
window.queryObj = {};
for(var i=0; i<window.querystring.length; i++ )
{
	var name  = window.querystring[i].split('=')[0];
	var value = window.querystring[i].split('=')[1];
	window.queryObj[name] = value;
}



var Wednesday = 
{
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	getNaturalLanguage:function()
	{
		$j.getJSON
		(
			window.jsonPath,
			function(data)
			{
				window.languageJSON = data;
				Wednesday.init();
			}
		);
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	tabComponents:function()
	{
		//OBJECT DECLARATION
		function TabComponent(el)
		{
			this.component     = el;
			this.tabHeaders    = this.component.find('.tab-header');
			this.tabNavigation = this.component.find('.tab-navigation');
			this.tabLinks      = this.tabNavigation.find('a');
			this.firstTabLink  = this.tabLinks.first();
			this.tabPanels     = this.component.find('div.panel');
			this.firstTabPanel = this.tabPanels.first();
			return this.init();
		}

		//OBJECT METHODS
		TabComponent.prototype =
		{
			init:function()
			{
				this.prepare();
				this.attachTabEvent();
			},

			attachTabEvent:function()
			{
				var that = this;
				this.tabLinks.each
				(
					function()
					{
						$j(this).bind
						(
							'click',
							function(e)
							{
								that.clearLinks();
								that.hidePanels();
								$j(this).attr('class', 'current');
								var hash = 'a' + $j(this).attr('href');
								that.component.find(hash).parent().show().attr('aria-hidden', 'false');
								return false;
							}
						);
					}
				);
			},
			prepare:function()
			{
				/*wai-aria*/
				this.tabPanels.attr("role","tabpanel");
				this.tabNavigation.attr("role","tablist");
				this.tabLinks.attr("role","tab");
				this.tabLinks.each
				(
					function()
					{
						$j(this).attr('id', this.hash.substr(1).replace("anchor", "link"));
					}
				);

				this.tabPanels.each
				(
					function()
					{
						var anchorLink = $j(this).find('a.named-anchor').attr('id').replace("anchor", "link");
						$j(this).attr("aria-labelledby",anchorLink);
					}
				);

				this.tabHeaders.addClass('screen-offset');
				this.hidePanels();
				this.firstTabLink.addClass('current');
				this.firstTabPanel.show().attr('aria-hidden', 'false');
			},
			clearLinks:function()
			{
				this.tabLinks.removeClass('current');
			},

			hidePanels:function()
			{
				this.tabPanels.hide().attr('aria-hidden', 'true');
			}
		};

		//OBJECT INSTANTIATION
		$j('div.tabs').each
		(
			function()
			{
				new TabComponent($j(this));
			}
		);
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	ie6FocusReplication:function()
	{
		$j('body.ie6 a').focus
		(
			function()
			{
				$j(this).addClass('focus');
			}
		)
		.blur
		(
			function()
			{
				$j(this).removeClass('focus');
			}
		);
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	internalLinks:function()
	{
		//OBJECT DECLARATION
		function InternalLinksObject(el)
		{
			//PROPERTIES
			this.__links    = el;
			this.__duration = 1000;
			this.__easing   = 'swing';

			//VARS
			var newHash, target, newLocation, that = this;

			this.__links.bind
			(
				'click',
				function(e)
				{
					e.preventDefault();
					newHash=this.hash;
					target=$j(newHash).offset().top;
					newLocation=this;
					$j('html:not(:animated),body:not(:animated)').animate
					(
						{scrollTop: target},
						that.__duration,
						that.__easing,
						function()
						{
							window.location.href=newLocation;
						}
					);
				}
			);
		}

		//OBJECT INSTANTIATION
		var obj = new InternalLinksObject($j('a[rel="internal"]').not('.tabs a'));
		obj = null;
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	externalLinks:function()
	{
		//OBJECT DECLARATION
		function ExternalLinksObject(el)
		{
			//PROPERTIES
			this.__links    = el;

			//VARS
			var location;

			this.__links.bind
			(
				'click',
				function(e)
				{
					e.preventDefault();
					location = this;
					window.open(location);
				}
			);
		}

		//OBJECT INSTANTIATION
		var obj = new ExternalLinksObject($j('a[rel="ext"]'));
		obj = null;
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	setWaiAria:function()
	{
		//LANDMARK ROLES (application, banner, complimnetary, contentinfo, form, main, navigation, search)
		$j('body').attr("role","application");
		$j('.logo').attr("role","banner");
		$j('#content').attr("role","main");
		$j('.navigation').attr("role","navigation");
		$j('.legal').attr("role","contentinfo");
		$j('form').attr("role","form");

		//DESCRIBEDBY
		var figureElements = $j('div.figure img');
		figureElements.each
		(
			function()
			{
				$j(this).attr("aria-describedby", $j(this).next().attr('id'));
			}
		);
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	googleMap:function()
	{
		if(window.google && $j('div.google-map').length>0)
		{
			//VARS
			var myLatlng, myOptions, map;

			myLatlng = new google.maps.LatLng(-34.397, 150.644);
			myOptions = 
			{
				zoom: 9,
				center: myLatlng,
				mapTypeId: google.maps.MapTypeId.ROADMAP
			};
			map = new google.maps.Map(document.getElementById("google-map-id"), myOptions);
		}
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	formValidations:function()
	{
		//OBJECT DECLARATION
		function FormValidation(el)
		{
			//PROPERTIES
			this.form        = el;
			this.errorsList  = $j('<ul class="list-unsigned errors screen-offset"></ul>');
			this.inputs      = this.form.find('div.input:not(.submit)');
			this.submit      = this.form.find('div.submit input:not(.inactive)');
			this.formError   = false;

			this.form.prepend(this.errorsList);

			//VARS
			var onBlurHandler, that = this;

			this.errorsList.attr
			(
				{
					'aaa:atomic' :"true",
					'aaa:live'   :"polite"
				}
			);

			this.inputs.attr
			(
				{
					'aaa:atomic' :"true",
					'aaa:live'   :"polite"
				}
			);

			onBlurHandler = function(e)
			{
				//VARS
				var targetInput, tag, elementContainer, elementAnchor, shortMessage, longMessage, emailAddress, numeric, hasError, inputError=false, shortErrorString="", longErrorString="", validationTests, $jthis;

				targetInput = e.target;
				tag = targetInput.tagName.toUpperCase();
				if(!(tag === "SELECT" || tag === "INPUT" || tag === "TEXTAREA"|| tag === "DIV"))
				{
					e.stopPropagation();
					return;
				}

				$jthis = $j(targetInput);

				//JAH
				if(tag === "DIV")
				{
					elementContainer = targetInput;
					elementAnchor    = $j(elementContainer).find('.named-anchor').attr('id');
					($j(elementContainer).attr('data-validation')) ? validationTests = $j(elementContainer).attr('data-validation') : validationTests = "";
				}
				else
				{
					elementContainer = targetInput.parentNode;
					elementAnchor    = $j(elementContainer).find('.named-anchor').attr('id');
					($j(elementContainer).attr('data-validation')) ? validationTests = $j(elementContainer).attr('data-validation') : validationTests = "";
				}

				if (validationTests==="")
				{
					return;
				}
				
		                //JAH Insert hack.
		                if(validationTests.match(/checkboxGroup/))
				{
					shortMessage = window.languageJSON.__ERROR_MESSAGES.__CHECKBOXGROUP.short_description;
					longMessage  = window.languageJSON.__ERROR_MESSAGES.__CHECKBOXGROUP.long_description;
					hasError     = true;
					$j("input", elementContainer).each
					(
						function(i,e)
						{
							if($j(e).is(':checked'))
							{
								hasError = false;
								$j('p.error',elementContainer).remove();
							}
						}
					);
		                    	that.setFormError(hasError);
					if(hasError===true)
					{
						inputError = true;
						shortErrorString += " " + shortMessage;
						longErrorString  += " " + longMessage;
			                        $j('p.error',elementContainer).remove();
			                        $j(elementContainer).prepend('<p style="color:#FF0000;" class="error">'+longMessage+'</p>');
					}
		                }
		                //JAH End hack.
                
                if(!(tag === "DIV")) {
                    if(validationTests.match(/mandatory/))
                    {
                        shortMessage = window.languageJSON.__ERROR_MESSAGES.__MANDATORY.short_description;
                        longMessage  = window.languageJSON.__ERROR_MESSAGES.__MANDATORY.long_description;
                        hasError     = !$jthis.val();
                        that.setFormError(hasError);
                        if(hasError===true)
                        {
                            inputError=true;
                            shortErrorString += " " + shortMessage;
                            longErrorString  += " " + longMessage;
                        }
                    }

                    if (validationTests.match(/maximumFourtyCharacters/))
                    {
                        shortMessage = window.languageJSON.__ERROR_MESSAGES.__MAXIMUM_FOURTY_CHARACTERS.short_description;
                        longMessage  = window.languageJSON.__ERROR_MESSAGES.__MAXIMUM_FOURTY_CHARACTERS.long_description;
                        hasError     = that.hasValue(targetInput) && (targetInput.value.length > 40);
                        that.setFormError(hasError);
                        if(hasError===true)
                        {
                            inputError=true;
                            shortErrorString += " " + shortMessage;
                            longErrorString  += " " + longMessage;
                        }
                    }

                    if (validationTests.match(/email/))
                    {
                        shortMessage = window.languageJSON.__ERROR_MESSAGES.__EMAIL.short_description;
                        longMessage  = window.languageJSON.__ERROR_MESSAGES.__EMAIL.long_description;
                        emailAddress =/^([a-zA-Z0-9_.\-])+@([a-zA-Z0-9_.\-])+\.([a-zA-Z])+([a-zA-Z])+/;
                        hasError     = that.hasValue(targetInput) && !emailAddress.test(targetInput.value);
                        that.setFormError(hasError);
                        if(hasError===true)
                        {
                            inputError=true;
                            shortErrorString += " " + shortMessage;
                            longErrorString  += " " + longMessage;
                        }
                    }

                    if (validationTests.match(/numeric/))
                    {
                        shortMessage = window.languageJSON.__ERROR_MESSAGES.__NUMERIC.short_description;
                        longMessage  = window.languageJSON.__ERROR_MESSAGES.__NUMERIC.long_description;
                        numeric      =/^[0-9]+[0-9]*$j/;
                        hasError     = that.hasValue(targetInput) && !numeric.test(targetInput.value);
                        that.setFormError(hasError);
                        if(hasError===true)
                        {
                            inputError=true;
                            shortErrorString += " " + shortMessage;
                            longErrorString  += " " + longMessage;
                        }
                    }
                }

				//ERROR MESSAGING
				if(inputError===true)
				{
					that.errorsList.find('#warning-' + elementAnchor).remove();
					$j(elementContainer).removeClass('valid').addClass('invalid');
					$j('<li id="warning-' + elementAnchor +'">' + '<strong><a href="#' + elementAnchor + '" rel="internal">' + $j(elementContainer).find("label").attr("for", targetInput.id).html() + '</a></strong> ' + longErrorString + '</li>').appendTo('ul.errors');
					Wednesday.internalLinks();
				}
				else
				{
					$j(elementContainer).removeClass('invalid').addClass('valid');
					that.errorsList.find('#warning-' + elementAnchor).remove();
				}
			};

			this.form.bind
			(
				'focusout',
				onBlurHandler
			);
			this.submit.bind
			(
				'click',
				function(e)
				{
					that.form.find("select, input, textarea").each
					(
						function()
						{

							if($j(this).val() == $j(this).attr("placeholder"))
							{
								$j(this).val('');

							}
						}
					)
					that.formError=false;
					that.form.find("select, input, textarea").trigger('focusout');
                                        that.form.find("div.checkbox-row").trigger('focusout');
					that.form.find("select, input, textarea").each
					(
						function()
						{
							if($j(this).val() == "")
							{
								$j(this).val($j(this).attr("placeholder"));
							}
						}
					);

					if(that.formError===true)
					{
						e.preventDefault();

					}
				}
			);
		}

		//OBJECT METHODS
		FormValidation.prototype =
		{
			hasValue: function(input)
			{
				if($j(input).val().length>0)
				{
					return true;
				}
				else
				{
					return false;
				}
			},
			setFormError: function(error)
			{
				if(error===true)
				{
					this.formError = true;
				}
			}
		};

		//OBJECT INSTANTIATION
		$j('.validate').each
		(
			function()
			{
				var obj = new FormValidation($j(this));
				obj = null;
			}
		);
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	carousels:function()
	{
		//OBJECT DECLARATION
		function Carousel(el, options)
		{
			//OBJECT PROPERTIES
			this.__SCROLL_OPTION            = options.scroll;
			this.__DIRECT_NAVIGATION_OPTION = options.directNavigation;
			this.__FLEXIBLE_WIDTH_OPTION    = options.flexibleWidth

			this.scrollTarget               = null;
			this.carousel                   = el;
			this.carouselClip               = this.carousel.find('div.carousel-clip');
			this.carouselList               = this.carouselClip.find('.carousel-items');

			var that                        = this;

			if(this.__FLEXIBLE_WIDTH_OPTION == "true")
			{
				var length = that.carouselList.find('li.carousel-item').length;

				for(iterator=0; iterator<5; iterator++)
				{
					this.carousel.find('li.carousel-item:nth-child(' + iterator +')').clone().addClass(''+iterator +' exclude postfix').attr('id', "").appendTo(this.carouselList);
				}

				var postfixCount=0;
				for(iterator=length; iterator>(length-4); iterator--)
				{
					this.carousel.find('li.carousel-item:nth-child(' + (iterator+postfixCount) +')').clone().addClass(''+ iterator +' exclude prefix').attr('id', "").prependTo(this.carouselList);
					postfixCount++;
				}
			}
			this.carouselListItems          = this.carouselList.find('li.carousel-item');
			this.carouselListItemsFiltered  = this.carouselList.find('li.carousel-item:not(.exclude)');

			this.__COUNT 		        = 0;
			this.__PAGE_COUNT               = 0;


			//ADD DIRECT NAVIGATION
			if(this.__DIRECT_NAVIGATION_OPTION != "false")
			{
				this.directNavigation();
			}

			this.manipulateCarouselList();


			//PROPERTIES
			this.__CAROUSEL_LENGTH         = this.carouselListItemsFiltered.length;
			this.__CAROUSEL_ITEM_WIDTH     = this.getCarouselListItemWidth();
			this.__CAROUSEL_CLIP_WIDTH     = this.carouselClip.width();
			this.__CAROUSEL_VIEWABLE_ITEMS = Math.round(this.__CAROUSEL_CLIP_WIDTH / this.__CAROUSEL_ITEM_WIDTH);

			if(this.__FLEXIBLE_WIDTH_OPTION == "true")
			{
				this.__CAROUSEL_VIEWABLE_ITEMS = 2;
			}
			this.__CAROUSEL_CLONE_NUMBER   =  this.__CAROUSEL_VIEWABLE_ITEMS

			//FINITE SCROLL PROPERTIES
			this.__CAROUSEL_START          = 0;
			this.__CAROUSEL_END            = -(this.getCarouselListWidth() - this.__CAROUSEL_CLIP_WIDTH);


			this.__SLIDE_DURATION = 750;

			this.setCarouselListWidth();
			this.navigation();

			if(this.__DIRECT_NAVIGATION_OPTION != "false")
			{
				this.maintainDirectLinks(this.__COUNT);
			}

			this.highlightCurrent();

			if(this.hasSufficientItems()==true)
			{
				//FINITE PREP
				if(this.__SCROLL_OPTION == "finite")
				{
					this.finiteScrollReset();
				}

				//INFINITE PREP
				if(this.__SCROLL_OPTION == "infinite")
				{
					this.infinitePrefixClones();
					this.infiniteSuffixClones();
				}
				this.attachClickEvents();
			}

			//IF FLEXIBLE WIDTH SET CENTER
			if(this.__FLEXIBLE_WIDTH_OPTION == "true")
			{
				this.setCenterPosition();
			}

			$j(window).bind
			(
				'resize',
				function()
				{
					if(that.__FLEXIBLE_WIDTH_OPTION == "true")
					{
						that.setCenterPosition();
					}
					else
					{
						//fullscreen carousel
						that.setCarouselListWidth();
						that.__CAROUSEL_END            = -(that.getCarouselListWidth() - that.carouselClip.width());
						that.__CAROUSEL_ITEM_WIDTH = that.getCarouselListItemWidth();
						that.carouselList.css('left', -parseInt(that.__CAROUSEL_ITEM_WIDTH * that.__COUNT));
					}
				}
			);
		}


		//OBJECT METHODS
		Carousel.prototype =
		{
			directNavigation:function()
			{
				that = this;
				this.directNavigation = $j('<ul class="list-unsigned list-hor list-hor-divide-1 navigation direct-navigation clearfix"></ul>');
				this.carouselListItemsFiltered.each
				(
					function(index, el)
					{
						var itemCount = parseInt(index + 1);
						if(itemCount<10)
						{
							itemCount = '0' + itemCount;
						}
						that.directNavigation.append
						(
							$j('<li><a href="#" id="' + index + '"">' + '<span class="item-count">' + itemCount + '</span>' +  " " + '<span class="item-label">' + $j(el).find('.item-label').html() + '</span>' + '</a></li>')
						);
					}
				);
				this.directNavigation.appendTo(this.carousel);
				this.directNavigationlinks = this.directNavigation.find('a');
				this.directNavigationlinks.bind
				(
					'click',
					function(e)
					{
						e.preventDefault();
						var index = $j(this).attr('id');
						if(index > that.__COUNT)
						{
							that.scroll("direct", index);
						}
						else if(index < that.__COUNT)
						{
							that.scroll("direct",index);
						}
					}
				);
			},

			getCenterPosition:function()
			{
				var center = $j(window).width() / 2;
				var listItemPosition    = this.carouselListItemsFiltered.eq(this.__COUNT).position();
				var leftPoint           = listItemPosition.left;
				var listItemSize     	= this.carouselListItemsFiltered.eq(this.__COUNT).width();
				var halfWayDimension    = listItemSize/2;
				return (center - (leftPoint + halfWayDimension));
			},

			setCenterPosition:function()
			{
				this.carouselList.css('left', this.getCenterPosition());
			},

			attachClickEvents:function()
			{
				var that = this;
				this.nextLink.bind
				(
					'click',
					function(e)
					{
						that.__CAROUSEL_ITEM_WIDTH  = that.getCarouselListItemWidth();
						that.scroll("relational", "next");
						e.preventDefault();
					}
				);

				this.prevLink.bind
				(
					'click',
					function(e)
					{
						that.__CAROUSEL_ITEM_WIDTH = that.getCarouselListItemWidth();
						that.scroll("relational", "prev");
						e.preventDefault();
					}
				);

				if(this.__DIRECT_NAVIGATION_OPTION != "false")
				{
					this.directNavigationlinks.bind
					(
						'click',
						function(e)
						{
							var index = $j(this).attr('id');
							that.scroll("direct", index);
						}
					);
				}
			},

			scrollResetTrigger:function()
			{
				if(this.__SCROLL_OPTION == "infinite")
				{
					this.infiniteScrollReset();
				}
				if(this.__SCROLL_OPTION == "finite")
				{
					this.finiteScrollReset();
				}
			},

			infiniteScrollReset:function()
			{
				if(this.__COUNT == this.__CAROUSEL_LENGTH)
				{
					this.carouselList.css('left', 0);
					this.__COUNT=0;
					this.maintainDirectLinks(this.__COUNT);
					this.highlightCurrent();
				}
				if(this.__COUNT == -1)
				{
					this.carouselList.css('left', -(this.__CAROUSEL_LENGTH -1) * this.__CAROUSEL_ITEM_WIDTH);
					this.__COUNT=this.__CAROUSEL_LENGTH -1;
					this.maintainDirectLinks(this.__COUNT);
					this.highlightCurrent();
				}
			},

			finiteScrollReset:function()
			{
				this.nextLink.css('display', 'block');
				this.prevLink.css('display', 'block');

				if(this.__COUNT == this.__CAROUSEL_LENGTH-1)
				{
					this.nextLink.css('display', 'none');
					this.prevLink.css('display', 'block');
				}
				if(this.__COUNT == 0)
				{
					this.nextLink.css('display', 'block');
					this.prevLink.css('display', 'none');
				}
			},

			navigation:function()
			{

				this.carouselNavigation = $j('<ul class="list-unsigned navigation relational-navigation"></ul>');
				this.nextListItem = $j('<li class="next"></li>');
				this.prevListItem = $j('<li class="prev"></li>');

				if(this.hasSufficientItems())
				{
					this.nextLink = $j('<a class="replaced" href="#" rel="next" title="' + window.languageJSON.__LINK_TEXT.__CAROUSEL_NEXT.title +'">' + window.languageJSON.__LINK_TEXT.__CAROUSEL_NEXT.text + '</a>');
					this.prevLink = $j('<a class="replaced" href="#" rel="prev" title="' + window.languageJSON.__LINK_TEXT.__CAROUSEL_PREV.title +'">' + window.languageJSON.__LINK_TEXT.__CAROUSEL_PREV.text + '</a>');
					this.nextLink.prependTo(this.nextListItem);
					this.prevLink.prependTo(this.prevListItem);
				}

				this.prevListItem.prependTo(this.carouselNavigation);
				this.nextListItem.prependTo(this.carouselNavigation);
				this.carouselNavigation.appendTo(this.carousel);
			},

			manipulateCarouselList:function()
			{
				this.carouselList.addClass('list-unsigned list-hor clearfix');
			},

			infinitePrefixClones:function()
			{
				var that = this;
				var iterator;
				var cloneIndex = 1;
				for(iterator=0; iterator<that.__CAROUSEL_CLONE_NUMBER; iterator++)
				{
					that.carousel.find('li.carousel-item:nth-child(' + cloneIndex +')').clone().appendTo(that.carouselList).attr('aria-hidden', 'true').addClass('clone clone-prefix clone-prefix-'+ cloneIndex).css({'margin-right': -((iterator+1) * that.__CAROUSEL_ITEM_WIDTH)+"px"});
					cloneIndex ++;
				}
			},

			infiniteSuffixClones:function()
			{
				var that = this;
				var iterator;
				var cloneIndex = that.__CAROUSEL_LENGTH;
				for(iterator=0; iterator<that.__CAROUSEL_CLONE_NUMBER; iterator++)
				{
					that.carousel.find('li.carousel-item:nth-child(' + cloneIndex +')').clone().appendTo(that.carouselList).attr('aria-hidden', 'true').addClass('clone clone-suffix clone-suffix-'+ cloneIndex).css({'margin-left': -((iterator+1) * that.__CAROUSEL_ITEM_WIDTH)+"px"});
					cloneIndex --;
				}
			},

			setCarouselListWidth:function()
			{
				if(this.__FLEXIBLE_WIDTH_OPTION == "false")
				{
					this.carouselList.css('width', this.getCarouselListWidth() + "px");
				}

				if(this.__FLEXIBLE_WIDTH_OPTION == "true")
				{
					var totalWidth = null;
					this.carouselListItems.each
					(
						function()
						{
							totalWidth += $j(this).width();
						}
					)
					this.carouselList.css('width', totalWidth * 4);
				}
			},

			getCarouselListItemWidth:function()
			{
				return this.carouselListItems.first().outerWidth();
			},

			getCarouselListItemCount:function()
			{
				return this.carouselListItems.length;
			},

			getCarouselListWidth:function(carousel)
			{
				return this.getCarouselListItemWidth() * this.getCarouselListItemCount();
			},

			hasSufficientItems:function()
			{
				return (this.__CAROUSEL_VIEWABLE_ITEMS < this.__CAROUSEL_LENGTH);
			},

			maintainDirectLinks:function(index)
			{
				this.directNavigationlinks.removeClass('directLinkCurrent');
				this.directNavigationlinks.eq(index).addClass('directLinkCurrent');
			},

			highlightCurrent:function()
			{
				this.carouselListItemsFiltered.removeClass('current-item');
				this.carouselListItemsFiltered.eq(this.__COUNT).addClass('current-item');
			},

			scroll:function(scrollAmount, scrollDirection)
			{
				if(!(this.carouselList.is(":animated")))
				{
					that = this;
					if(scrollAmount==="relational")
					{
						(scrollDirection==="next") ? this.__COUNT++ : this.__COUNT--;
						if(this.__FLEXIBLE_WIDTH_OPTION == "true")
						{
								//FLEXIBLE WIDTH
								this.__scrollTarget = this.getCenterPosition();
						}
						else
						{
								//FIXED WIDTH
								this.__scrollTarget = -parseInt(this.__CAROUSEL_ITEM_WIDTH * this.__COUNT);
						}
					}
					else
					{
						this.__COUNT = scrollDirection;
						if(this.__FLEXIBLE_WIDTH_OPTION == "true")
						{
							this.__scrollTarget = this.getCenterPosition();
						}
						else
						{
							this.__scrollTarget = -parseInt(this.__CAROUSEL_ITEM_WIDTH * scrollDirection);
						}
					}

					this.carouselList.animate
					(
						{
							left: that.__scrollTarget
						},
						that.__SLIDE_DURATION,
						'easeOutExpo',
						function()
						{
							that.scrollResetTrigger();
						}
					);

					if(this.__DIRECT_NAVIGATION_OPTION != "false")
					{
						this.maintainDirectLinks(this.__COUNT);
					}

					this.highlightCurrent();
				}
			}
		}

		$j('.carousel').each
		(
			function()
			{
				var scroll, directNavigation, flexibleWidth;
				$j(this).attr('data-config-scroll')     ? scroll           = $j(this).attr('data-config-scroll')     : scroll           = "finite";
				$j(this).attr('data-direct-navigation') ? directNavigation = $j(this).attr('data-direct-navigation') : directNavigation = "true";
				$j(this).attr('data-flexible-width')    ? flexibleWidth    = $j(this).attr('data-flexible-width')    : flexibleWidth    = "false";
				var obj = new Carousel
				(
					$j(this),
					{
						'scroll'           : scroll,
						'directNavigation' : directNavigation,
						'flexibleWidth'    : flexibleWidth
					}
				);
			}
		);
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	fancyboxes:function()
	{
		$j("a.fancybox").fancybox
		(
			{
				'padding':'0',
				'opacity' :false,
				'overlayShow':false,
				'titleShow':false,
				'transitionIn':'none',
				'transitionOut':'none',
				'onComplete':function()
				{
					Wednesday.scrollPanes();
				}
			}
		);

		$j("a.fancybox.fancybox-title-inside").fancybox
		(
			{
				'titlePosition':'inside',
				'transitionIn' :'elastic',
				'transitionOut':'elastic'
			}
		);

		$j("a.fancybox.fancybox-title-outside").fancybox
		(
			{
				'titlePosition':'outside',
				'transitionIn' :'elastic',
				'transitionOut':'elastic'
			}
		);

		$j("a.fancybox.fancybox-title-over").fancybox
		(
			{
				'titlePosition':'over',
				'transitionIn' :'elastic',
				'transitionOut':'elastic'
			}
		);

		$j("a.fancybox.fancybox-iframe-content").fancybox
		(
			{
				'autoScale'    :false,
				'height'       :'75%',
				'titlePosition':'over',
				'transitionIn' :'elastic',
				'transitionOut':'elastic',
				'type'         :'iframe',
				'width'	       :'75%'
			}
		);

		$j("a.fancybox[rel=fancybox-group]").fancybox
		(
			{
				'titlePosition': 'over',
				'transitionIn' :'elastic',
				'transitionOut':'elastic',
				'titleFormat'	: function(title, currentArray, currentIndex, currentOpts){return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';}
			}
		);

		$j("a.search").fancybox
		(
			{
				'centerOnScroll':true,
				'hideOnOverlayClick':true,
				'opacity':false,
				'overlayOpacity':0,
				'padding':'0',
				'onStart':function(e)
				{
					$j('html').addClass('search-lightbox');
				},
				'onClosed':function(e)
				{
					$j('html').removeClass('search-lightbox');
				}
			}
		);
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	tooltips:function()
	{
		//PROPERTIES
		this.__toolTipDiv           = $j('<div id="tooltip" aaa:atomic="true" aaa:live="rude"><div id="tooltip-top"></div><div id="tooltip-body"></div></div>');
		this.__toolTipBody          = this.__toolTipDiv.find('#tooltip-body');
		this.__titledElements       = $j('div#primary-navigation a[title], div.homepage-carousel a.item-label[title], div.homepage-carousel a.logo[title]');
		this.__TOOLTIP_WIDTH_OFFSET = 50;

		//VARS
		var that = this;

		this.__toolTipDiv.appendTo($j('div#wrapper'));
		this.__toolTipDiv.hide();

		this.__titledElements.each
		(
			function()
			{
				var __TITLE, __LINK_WIDTH_OFFSET, __LINK_HEIGHT_OFFSET;

				__TITLE              = $j(this).attr('title');
				__LINK_WIDTH_OFFSET  = $j(this).outerWidth() /2;
				__LINK_HEIGHT_OFFSET = 15;

				$j(this).bind
				(
					'mouseenter',
					function()
					{
						$j(this).attr('title', "");
						that.__toolTipBody.html(__TITLE);
						that.__toolTipDiv.show();
					}
				)
				.bind
				(
					'mousemove',
					function(e)
					{
						that.__toolTipDiv.css
						(
							{
								'left': e.pageX - that.__TOOLTIP_WIDTH_OFFSET,
								'top' : e.pageY + __LINK_HEIGHT_OFFSET
							}
						);
					}
				)
				.bind
				(
					'focus',
					function()
					{
						var __LINK_COORDS = $j(this).offset();
						$j(this).attr('title', "");
						that.__toolTipBody.html(__TITLE);
						that.__toolTipDiv.css
						(
							{
								'left': __LINK_COORDS.left + __LINK_WIDTH_OFFSET - that.__TOOLTIP_WIDTH_OFFSET,
								'top' : __LINK_COORDS.top  + __LINK_HEIGHT_OFFSET
							}
						);
						that.__toolTipDiv.show();
					}
				)
				.bind
				(
					'blur mouseout',
					function()
					{
						that.__toolTipDiv.hide();
						$j(this).attr('title', __TITLE);
					}
				);
			}
		);
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	scrollPanes:function()
	{
		$j('div.scroll-pane').each
		(
			function()
			{
				$j(this).jScrollPane
				(
					{
						showArrows: false
					}
				);



				var api = $j(this).data('jsp');
				var throttleTimeout;
				$j(window).bind
				(
					'resize orientationchange',
					function()
					{
						if ($j.browser.msie)
						{
							if (!throttleTimeout)
							{
								throttleTimeout = setTimeout
								(
									function()
									{
										api.reinitialise();
										throttleTimeout = null;
									},
									50
								);
							}
						}
						else
						{
							api.reinitialise();
						}
					}
				);
			}
		);

	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	filteredProjectComponents:function()
	{
		//OBJECT DECLARATION
		function FilteredProjectComponent(el)
		{
			//OBJECT PROPERTIES
			this.__FILTERED_PROJECT_COMPONENT = el;
			this.__PROJECT_FILTER_LINKS       = this.__FILTERED_PROJECT_COMPONENT.find('ul.project-filters a');
			this.__MODULES_CONTAINER          = this.__FILTERED_PROJECT_COMPONENT.find('div.modules');
			this.__MODULES                    = this.__MODULES_CONTAINER.find('div.module');
			this.__PROJECT_MODULES            = this.__MODULES_CONTAINER.find('div.module:not(.module-logo, .module-form)');
			this.__PROJECT_LOGO_MODULE        = this.__MODULES_CONTAINER.find('div.module-logo');
			this.__ORDERED_MODULES            = null;
			this.__CATEGORIES_ARRAY           = new Array();
			this.__selected_category          = "category-all";
			this.__filtered_tag               = false;
			this.__reset_tag                  = null;

			return this.init();
		}

		//OBJECT METHODS
		FilteredProjectComponent.prototype =
		{
			init:function()
			{
				this.populateCategoriesArray();
				this.tagModuleOrder();
				this.setOrderedModules();
				this.attachFiltersLinkClickEvent();
			},

			attachFiltersLinkClickEvent:function()
			{
				var that = this;
				this.__PROJECT_FILTER_LINKS.bind
				(
					'click',
					function(e)
					{
						e.preventDefault();
						that.animateToTop();
						that.__selected_category = this.hash.replace('#', '');
	
						if(that.__selected_category==="category-all")
						{
							that.__reset_tag    = true;
							that.__filtered_tag = false;
							that.resetCategoryAll();
						}
						else
						{
							if(that.__filtered_tag===false)
							{
								that.resetCategorySelection();
								that.__filtered_tag=true;
							}
							else
							{
								if($j(this).hasClass('filtered'))
								{
									that.removeCategory(that.__CATEGORIES_ARRAY[that.__selected_category]);
								}
								else
								{
									that.appendCategory(that.__CATEGORIES_ARRAY[that.__selected_category]);
								}
							}
						}
						$j(this).toggleClass('filtered');
					}
				);
			},

			populateCategoriesArray:function()
			{
				var that = this;
				this.__PROJECT_FILTER_LINKS.each
				(
					function()
					{
						$j(this).data("category", this.hash.replace('#', ''));
						that.__CATEGORIES_ARRAY[$j(this).data("category")] = $j('div.' + $j(this).data("category"));
					}
				);
			},

			tagModuleOrder:function()
			{
				var count=0;
				$j('div.module').each
				(
					function()
					{
						$j(this).attr("id", 'order-' + count);
						count++;
					}
				);
			},

			setOrderedModules:function()
			{
				var orderedModulesString = "";
				for(i=1; i<this.__MODULES.length; i++)
				{
					orderedModulesString += "#order-" + i + ", ";
				}
				this.__ORDERED_MODULES=$j(orderedModulesString);
			},

			animateToTop:function()
			{
					$j('html, body').animate
					(
						{scrollTop: 0},
						200
					);
			},

			clearFilterNavigation:function()
			{
				this.__PROJECT_FILTER_LINKS.removeClass('filtered');
				this.__PROJECT_FILTER_LINKS.first().addClass('filtered');
			},

			resetCategoryAll:function()
			{
				var objectToRemove = $j('div.module:not(.module-logo):not(:hidden)');
				this.removeCategory(objectToRemove);
				this.clearFilterNavigation();
			},

			resetCategorySelection:function()
			{
				var objectToRemove = $j('div.module:not(.module-logo, .module-form):not(.'+ this.__selected_category +')');
				this.removeCategory(objectToRemove);
				this.__PROJECT_FILTER_LINKS.first().removeClass('filtered');
			},

			resetOriginalOrder:function()
			{
				if(this.__reset_tag===true)
				{
					this.appendCategory(this.__ORDERED_MODULES);
					this.__reset_tag=false;
					this.__filtered_tag=false;
					this.clearFilterNavigation();
				}
			},

			appendCategory:function(els)
			{
				var that = this;

				if(this.__reset_tag!=true)
				{
					els.insertAfter(this.__PROJECT_LOGO_MODULE).hide();
				}
				else
				{
					els.each
					(
						function()
						{
							$j(this).appendTo(that.__MODULES_CONTAINER).hide();
						}
					)
				}

				var displayedElementsArray = new Array();
				els.each
				(
					function()
					{
						displayedElementsArray.push(this);
					}
				);

				function play(elements)
				{
					if(elements.length > 0)
					{
						var currentChild = elements.shift();
						$j('a#content-anchor').animate
						(
							{
								opacity: '1'
							},
							100,
							function()
							{
								$j(currentChild).fadeIn(200);
								play(displayedElementsArray);
							}
						);
					}
					else
					{
						$j('a#content-anchor').animate
						(
							{
								opacity: '1'
							},
							300,
							function()
							{
								displayedElementsArray=null;
								return false;
							}
						);
					}
				}
				play(displayedElementsArray);
			},

			removeCategory:function(els)
			{
				var that = this;
				var displayedElementsArray = new Array();

				els.each
				(
					function()
					{
						displayedElementsArray.push(this);
					}
				);

				function play(elements)
				{
					if(elements.length > 0)
					{
						var currentChild = elements.pop();
						$j('a#content-anchor').animate
						(
							{
								opacity: '1'
							},
							100,
							function()
							{
								$j(currentChild).fadeOut(200);
								play(displayedElementsArray);
							}
						);
					}
					else
					{
						$j('a#content-anchor').animate
						(
							{
								opacity: '1'
							},
							300,
							function()
							{
								that.resetOriginalOrder();
								return;
							}
						);
					}
				}
				play(displayedElementsArray);
			}
		};

		//OBJECT INSTANTIATION
		$j('div.project-filtered').each
		(
			function()
			{
				new FilteredProjectComponent($j(this));
			}
		);
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	pagerComponents:function()
	{
		//OBJECT DECLARATION
		function PageComponent(el)
		{
			//OBJECT PROPERTIES
			this.__PAGED_COMPONENT     = el;
			this.__PAGES               = this.__PAGED_COMPONENT.find('div.page');
			this.__PAGES_COUNT_NUMBER  = this.__PAGES.length;
			this.addPageNavigation();
			this.__PAGE_NAVIGATION     = this.__PAGED_COMPONENT.find('a.page-navigation');
			this.__global_count_number = 0;

			this.__FADE_OUT_DURATION  = 250;
			this.__FADE_IN_DURATION   = 250;

			return this.init();
		}

		//OBJECT METHODS
		PageComponent.prototype =
		{
			init:function()
			{
				this.attachPageNavigationEvents();
				this.prepare();
			},

			addPageNavigation:function()
			{
				for(i=1; i<this.__PAGES_COUNT_NUMBER; i++)
				{
					this.__PAGES.eq(i).prepend($j('<p><a class="navigation page-navigation prev" href="#" rel="prev" title="'+ window.languageJSON.__PAGED_LINK_TEXT.__PREV.title +'">'+ window.languageJSON.__PAGED_LINK_TEXT.__PREV.text +'</a></p>'));
				}
				for(i=0; i<this.__PAGES_COUNT_NUMBER-1; i++)
				{
					this.__PAGES.eq(i).append($j('<p><a class="navigation page-navigation next" href="#" rel="next" title="'+ window.languageJSON.__PAGED_LINK_TEXT.__NEXT.title +'">'+ window.languageJSON.__PAGED_LINK_TEXT.__NEXT.text +'</a></p>'));
				}
			},

			attachPageNavigationEvents:function()
			{
				var that = this;
				this.__PAGE_NAVIGATION.bind
				(
					"click",
					function(e)
					{
						e.preventDefault();

						var directionString;
						$j(this).hasClass("next") ? directionString="next" : directionString="prev";
						that.hidePage(directionString);

					}
				);
			},

			prepare:function()
			{
				this.setWaiAria();
				this.hidePages();
				this.showPage();
			},

			setWaiAria:function()
			{
				this.__PAGED_COMPONENT.attr
				(
					{
						'aaa:atomic' :"true",
						'aaa:live'   :"polite"
					}
				);
			},

			hidePages:function()
			{
				this.__PAGES.attr('aria-hidden', 'true').hide();
			},

			hidePage:function(direction)
			{
				var that = this;
				this.__PAGES.eq(this.__global_count_number).fadeOut
				(
					this.__FADE_OUT_DURATION,
					function()
					{
						direction=== "next" ? that.__global_count_number++ : that.__global_count_number--;
						that.showPage();
					}
				);
			},

			showPage:function()
			{

				this.__PAGES.eq(this.__global_count_number).attr('aria-hidden', 'false').fadeIn(this.__FADE_IN_DURATION);
			}
		};

		//OBJECT INSTANTIATION
		$j('div.pager').each
		(
			function()
			{
				new PageComponent($j(this));
			}
		);
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	imageTints:function()
	{
		//OBJECT DECLARATION
		function ImageTintComponent(el)
		{
			//OBJECT PROPERTIES
			this.__IMAGE_TINT_COMPONENT   = el;
			this.__COLOR_IMAGE            = this.__IMAGE_TINT_COMPONENT.find('img.color-image');
			this.__TINTED_IMAGE_CONTAINER = $j('<div class="tinted-image"></div>');
			this.__TINTED_IMAGE_CONTAINER.appendTo(this.__IMAGE_TINT_COMPONENT);

			this.__COLOR_IMAGE.clone().removeClass('color').addClass('desaturated-image').appendTo(this.__TINTED_IMAGE_CONTAINER);

			this.__DESATURATED_IMAGE = this.__IMAGE_TINT_COMPONENT.find('.desaturated-image');
			this.__DESATURATED_IMAGE.pixastic("desaturate");


			this.__OVERLAY_TINT = $j('<span class="tint" /></span>');
			this.__OVERLAY_TINT.appendTo(this.__TINTED_IMAGE_CONTAINER);
		}

		//OBJECT INSTANTIATION
		$j('html.canvas a.color-tint').each
		(
			function()
			{
				new ImageTintComponent($j(this));
			}
		);
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	shareWidgets:function()
	{
		//OBJECT DECLARATION
		function ShareWidget(el)
		{
			//OBJECT PROPERTIES
			this.__SHARE_WIDGET              = el;
			this.__SHARE_LINK                = $j('a.share');
			this.__SHARE_WIDGET_WIDTH_OFFSET = this.__SHARE_WIDGET.outerWidth();
			this.__FADE_DURATION             = 100;

			return this.init();
		}

		ShareWidget.prototype =
		{
			init:function()
			{
				this.prepare();
				this.bindShareLinkEvents();
				this.bindClickOutsideEvent();
				this.positionOnResize();
			},

			prepare:function()
			{
				this.__SHARE_WIDGET.hide();
				$j('html').addClass('share-menu-closed');
			},

			openWidget:function()
			{
				var that = this;
				this.__SHARE_WIDGET.fadeIn
				(
					that.__FADE_DURATION,
					function()
					{
						$j('html').removeClass('share-menu-closed').addClass('share-menu-open');
					}
				);
			},

			closeWidget:function()
			{
				var that = this;
				this.__SHARE_WIDGET.fadeOut
				(
					that.__FADE_DURATION,
					function()
					{
						$j('html').removeClass('share-menu-open').addClass('share-menu-closed');
					}
				);
			},

			positionWidget:function()
			{
				var coords                = this.__SHARE_LINK.offset();
				var shareLinkLeftCoord    = Math.round(coords.left);
				var shareLinkWidthOffset  = Math.round(this.__SHARE_LINK.width()/2);
				var targetLeftPosition    = shareLinkLeftCoord +  shareLinkWidthOffset - this.__SHARE_WIDGET_WIDTH_OFFSET + 18;
				this.__SHARE_WIDGET.css('left',targetLeftPosition);
			},

			bindShareLinkEvents:function()
			{
				var that = this;
				this.__SHARE_LINK.bind
				(
					'click',
					function(e)
					{
						e.preventDefault();
						if($j('html').hasClass('share-menu-closed'))
						{

							that.positionWidget();
							that.openWidget();
						}
						else
						{
							that.closeWidget();
						}
					}
				);
			},

			bindClickOutsideEvent:function()
			{
				var that = this;
				this.__SHARE_WIDGET.bind
				(
					"clickoutside",
					function()
					{
						if($j('html').hasClass('share-menu-open'))
						{
							that.closeWidget()
						}
					}
				);
			},

			positionOnResize:function()
			{
				var that = this;
				$j(window).resize
				(
					function()
					{
						if($j('html').hasClass('share-menu-open'))
						{
							that.positionWidget();
						}
					}
				)
			}
		}


		//OBJECT INSTANTIATION
		$j('div#share').each
		(
			function()
			{
				obj = new ShareWidget($j(this));
			}
		);
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	positionFixedElements:function()
	{
		var movedElements    = $j('div#head, div#content, div#footer, div.page-meta');
		var projectsMenu     = $j('div#projects-menu');
		var __SLIDE_DUARTION = 500;
		var headElement      = $j('div#head');
		var footElement      = $j('div#footer');

		if($j('body').hasClass('ie6'))
		{
			scaleNavigation();
			positionHeader();
			positionFooter();
			positionNavigation();
		}

		if(navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/iPad/i))
		{
			scaleNavigation();
			positionNavigation();
		}

		$j(window).bind
		(
			"scroll resize",
			function()
			{
				if($j('body').hasClass('ie6'))
				{
					scaleNavigation();
					positionHeader();
					positionFooter();
					positionNavigation();
				}

				if(navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/iPad/i))
				{
					scaleNavigation();
					positionNavigation();
				}
			}
		);

		$j('a[rel="projects-menu"]').bind
		(
			'click',
			function(e)
			{
				e.preventDefault();
				if($j('html').hasClass('open-menu'))
				{
					closeMenu();
				}
				else
				{
					openMenu();
				}
			}
		);

		if(navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/iPad/i))
		{
			$j('#content').bind
			(
				"touchstart",
				function()
				{
					if($j('html').hasClass('open-menu'))
					{
						closeMenu();
					}
				}
			);
		}
		else
		{
			projectsMenu.bind
			(
				"clickoutside",
				function(e)
				{
					if($j('html').hasClass('open-menu') && (!projectsMenu.is(":animated")))
					{
						closeMenu();
					}
				}
			);
		}

		function scaleNavigation()
		{
			projectsMenu.css('height', window.height);
		}

		function positionHeader()
		{
			menuHeight     = projectsMenu.height();
			currentScroll  = $j(window).scrollTop();
			if(window.documentHeight>window.height)
			{
				headElement.css('top', currentScroll);
			}
			else
			{
				headElement.css('top', 0);
			}
		}

		function positionFooter()
		{
			footerHeight    = $j('#footer').outerHeight();
			currentScroll  = $j(window).scrollTop();
			if(window.documentHeight>window.height)
			{
				if(currentScroll < (documentHeight-footerHeight))
				{
					footElement.css('top', (currentScroll + window.height - footerHeight));
				}
			}
		}

		function positionNavigation()
		{
			menuHeight     = projectsMenu.height();
			currentScroll  = $j(window).scrollTop();
			if(window.documentHeight>window.height)
			{
				if(currentScroll < (window.documentHeight-menuHeight))
				{
					projectsMenu.css('top', currentScroll);
				}
				else
				{
					projectsMenu.css('top', (window.documentHeight-menuHeight));
				}
			}
			else
			{
				projectsMenu.css('top', 0);
			}
		}

		function openMenu()
		{
			$j('html').addClass('open-menu');
			if(navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/iPad/i))
			{
				projectsMenu.css('opacity',1);
			}
			else
			{
				projectsMenu.animate
				(
					{
						'margin-left':0
					},
					__SLIDE_DUARTION,
					'easeOutExpo'
				);
				movedElements.animate
				(
					{
						'margin-left': 334
					},
					__SLIDE_DUARTION,
					'easeOutExpo'
				);
			}
		}

		function closeMenu()
		{
			if(navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/iPad/i))
			{
				projectsMenu.css('opacity',0);
				$j('html').removeClass('open-menu');
			}
			else
			{
				projectsMenu.animate
				(
					{
						'margin-left':-334
					},
					__SLIDE_DUARTION,
					'easeOutExpo',
					function()
					{
						$j('html').removeClass('open-menu');
					}
				);
				movedElements.animate
				(
					{
						'margin-left':0
					},
					__SLIDE_DUARTION,
					'easeOutExpo'
				);
			}
		}
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	scaleFullScreenCarousels:function()
	{
		if($j('div.full-screen-carousel').length>0)
		{

			function scaleCarousels()
			{
				$j('div.full-screen-carousel div.carousel-clip, div.full-screen-carousel div.carousel-clip li.carousel-item').css('width', window.width);
				$j('div.full-screen-carousel .clone-suffix').css('margin-left', -(window.contentWidth));
				$j('div.full-screen-carousel .clone-prefix').css('margin-right', -(window.contentWidth));
			}
			scaleCarousels();
			$j(window).bind
			(
				'resize',
				function()
				{
					scaleCarousels();
				}
			)
		}
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	formPlaceholders:function()
	{
		Placeholder.init
		(
			{
				normal      : "#666666",
				placeholder : "#666666"
			}
		);
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	scaleZoomModules:function()
	{
		scale = function()
		{
			winWidth = $j('html.template-project-zoom div.module:not(:hidden)').first().width();
			$j("html.template-project-zoom div.module").css("font-size", (winWidth/500)*100 + "%");
		}
		scale();
		$j(window).resize
		(
			function()
			{
				scale();
			}
		);
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	printPage:function()
	{
		$j('a[rel="print"]').bind
		(
			'click',
			function(e)
			{
				e.preventDefault();
				window.print();
			}
		);
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	formResponses:function()
	{
		$j('form').submit
		(
			function(e)
			{
				e.preventDefault();
	 	                
	 	        var form = $j(this);
	 	        //JAH Disabled form while ajax is loading to stop lots of requests.
	 	        $j(".submit input", form).val('loading');
	 	        $j(".submit input", form).attr('disabled', 'disabled');
				url = form.attr('action');
				$j.post
				(
					url,
					form.serialize(),
					function(data)
					{
						$j(form).parent().parent().empty().append(data).hide().fadeIn(1000);
					}
				);
			}
		);
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	checkAllInput:function()
	{
		//OBJECT DECLARATION
		function CheckAllInput(el)
		{
			//OBJECT PROPERTIES
			this.__CHECK_ALL_INPUT = el;
			this.__RELATED_CHECKBOXES = $j('input.' + this.__CHECK_ALL_INPUT.attr('rel'));

			return this.init();
		}

		CheckAllInput.prototype =
		{
			init:function()
			{
				this.assignChangeEvents();
			},

			assignChangeEvents:function()
			{
				var that = this;
				this.__RELATED_CHECKBOXES.change
				(
					function()
					{
						if(that.getAllChecked())
						{
							that.__CHECK_ALL_INPUT.attr('checked', true);
						}
						else
						{
							that.__CHECK_ALL_INPUT.attr('checked', false);
						}
					}
				);

				this.__CHECK_ALL_INPUT.change
				(
					function()
					{
						if($j(this).is(':checked'))
						{
							that.__RELATED_CHECKBOXES.attr('checked', true);
						}
						else
						{
							that.__RELATED_CHECKBOXES.attr('checked', false);
						}
					}
				);
			},

			getAllChecked:function()
			{
				var allChecked = true;
				this.__RELATED_CHECKBOXES.each
				(
					function()
					{
						if(!$j(this).is(':checked'))
						{
							allChecked = false;
						}
					}
				);
				return allChecked;
			}
		};


		//OBJECT INSTANTIATION
		$j('input.check-all').each
		(
			function()
			{
				obj = new CheckAllInput($j(this));
			}
		);
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	projectZoom:function()
	{
		$j('a.overlay').bind
		(
			'click',
			function(e)
			{
				e.preventDefault();
				var element = $j(this).parent();

				if(!$j('html').hasClass('template-project-zoom'))
				{
					$j('html').addClass('template-project-zoom');
					Wednesday.scaleZoomModules();

					var displayedModules = $j('div.module-graphic:not(:hidden), div.module-graphic-annotated:not(:hidden)');
					displayedModules.each
					(
						function()
						{
							var defaulImage     = $j(this).find('img.size-default');
							var defaultImageSrc = defaulImage.attr('src');
							if($j(this).find('img.size-zoomed').length===0)
							{
								var zoomedImage = new Image();
								zoomedImage.src = defaultImageSrc.replace("medium","large");
								$j(zoomedImage).addClass('size-zoomed').insertAfter(defaulImage);
							}
						}
					);
					elementOffset = element.offset();
					$j('html, body').scrollTop(elementOffset.top);
				}
			}
		);


		$j('a.close').bind
		(
			'click',
			function(e)
			{
				e.preventDefault();
				$j('html').removeClass('template-project-zoom');
				$j('div.module').css('font-size', '100%');
				$j('html, body').scrollTop(0);
			}
		);
	},


	/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
	init:function()
	{
		this.pagerComponents();
		this.tabComponents();
		this.scaleFullScreenCarousels();
		this.carousels();
		this.googleMap();
		this.fancyboxes();
		this.setWaiAria();
		this.ie6FocusReplication();
		this.formValidations();
		this.internalLinks();
		this.externalLinks();
		this.tooltips();
		this.scrollPanes();
		this.filteredProjectComponents();
		this.positionFixedElements();
		this.shareWidgets();
		this.formPlaceholders();
		this.formResponses();
		this.printPage();
		this.projectZoom();
		this.checkAllInput();
	}
}


$j(document).ready
(
	function()
	{
		Wednesday.getNaturalLanguage();
	}
);


$j(window).load
(
	function()
	{
		Wednesday.imageTints();
		$j('div#preloader-mask').delay(1500).fadeOut(500);
		$j(document).trigger('resize scroll');
	}
);


$j(window).bind
(
	'resize',
	function()
	{
		window.height         = $j(window).height();
		window.width          = $j(window).width();
		window.documentHeight = $j('#wrapper').height();
		window.contentWidth   = $j('div#content').width();
	}
);
