/**
* © 2010-2020, 11Eleven Development, LLC (http://www.11elevendevelopment.com)
* All Rights Reserved
*
* Author: Paul Furiani
*
**/

/*scroll to function*/
function scollToId(id) {
   window.scrollTo(0,$("#"+id).offset().top);
}

var contactMenuHasFocus = false;

function slider11_change_project(groupID) {
	$('.bottom-nav .submenu a').removeClass('selected');
	$('.bottom-nav .submenu a#' + groupID + '-nav-link').addClass('selected');
	groupID = groupID + '-group';
	$('#slider11-container').slider11('gotoGroupById', {'gotoGroupById':groupID});
}

function updateSubmenuSelected() {
	theID = $('#slider11-container .slider11-current-group').attr('id');
	theID = theID.substr(0, theID.length - 6);
	$('.bottom-nav .submenu a').removeClass('selected');
	$('.bottom-nav .submenu a#' + theID + '-nav-link').addClass('selected');
}

$(document).ready(function() {
	$('#slider11-container').hover(function(event) {
			$('#slider11-container').slider11('stopAutoScroll');
			$(this).find('.slider-overlay').stop(true).animate({opacity: 0}, 200, function() { $(this).hide()});
		}, function(event) {
			$(this).find('.slider-overlay').stop(true).show().animate({opacity: 0.5}, 200);
			$('#slider11-container').slider11("startAutoScroll");
	});

	$('#slider11-container').slider11();

	/* setup subnavs */
    $('.top-nav-link .contact-form input, .top-nav-link .contact-form textarea').focusin(function() {
        //contactMenuHasFocus = true;
    });

    $('.top-nav-link .contact-form input, .top-nav-link .contact-form textarea').focusout(function() {
        //contactMenuHasFocus = false;
    });


	$('.top-nav-link').hover(
		function () {
			//if(!contactMenuHasFocus) {
				$('.top-nav-link').children('a:not(.contact-form-link a)').removeClass('hover');
				$(this).children('a').addClass('hover');
				//$('.top-nav-link').children('.submenu').hide();
				$(this).children('.submenu').show();
			//}
		},
		function () {
			// do nothing
		}
	);

	$('.nav-link').hover(
		function () {
			$('.nav-link').children('a').removeClass('hover');
			$(this).children('a').addClass('hover');
			$('.nav-link').children('.submenu').hide();
			$(this).children('.submenu').show();
		},
		function () {
			// do nothing
		}
	);

	$('.top-nav').hover(
		function() {
			// do nothing
		},
		function() {
			if(!contactMenuHasFocus) {
				//$('.top-nav-link').children('.submenu').hide();
				$('.top-nav-link').children('a:not(.contact-form-link a)').removeClass('hover');
			}
		}
	);

	$('.top-nav-link .submenu .submenu-close-button').click(function() {
			$(this).parent().prev().removeClass('hover');
			$(this).parent().hide();
		});

	$('.bottom-nav').hover(
		function() {
			// do nothing
		},
		function() {
			$('.nav-link').children('.submenu').hide();
			$('.nav-link').children('a').removeClass('hover');
		}
	);

	// this will be appended to the slider11 click function

	$('#slider11-container').find('.slider11-prev').click(function() {
		updateSubmenuSelected();
		return true;
	});

	$('#slider11-container').find('.slider11-next').click(function() {
		updateSubmenuSelected();
		return true;
	});

	if(location.hash) {
		//$('#slider11-container').slider11('gotoGroupById', location.hash.substr(1));
		//$('.bottom-nav #' + location.hash.substr(1) + '-nav-link').click();
		slider11_change_project(location.hash.substr(1));
	}
});
