/* Minification failed. Returning unminified contents.
(1,1): run-time error CSS1019: Unexpected token, found '$'
(1,2): run-time error CSS1019: Unexpected token, found '('
(1,9): run-time error CSS1031: Expected selector, found ')'
(1,9): run-time error CSS1025: Expected comma or open brace, found ')'
(6,2): run-time error CSS1019: Unexpected token, found ')'
(8,10): run-time error CSS1031: Expected selector, found 'switchVideo('
(8,10): run-time error CSS1025: Expected comma or open brace, found 'switchVideo('
(33,10): run-time error CSS1031: Expected selector, found 'hideVideo('
(33,10): run-time error CSS1025: Expected comma or open brace, found 'hideVideo('
(42,10): run-time error CSS1031: Expected selector, found 'loadMoreVideo('
(42,10): run-time error CSS1025: Expected comma or open brace, found 'loadMoreVideo('
(52,10): run-time error CSS1031: Expected selector, found 'initSearchPanel('
(52,10): run-time error CSS1025: Expected comma or open brace, found 'initSearchPanel('
(114,10): run-time error CSS1031: Expected selector, found 'getScrollPosition('
(114,10): run-time error CSS1025: Expected comma or open brace, found 'getScrollPosition('
(126,10): run-time error CSS1031: Expected selector, found 'onscroll('
(126,10): run-time error CSS1025: Expected comma or open brace, found 'onscroll('
(135,10): run-time error CSS1031: Expected selector, found 'updateStickyMenu('
(135,10): run-time error CSS1025: Expected comma or open brace, found 'updateStickyMenu('
(147,1): run-time error CSS1019: Unexpected token, found 'updateStickyMenu('
(147,18): run-time error CSS1019: Unexpected token, found ')'
(149,1): run-time error CSS1019: Unexpected token, found '$'
(149,2): run-time error CSS1019: Unexpected token, found '('
(149,9): run-time error CSS1031: Expected selector, found ')'
(149,9): run-time error CSS1025: Expected comma or open brace, found ')'
 */
$(window).load(function () {
    switchVideo();
    hideVideo();
    loadMoreVideo();
    initSearchPanel();
});

function switchVideo() {
    var videos = $("#VideosSection .video-items .item");

    var firstCover = $("#VideosSection .video-items .item:first .overcover").css("background-color", "rgba(255, 255, 255, 0.2)");

    videos.each(function (index, elem) {

        $(elem).on("click", function () {
            console.log($(window).width());
            $('html, body').animate({
                scrollTop: ($('#VideosSection .video-items').offset().top - ($(window).width() > 767 ? 200 : 500))
            }, 200);

            videos.each(function (index, elem) {
                $(elem).find(".overcover").css("background-color", "");
            });

            $("#VideosSection .main-video iframe").attr("src", $(elem).find("iframe").attr("src") + "?autoplay=1&cc_load_policy=1&rel=0");
            $(elem).find(".overcover").css("background-color", "rgba(255, 255, 255, 0.2)");
        });

    })

}

function hideVideo() {
    if ($(window).width() < 767) {
        $("#VideosSection .video-items .item").slice(0, 3).removeClass("hidden");
        $("#VideosSection .video-items .show-more-video").removeClass("hidden");
    }
    else
        $("#VideosSection .video-items .item").removeClass("hidden");
}

function loadMoreVideo() {
    $("#VideosSection .video-items .show-more-video").on('click', function (e) {
        e.preventDefault();
        $("#VideosSection .video-items .item:hidden").slice(0, 3).removeClass("hidden");
        if ($("#VideosSection .video-items .item:hidden").length == 0) {
            $("#VideosSection .video-items .show-more-video").fadeOut('slow');
        }
    });
}

function initSearchPanel() {
	$('.search-type-dropdown li a').on('click', function (e) {
		e.preventDefault();		

		var searchType = $(this).attr("data-search-type");
		var searchTypeName = $(this).text();

		$('#search-dropdown').find('.inner-text').text(searchTypeName);

		//save selection
		$('.search-type-dropdown li a.selected').removeClass('selected');
		$(this).addClass('selected');

	})

	$('body').on('click', '.events-dropdown li a', function () {
		$('.events-dropdown .text-inner').text($(this).text())
		$('.events-dropdown a.selected').removeClass('selected');
		$(this).addClass('selected');		
	});

	//on submit
	$('.search-wrapper').on('submit', function (e) {
		e.preventDefault();

		var searchQuery = $('.search-input ').find('input').val();
		$(this).removeClass("empty-query-error")

		if ($.trim(searchQuery) == '') {
			$(this).addClass("empty-query-error")
			return;
		}		

		var searchModel = {
			searchQuery: searchQuery,
			searchType: $('.search-type-dropdown li a.selected').attr('data-search-type')
		}

		$('.search-button button').addClass('in-progress');

		$.post("/Home/Search", searchModel)
			.done(function (resp) {
				$('.search-results-container').remove();
				$(resp).insertAfter('#intro');

				$('.search-results-container .blog-list-section .blog-post-item .title a')
					.dotdotdot({ height: 60, watch: true })

				$('.search-results-container .blog-list-section .blog-post-item .text')
					.dotdotdot({ height: 60, watch: true })

				$('.search-results-events-section .event-description')
					.dotdotdot({height: 45, watch: true})
			})
			.always(function () {
				$('.search-button button').removeClass('in-progress');
			})
	});
	
}


function getScrollPosition() {
    if (window.pageYOffset != undefined) {
        return pageYOffset;
    } else {
        var sy, d = document,
            r = d.documentElement,
            b = d.body;
        sy = r.scrollTop || b.scrollTop || 0;
        return sy;
    }
}

function onscroll() {
    if (getScrollPosition() !== 0) {
        document.getElementById("userSection").style.position = "fixed";
    }
    else {
        document.getElementById("userSection").style.position = "relative";
    }
}

function updateStickyMenu() {
    if ($(window).scrollTop() > 350 && $(window).scrollTop() < 7202) {

        $('.sticky-menu').addClass("sticky-show");
    }

    else {

        $('.sticky-menu').removeClass("sticky-show");

    }
}
updateStickyMenu();

$(window).scroll(updateStickyMenu);
