$(
	function () {

		var menuWidth = parseInt($('.YELLOW_topmenu').width());
		var itemPadding = parseInt($('.YELLOW_topmenu').find('li').css('padding-left')) + parseInt($('.YELLOW_topmenu').find('li').css('padding-right'));
		var maxSlideWidth = menuWidth - 50;

		var items = $('.YELLOW_topmenu').find('li');
		var nbItems = items.length;
		var slideWidth = 0;
		var slideIndex = 1;
		var currentSlideIndex = 1;
		var slide = null;

		items.each(
			function (index, item) {
				currentSlideIndex = slideIndex;
				slideWidth += parseInt($(item).width()) + itemPadding;
				if (slideWidth > maxSlideWidth) {
					//Create new slide (only if not sufficient place for last item).
					if (!(index + 1 == nbItems && (slideWidth - 50) <= maxSlideWidth)) {
						//Update maxSlideWith to support more and less links.
						maxSlideWidth = menuWidth - 2 * 75 - itemPadding;
						//Increment slide index.
						slideIndex++;
						//Create new slide.
						slide = $('<ul id="slide' + slideIndex +'" class="YELLOW_topmenu"></ul>');
						//Reset slideWidth;
						slideWidth = parseInt($(item).width()) + itemPadding;
						//Add class to item.
						$(item).addClass('YELLOW_topmenu_first');
					}
				}
				if (slideIndex > 1) {
					slide.append($(item));
				}

				//New slide added, add slide to horizontal menu and add navigation links.
				if (currentSlideIndex != slideIndex) {
					$('.dYELLOW_section').append(slide);
					slide.prepend('<li id="YELLOW_LESS_BUT"><a href="javascript: void(0);"><< ' + menu_less + '</a></li>');
					slide.prev().append('<li id="YELLOW_MORE_BUT"><a href="javascript: void(0);">' + menu_more + ' >></a></li>');
					if (slideIndex > 1) {
						slide.hide();
					}
				}
			}
		);

		$('#YELLOW_MORE_BUT').live(
			'click',
			function (e) {
				e.preventDefault();
				var slide = $(this).parents('ul');
				var next = slide.next(); 
				slide.hide(
					'slide',
					{
						direction: 'left'
					},
					function () {
						next.show();
					}
				);
			}
		);
		$('#YELLOW_LESS_BUT').live(
			'click',
			function (e) {
				e.preventDefault();
				var slide = $(this).parents('ul');
				var prev = slide.prev();
				slide.hide(
					'slide',
					{
						direction: 'right'
					},
					function () {
						prev.show();
					}
				);
			}
		);

		$('.category span').click(
			function () {
				var cat = $(this);
				var ul = cat.siblings('ul');
				if (ul.is(':visible')) {
					ul.hide();
				} else {
					ul.show();
				}
			}
		)

		$('.page' + page).parents('ul').show();
	}
);

function is_ie6 () {
	return ((window.XMLHttpRequest == undefined) && (ActiveXObject != undefined));
}
