﻿$(document).ready(function () {
	LoadSizes();
	FilloutMenu();

	$('.GalleryFilterHeader').click(function () {
		var visible = $(this).next('.GalleryFilterItems').is(':visible');

		if (!visible) {
			$('.GalleryFilterItems:visible').slideUp();
			$(this).next('.GalleryFilterItems').slideDown();
		}
		else {
			$(this).next('.GalleryFilterItems').slideUp();
		}
	});

	LoadGalleryFilter();
	window.setTimeout(function () {
		LoadSizes();
	}, 100);

});

$(window).resize(function () {
	LoadSizes();
});

function LoadGalleryFilter() {
	$('.GalleryLinkActive,.GalleryFilterExpandItems').each(function () {
		if ($(this).parents(".GalleryFilterItems").size() > 0) {
			$(this).parents(".GalleryFilterItems").show();
		}
	});
};

function FilloutMenu() {
	var $menuInner = $('#menuInnerDiv');
	var $rmuMenu = $('#menuInnerDiv #rmuMenu');
	var spaceLeft = ($menuInner.width()) - ($rmuMenu.width());
	var menuItems = $rmuMenu.find('ul.rmRootGroup > li.rmItem').length;
	var paddingPerItem = Math.floor(spaceLeft / (menuItems * 2));

	if (paddingPerItem > 0) {
		var pleft = parseInt($rmuMenu.find('ul.rmRootGroup > li.rmItem > a > span').css('paddingLeft').replace('px', '')) + paddingPerItem;
		var pright = parseInt($rmuMenu.find('ul.rmRootGroup > li.rmItem > a > span').css('paddingRight').replace('px', '')) + paddingPerItem;

		$rmuMenu.find('ul.rmRootGroup > li.rmItem > a > span').css({
			'padding-right': pright + 'px',
			'padding-left': pleft + 'px'
		});
	}

	spaceLeft = ($menuInner.width()) - ($rmuMenu.width());

	if (spaceLeft >= menuItems) {
		var padding = parseInt($rmuMenu.find('ul.rmRootGroup > li.rmItem > a > span').css('paddingRight').replace('px', '')) + 1;

		$rmuMenu.find('ul.rmRootGroup > li.rmItem > a > span').css({
			'padding-right': padding + 'px'
		});
	}
	$rmuMenu.css('visibility', 'visible');
};

function LoadSizes() {
	$('.ContentClearingDiv').css({
		'height': '100%'
	});
	$('.ContentClearingDivNoStroke').css({
		'height': '100%'
	});
	$('.ContentClearingDivHome').css({
		'height': '100%'
	});

	SetGalleryListHeight();
	SetFleetDetailHeight();
	SetClearingScrollHeight();
	SetClearingHeight();
	$('.GoogleWebSearchControlDiv').css('visibility', 'visible');
};

function SetClearingScrollHeight() {
	$('div.ClearingScrollDiv').css({
		'height': 'auto',
		'overflow-y': 'visible'
	});

	var maxHeight = ($(window).height() - 170);
	var currentHeight = ($('div.ClearingScrollDiv').height());

	if (currentHeight > maxHeight) {
		$('div.ClearingScrollDiv').css({
			'height': ($(window).height() - 170) + 'px',
			'overflow-y': 'scroll'
		});
	}
};

function SetFleetDetailHeight() {
	var footerHeight = ($('div.FleetDetailFooterDiv').height());
	var maxHeight = ($(window).height() - 150) - footerHeight;
	var currentFleetHeight = $('div.FleetShowContentInnerDiv').innerHeight();

	if (currentFleetHeight >= maxHeight) {
		$('div.FleetShowContentDiv').css({
			'height': maxHeight + 'px',
			'overflow-y': 'scroll',
			'overflow-x': 'hidden'
		});
	}
	else {
		$('div.FleetShowContentDiv').css({
			'height': maxHeight + 'px',
			'overflow-y': 'visible',
			'overflow-x': 'visible'
		});
	}
	$('div.FleetShowContentDiv').css('visibility', 'visible');
};

function SetGalleryListHeight() {
	$('div.GalleryListDiv').css({
		'height': 'auto',
		'overflow-y': 'visible'
	});

	var maxHeight = ($(window).height() - 170);
	var currentHeight = ($('div.GalleryListDiv').height());

	if (currentHeight > maxHeight) {
		$('div.GalleryListDiv').css({
			'height': maxHeight + 'px',
			'overflow-y': 'scroll'
		});
	}
};

function SetClearingHeight() {
	var dHeight = $(document).height() - 4;
	var wHeight = $(window).height();
	if (wHeight >= dHeight) {
		$('.ContentClearingDiv').css({
			'height': ($(window).height() - 90) + 'px'
		});
		$('.ContentClearingDivNoStroke').css({
			'height': ($(window).height() - 90) + 'px'
		});
		$('.ContentClearingDivHome').css({
			'height': ($(window).height() - 90) + 'px'
		});
	}
};
