var LINEUKCOM = {
	navigation: {
		timer: false,
		inAction: false,

		init: function() {
			// Move the navigation to the header.
			jQuery('#our_work').wrap('<div id="our_work_wrapper"></div>');
			jQuery('#our_work_wrapper').appendTo(jQuery('#header .constrain'));
			// Remove the #tab link; replace with a span.
			jQuery('#tab').replaceWith('<span id="tab">Our work</span>');

			// Add a class to the #our_work element each time a
			// navigation anchor is hovered over; remove the class once
			// the mouse moves away.
			jQuery('#our_work a').hover(
				function(eventObject) {
					var elementId = jQuery(this).parent('li').get(0).id;
					jQuery('#our_work').addClass(elementId);
				},
				function(eventObject) {
					var elementId = jQuery(this).parent('li').get(0).id;
					jQuery('#our_work').removeClass(elementId);
				}
			);

			jQuery('#header,#tab,#phone').hover(
				LINEUKCOM.navigation.showNav,
				LINEUKCOM.navigation.hideNav
			);
			jQuery('#main').hover(
				LINEUKCOM.navigation.hideNav,
				function() {}
			);
		},

		showNav: function() {
			// When the header or the 'Our work' tab are hovered over,
			// display the navigation.
			if (!LINEUKCOM.navigation.inAction) {
				window.clearTimeout(LINEUKCOM.navigation.timer);
				LINEUKCOM.navigation.timer = setTimeout(
					function() {
						// If we're on the home page, stop the carousel
						// animation.
						var flash = jQuery('#carousel_flash').get(0);
						if (flash != undefined && !jQuery.browser.msie) {
							flash.JS2AS_StopRender();
						}
						jQuery('#tab').addClass('on');
						LINEUKCOM.navigation.inAction = true;
						jQuery('#our_work_wrapper').slideDown(400, function() {LINEUKCOM.navigation.inAction = false;});
					},
					200
				);
			}
		},

		hideNav: function() {
			// When the mouse pointer leaves the header or 'Our work'
			// elements, hide the navigation.
			if (!LINEUKCOM.navigation.inAction) {
				window.clearTimeout(LINEUKCOM.navigation.timer);
				LINEUKCOM.navigation.timer = setTimeout(function() {
					jQuery('#tab').removeClass('on');
					LINEUKCOM.navigation.inAction = true;
					jQuery('#our_work_wrapper').slideUp(400, function() {
						LINEUKCOM.navigation.inAction = false;
						// If we're on the home page, start the carousel
						// animation.
						var flash = jQuery('#carousel_flash').get(0);
						if (flash != undefined && !jQuery.browser.msie) {
							flash.JS2AS_ContinueRender();
						}
					});
				}, 200);
			}
		}
	},

	pages: {}
};

jQuery(document).ready(function(){
	LINEUKCOM.navigation.init();
});
