$(document).ready(function()
{
	$('#navigation li').hover(function()
	{
	      $(this).addClass('hover');
	},
	function()
	{
	      $(this).removeClass('hover');
	});


	// The reason this is done in JS and not in XSLT
	// If we move all of the children items of "Facilities Overview" and "Precincts Overview" underneith the Overview pages in the CMS then the
	// xlst that generates the inner page navigation will hide the child pages until their parent is actually selected, which is not what the client wants.
	// If we automatically show all the client items then ALL the client items will have to appear in all cases, which is what we do not want.

	var newUl = null;
	$('ul:first > li', $('ul#navigation li a[href=/Facilities-%26-Precincts/]').parent()).each(function()
	{
	   
	    if( $('a:first', $(this)).text() == 'Facilities Overview' || $('a:first', $(this)).text() == 'Precincts Overview' )
	    {
	        newUl = $('<ul />');

	        $(this).append(newUl);
	    }
	    else
	    {
	        if( newUl != null )
	        {
	           newUl.append($(this));
	        }
	    }
	});



	/*Cufon.replace('div.homepage-heading', { fontFamily: 'DINWebCondensedMedium' });

	Cufon.replace('div#hero-container div#hero-title a', { fontFamily: 'DINWebLight' });
	Cufon.replace('div#hero-container div#hero-date', { fontFamily: 'DINWebCondensedMedium' });
	Cufon.replace('div#hero-container div#hero-departments div.hero-department span', { fontFamily: 'DINWebCondensedMedium' });

	Cufon.replace('div#inner-content-navigation-title', { fontFamily: 'DINWebCondensedMedium' });
	Cufon.replace('div#inner-content-navigation-container div.sidebar_module div.news h2', { fontFamily: 'DINWebCondensedMedium' });

	Cufon.replace('h4, h4 a', { fontFamily: 'DINWebCondensedMedium' });


	Cufon.replace('div#industry-information-container div.col-header', { fontFamily: 'DINWebCondensedMedium' });*/


	if( $('#business_list').length > 0 )
	{
		var navigation_type_list = ['All', 'Fabrication', 'Services', 'Ship Builders', 'Suppliers'];

		$.each(navigation_type_list, function(index, value)
		{
			var btn = $('<div class="navigation-row group"><div class="navigation-icon"><img width="22" height="23" src="/_image/common/btn_arrow.png" alt=""></div><div class="navigation-text"><strong><a href="#" title="' + value + '">' + value + '</a></strong></div></div>');

			$('div.inner-content-navigation:first').append(btn);
		});


		// Business type onClick bind
		$('div.inner-content-navigation:first a').click(function()
		{
			// Remove the a-z highlighting
			$('#business_directory_a_z a').removeClass('selected');

                        $('div.inner-content-navigation:first a').removeClass('active');
			$.get('api/', { type: $(this).attr('title') },
			function(data) {
			  $('#business_list').html(data);
			});

			$(this).addClass('active');
		});


		// A-Z alphabetical characters onClick bind
		$('#business_directory_a_z a').click(function()
		{
			// Remove the a-z highlighting
			$('#business_directory_a_z a').removeClass('selected');
			$('div.inner-content-navigation:first a').removeClass('active');

			// Mark this link as 'selected'
			$(this).addClass('selected');

			// Load the data
			$.get('api/', { alpha: $(this).attr('title') },
			function(data) {
			  $('#business_list').html(data);
			});
		});


		// Initialy load all the businesses
		$.get('api/', function(data)
		{
			$('#business_list').html(data);
		});


	}

	$('.navigation-text:last').addClass('navigation-text-last');

	$('#most-visited-pages-box p').wrap('<div>');
	$('#most-visited-pages-box div:odd').addClass('news-row-odd');
	$('#most-visited-pages-box div:even').addClass('news-row-even');
});
