/* 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('
 */
$(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');
			})
	});
	
}
