﻿$(function () {

    // global menu
    $('#globalMenu').children().globalMenu();

    // text size buttons
    $('#changeTextSize').textSize();

    // accordion menu
    $('.accordionmenu').createAccordion();

    // share links
    $('#delingLinker, #footerdelingLinker').hoverIntent(showShare, hideShare).children('ul').hide();

    // fix article header when there is no image
    $('.articleHeader').not(':has(img)').addClass('noImage');

    // accordion menu for "Muligheter i forsvaret"
    $('.muligheter > ul > li > a').click(function () {
        $(this).parent().children('ul').toggle();
        return false;
    });

    // datepicker - forsvaret today / activitycalendar
    $.tools.dateinput.localize('no', {
        months: 'januar,februar,mars,april,mai,juni,juli,august,september,oktober,novermber,desember',
        shortMonths: 'jan,feb,mar,apr,mai,jun,jul,aug,sep,okt,nov,des',
        days: 'søndag,mandag,tirsdag,onsdag,torsdag,fredag,lørdag',
        shortDays: 'søn,man,tir,ons,tor,fre,lør'
    });
    $(':date').dateinput({
        lang: 'no',
        format: 'dd.mm.yyyy',
        firstDay: 1,
        trigger: true,
        min: -1
    });
    $('div.calender').calendar();

    // images in an article body
    $('.hovedInnhold a.inlinebilde').fancybox({
        speedIn: 300,
        speedOut: 200,
        transitionIn: 'fade',
        transitionOut: 'fade',
        hideOnContentClick: true,
        titleShow: true,
        titlePosition: 'inside',
        enableEscapeButton: true,
        showCloseButton: 'true',
        autoDimensions: 'true',
        autoScale: 'true',
        titleFormat: function (title) {
            return $(this.orig).siblings('p').text() || title;
        }
    });

    // forsvaret today
    $('a.forsvaretidagbilde').fancybox({
        titlePosition: 'inside',
        speedOut: 200,
        hideOnContentClick: true,
        titleFormat: function (title, currentArray, currentIndex) {
            return $('.inline:eq(' + currentIndex + ')').html();
        }
    });

    // > IE 7 fix for auto width image captions
    if ($.browser.msie && $.browser.version < 8) {
        $('.inlinebilde').css('display', 'block').width(function () {
            return $(this).children('img').width();
        });
    }

    // float-sameHeight fix for article list
    $('.articleList > article:first-child, .articleList > div').each(function () {
        $(this).nextUntil('div').add(this).children('a').sameHeight();
    });

    // unknown SharePoint fix
    $('.ms-vb-title').mouseover(function () {
        var $this = $(this);
        $this.children('.s4-ctx').css('top', ($this.position().top - $('#wrapper').position().top) + 'px');
    });

});

$(window).load(function () {
    $('.frontPageNews .articleListItem').sameHeight();
    $('.coda-nav > ul > li > a').sameHeight();
});

// Add VideoJS to all video tags on the page when the DOM is ready
VideoJS.setupAllWhenReady({
    controlsBelow: true, // Display control bar below video vs. in front of
    showControlsAtStart: true, // Make controls visible when page loads
    controlsHiding: false, // Hide controls when not over the video
    defaultVolume: 0.80, // Will be overridden by localStorage volume if available
    flashVersion: 9, // Required flash version for fallback
    linksHiding: true, // Hide download links when video is supported
    flashIsDominant: false, // Always use Flash when available
    useBrowserControls: false, // Dont' use the video JS controls (iPhone)
    players: ['html5', "flashObject", "links"] // Players and order to use them
});
