$(function () {
	Nortech = {
		titleAnimation: function (el) {
			$(el).hover(
				function () {
					$(this).stop(true, true).animate({ paddingLeft: '5px' }, 'fast');
				},
				function () {
					$(this).stop(true, true).animate({ paddingLeft: '0px' }, 'fast');
				}
			);
		},

		searchBox: function (el) {
			var $el = $(el);
			var defaultVal = lang_SearchBoxDefaultText;

			$el.val(defaultVal);
			
			$el.focusin(function () {
				if ($el.val() == defaultVal) {
					$el.val('')
				}
			});

			$el.focusout(function () {
				if ($el.val() == '') {
					$el.val(defaultVal)
				}
			});
		},

		newsList: function () {
			$('.news-list-item').each(function () {
				var link = $(this).children('.more').attr('href');

				$(this).wrap('<a href="' + link + '" class="news-list-wrapper"></a>');
			});

		},

		flyoutNav: function () {
			$('.main-nav .lvl-one-CMSListMenuUL')
			.wrap('<div class="flyout-nav-wrapper"></div>')
			.wrap('<div class="flyout-nav"></div>');

			$('.main-nav > ul > li').hover(
				function () {
					($.browser.msie) ? $(this).find('.flyout-nav-wrapper, .lvl-one-CMSListMenuUL').show() : $(this).find('.flyout-nav-wrapper, .lvl-one-CMSListMenuUL').stop(true, true).delay(400).fadeIn('fast');
				},
				function () {
					($.browser.msie) ? $(this).find('.flyout-nav-wrapper, .lvl-one-CMSListMenuUL').hide() : $(this).find('.flyout-nav-wrapper, .lvl-one-CMSListMenuUL').stop(true, true).fadeOut('fast');
				}
			);
		},

		servicesNav: function () {
			var otherServices = $('.main-nav .services .lvl-one-CMSListMenuUL > li').not('.medical-service');
			otherServices.wrapAll('<li class="lvl-one-CMSListMenuLI other-services"><ul></ul></li>');

			$('.main-nav .other-services').prepend('<a href="#" class="lvl-one-CMSListMenuLink">' + lang_OtherServicesMenuTitle + '</a>');

			$('.main-nav .other-services > ul').css('display', 'none');
			$('.main-nav .other-services > a').addClass('unselected');

			$('.main-nav .medical-service > a, .main-nav .other-services > a').hover(function () {
				var siblingItem = $(this).parent().siblings('li');

				$(this).removeClass('unselected');
				siblingItem.children('a').addClass('unselected');

				$(this).siblings('ul').css('display', 'block');
				siblingItem.children('ul').css('display', 'none');
			});
		},

		imageFloat: function () {
			$('.main-content p img').each(function () {
				var imgFloat = $(this).css('float');
				if (!($(this).hasClass())) {
					$(this).addClass(imgFloat);
				}
				// !($(this).hasClass()) ? ($(this).addClass(imgFloat)) : ;
			});
		},

		tabs: function () {
			$('.table-tabs').each(function (index) {
				var len = $(this).children('dt').length;

				$(this).after('<div class="table-tabsUL" id="TableTabsUL' + index + '"></div>');

				var that = $('#TableTabsUL' + index);

				that.append('<ul class="headers"></ul>');
				that.append('<ul class="desc"></ul>');

				for (var i = 0; i < len; i++) {
					that.children('.headers').append('<li class="headers-' + i + '">' + $(this).children('dt').eq(i).html() + '</li>');
					that.children('.desc').append('<li class="desc-' + i + '">' + $(this).children('dd').eq(i).html() + '</li>');
				}

				$(this).hide();

				var descItem = that.find('.desc li');
				descItem.not('.desc-0').css('display', 'none');

				var current = $('.headers-0');
				current.addClass('highlight2')

				that.find('.headers li').click(function () {
					current.removeClass('highlight2');
					current = $(this);
					current.addClass('highlight2');

					descItem.css('display', 'none');
					var itemIndex = $(this).index();
					descItem.eq(itemIndex).css('display', 'block');
				});
			});
		}
	}

	Nortech.titleAnimation('#latest-news h4 a, #announcements h4 a');
	Nortech.searchBox('.search-input');
	Nortech.newsList();
	Nortech.flyoutNav();
	Nortech.servicesNav();
	$(".main-nav #menuElem").css("visibility", "visible");
	Nortech.imageFloat();
	Nortech.tabs();

	//banners
	$('.banners ul').cycle({
		fx: 'fade',
		speed: 'slow',
		prev: '.prev',
		next: '.next',
		pager: '.numeration'
	});

	//ie conditionals
	//if (parseInt(jQuery.browser.version) == 7) {

	//};
});

