$(document).ready(function() {
    tabs();
    pageLoad();
    productVideoModal();
});

function productVideoModal() {
    $("body").prepend($("#productVideo"));
    $("a.viewProductVideo").click(function() {
        $("#productVideo").fadeIn('fast');
        $("html,body").css({ "overflow": "hidden" });
    });
    $("#productVideo .close").click(function() {
        $("html,body").css({ "overflow": "auto" });
        modalExit();
    });
    $(document).keydown(function(e) {
        if ($(document).find("#productVideo").length > 0 && e.keyCode == 27) {
            modalExit();
        }
    });
    function modalExit() {
        $("#productVideo").fadeOut('fast');
    }
}

function tabs(){
    $('#tabRow a').hover(function() {
		if(!$(this).hasClass('activeTab')){$(this).addClass('hover');}
	},function(){
		$(this).removeClass('hover');
	})

	$('#tabRow a').click(function(e) {
	    $(this).removeClass('hover');
	    $(this).removeClass('activeTab');
	    var className = '.' + $(this).attr('class');
	    $(this).addClass('hover');
	    $(this).addClass('activeTab').removeClass('hover').siblings().removeClass('activeTab')
	    $('.tabContent').hide();
	    $(className).show();
	    e.preventDefault();

	})
}

function pageLoad() {

    $('.tabContent').hide();

    var showingFirst = false;

    $('.tabContent').each(function(index) {

        if ($(this).text().length > 0) {
            if (!showingFirst) {
                $(this).show();
                
                // activate the first tab
                var firstTab = '#tabRow a.tabContent' + (index + 1);
                $(firstTab).addClass('activeTab');
                
                showingFirst = true;
            }
        }
        else {
            var classname = '.tabContent' + (index + 1);
            $(classname).hide();
        }
    });
}
