(function($) {

	"use strict";

	function festate_mainMenuClear() {

		if ( $(window).width() >= 800 ) {
		
			$('#navmain > div > ul > li:has("ul")').removeClass('level-one-sub-menu');
			$('#navmain > div > ul li ul li:has("ul")').removeClass('level-two-sub-menu');										
		}

		if ( $('ul:first-child', $('#navmain > div') ).is( ":visible" ) ) {

			$('ul:first-child', $('#navmain > div') ).css('display', '');
		}
	}

	function festate_mainMenuInit() {

		if ( $(window).width() >= 800 ) {
		
			$('#navmain > div > ul > li:has("ul")').addClass('level-one-sub-menu');
			$('#navmain > div > ul li ul li:has("ul")').addClass('level-two-sub-menu');										
		}
	}

	$( document ).ready(function() {

		festate_mainMenuInit();

		$('#navmain > div').on('click', function(e) {

			e.stopPropagation();

			// toggle main menu
			if ( $(window).width() < 800 ) {

				var parentOffset = $(this).parent().offset(); 
				
				var relY = e.pageY - parentOffset.top;
			
				if (relY < 36) {
				
					$('ul:first-child', this).toggle(400);
				}
			}
		});

		// re-init main menu on screen resize
		$(window).resize(function () {
	       
	    	festate_mainMenuClear();
	    	festate_mainMenuInit();
		});

		$('.scrollup').click(function () {
			
			$("html, body").animate({
				  scrollTop: 0
			  }, 600);

			return false;
		});

		$(window).scroll(function () {

			var fadeInScrollUp = $(this).scrollTop() > 100;

			if (fadeInScrollUp) {

				$('.scrollup').fadeIn();

			} else {

				$('.scrollup').fadeOut();

			}
		});

		// display slider
		$( '.sldr' ).each( function() {
			var th = $( this );
			th.sldr({
				focalClass    : 'focalPoint',
				offset        : th.width() / 2,
				sldrWidth     : 'responsive',
				nextSlide     : th.nextAll( '.sldr-nav.next:first' ),
				previousSlide : th.nextAll( '.sldr-nav.prev:first' ),
				selectors     : th.nextAll( '.selectors:first' ).find( 'li' ),
				toggle        : th.nextAll( '.captions:first' ).find( 'div' ),
				sldrAuto      : false,
				sldrTime      : 4500,
				hasChange     : true
			});
		});
	});

})(jQuery);