var handlerGallerySlideNext = function () { slideGalleryNext(); }
var handlerGallerySlidePrev = function () { slideGalleryPrev(); }
var $WindowWidth = 0;
var $PlayerWidth = 0;

//Ready Start
$(document).ready(function () {

    //setTimeout(alert($(window).width()), 50);

    //Browser detection
    var OSName = "Unknown OS";
    if (navigator.appVersion.indexOf("Win") != -1) OSName = "Windows";
    if (navigator.appVersion.indexOf("Mac") != -1) OSName = "MacOS";
    if (navigator.appVersion.indexOf("X11") != -1) OSName = "UNIX";
    if (navigator.appVersion.indexOf("Linux") != -1) OSName = "Linux";
    //alert(OSName);
    if (OSName == "MacOS" && !navigator.userAgent.match(/iPhone/i)) {
        $('#MoodsContentMain').css('margin', '502px -60px 0px 0px');
        $('#MoodsContentMain').css('width', '253px');
        $('#MoodsContentMain div').css('width', '253px');
    }

    flashWidth = $('.FlashDiv').width();
    flashHeight = $('.FlashDiv').height();
    //Flash Video Start
    $WindowWidth = $(window).width();
    $PlayerWidth = $('.Player').width();
    $('.VideoLogo, .VideoLogoFacts').click(function () {
        $("#vimeoplayersingle").attr("src", $("#vimeoplayersingle").attr("src"));
        setTimeout("LaunchPopup()", 500);
 
//        $('.Player').css("display", "block");
//        $('.Player').css("margin-left", ($WindowWidth / 2) - ($PlayerWidth / 2)); //Centrer modal popup
//        $('#ModalOverlay').css("display", "block");
//        $('#ModalOverlay').height($(window).height());
//        $('#ModalOverlay').addClass("ModalPopUpLayer");
//        $("#MoodsContentMain").css("display", "none");
    });

    $('#closeFlashPopup').click(function () {
        $('.Player').css("display", "none");
        $('#ModalOverlay').removeClass('ModalPopUpLayer');
        $('#ModalOverlay').css("display", "none");
        $("#MoodsContentMain").css("display", "block");
        //document.getElementById("FlashMoviePopup").stopMoviePlayer();
        vimeoplayersingler = document.getElementById('vimeoplayersingle');
        vimeoplayersingler.api("api_pause");
        //$('#Wrapper').height($(window).height());
        return false;
    });

    //    if ($('#Video').length == 0) {
    //        $('#VideoLogo').css('display', 'none');
    //    }
    //Flash Video End

    //Portefolio Gallery Start
    //    if ($("#PortfolioGallery iframe").length > 0) {
    //        $('.PortfolioGalleryButtons').css('visibility', 'visible');
    //    }


    if ($('#PortfolioGallery iframe').length > 0 || $('#PortfolioGallery img').length > 0) {
        $('.PortfolioGalleryButtons').css('visibility', 'visible');
    }
    else {
        $('.PortfolioGalleryButtons').css('visibility', 'hidden');
    }
    $('.PortfolioGalleryButtons .NextButton').click(function () {
        $toShow = 0;
        if ($('#PortfolioGallery .Active iframe').length > 0) {
            $('#PortfolioGallery .Active iframe').attr("src", "");

        }
        // $('.FlashDiv').css("display") til IPhone
        if ($('.FlashDiv').width() == 0 || $('.FlashDiv').css("display") == "none") {
            //Hvis flash ikke er aktiv så find det næste billlede
            $toHide = $('#PortfolioGallery .Active object');
            //Sluk for film ved klik på "næste"

            $toShow = $('#PortfolioGallery .Active').removeClass('Active').addClass('DisplayNone').next();
        }
        else {
            //Hvis flash er aktiv, så ta det første billede
            $toShow = $('#PortfolioGallery div:first').removeClass('DisplayNone').addClass('Active');
        }
        if ($toShow.length != 0) {
            $($toShow).removeClass('DisplayNone').addClass('Active');
            $('.FlashDiv').width(0);
            $('.FlashDiv').height(0);
            $('.FlashDiv').css("width", "0px");
            $('.FlashDiv').css("height", "0px");
            if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
                $('.FlashDiv').css("display", "none");
            }
        }
        else {
            $('.FlashDiv').width(flashWidth);
            $('.FlashDiv').height(flashHeight);
            $('.FlashDiv').css("width", flashWidth);
            $('.FlashDiv').css("height", flashHeight);
            if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
                $('.FlashDiv').css("display", "block");
            }
        }

        //Hvis flash ikke kan vises , åben en player ved klik på billedet
        if ($toShow.find("img").hasClass("startiphonemovie")) {
            iphoneimagestarter = $toShow.find("img");
            $(iphoneimagestarter).click(function () {
                window.location = $toShow.find("a:first").attr('href');
            });
        }
        if ($('#PortfolioGallery .Active iframe').length > 0) {
            vimeourl = $('#PortfolioGallery .Active  a').html();
            $('#PortfolioGallery .Active iframe').attr("src", vimeourl);
        }

    });
    $('.PortfolioGalleryButtons .PrevButton').click(function () {
        $toShow = 0;
        if ($('#PortfolioGallery .Active iframe').length > 0) {
            $('#PortfolioGallery .Active iframe').attr("src", "");

        }
        if ($('.FlashDiv').width() == 0 || $('.FlashDiv').css("display") == "none") {
            //Hvis flash ikke er aktiv så find det forrige billlede
            $toHide = $('#PortfolioGallery .Active object');


            $toShow = $('#PortfolioGallery .Active').removeClass('Active').addClass('DisplayNone').prev();
        }
        else {
            //Hvis flash er aktiv, så ta det sidste billede
            $toShow = $('#PortfolioGallery > div:last').removeClass('DisplayNone');
        }
        if ($toShow.length != 0) {
            $toShow.removeClass('DisplayNone').addClass('Active');
            $('.FlashDiv').width(0);
            $('.FlashDiv').height(0);
            $('.FlashDiv').css("width", "0px");
            $('.FlashDiv').css("height", "0px");
            if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
                $('.FlashDiv').css("display", "none");
            }
        }
        else {
            $('.FlashDiv').width(flashWidth);
            $('.FlashDiv').height(flashHeight);
            $('.FlashDiv').css("width", flashWidth);
            $('.FlashDiv').css("height", flashHeight);
            if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
                $('.FlashDiv').css("display", "block");
            }
        }
        if ($toShow.find("img").hasClass("startiphonemovie")) {
            iphoneimagestarter = $toShow.find("img");
            $(iphoneimagestarter).click(function () {
                window.location = $toShow.find("a:first").attr('href');
            });
        }
        if ($('#PortfolioGallery .Active iframe').length > 0) {
            vimeourl = $('#PortfolioGallery .Active  a').html();
            $('#PortfolioGallery .Active iframe').attr("src", vimeourl);
        }
    });
    //Portefolio Gallery End



    //Moods Gallery Start
    if ($('#MoodsGallery img').length > 0 || $('#MoodsGallery iframe').length > 0) {
        //alert("Moods test");
        $('.MoodsGalleryButtons').css('visibility', 'visible');
    }
    else {
        $('.MoodsGalleryButtons').css('visibility', 'hidden');
    }
    $('.MoodsGalleryButtons .NextButton').click(function () {
        $toShow = 0;
        if ($('#MoodsGallery .Active iframe').length > 0) {
            $('#MoodsGallery .Active iframe').attr("src", "");

        }
        // $('.FlashDiv').css("display") til IPhone
        if ($('.FlashDiv').width() == 0 || $('.FlashDiv').css("display") == "none") {

            //Hvis flash ikke er aktiv så find det næste billlede
            $toHide = $('#MoodsGallery .Active object');
            $toShow = $('#MoodsGallery .Active').removeClass('Active').addClass('DisplayNone').next();
        }
        else {
            //Hvis flash er aktiv, så ta det første billede
            $toShow = $('#MoodsGallery div:first').removeClass('DisplayNone').addClass('Active');
        }
        if ($toShow.length != 0) {
            $($toShow).removeClass('DisplayNone').addClass('Active');
            $('.FlashDiv').width(0);
            $('.FlashDiv').height(0);
            $('.FlashDiv').css("width", "0px");
            $('.FlashDiv').css("height", "0px");
            if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
                $('.FlashDiv').css("display", "none");
            }
            $('#MoodsContentMain').css('visibility', 'hidden');

        }
        else {
            $('.FlashDiv').width(flashWidth);
            $('.FlashDiv').height(flashHeight);
            $('.FlashDiv').css("width", flashWidth);
            $('.FlashDiv').css("height", flashHeight);
            if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
                $('.FlashDiv').css("display", "block");
            }
            $('#MoodsContentMain').css('visibility', 'visible');

        }

        //Hvis flash ikke kan vises , åben en player ved klik på billedet
        if ($toShow.find("img").hasClass("startiphonemovie")) {
            iphoneimagestarter = $toShow.find("img");
            $(iphoneimagestarter).click(function () {
                window.location = $toShow.find("a:first").attr('href');
            });
        }
        if ($('#MoodsGallery .Active iframe').length > 0) {
            vimeourl = $('#MoodsGallery .Active  a').html();
            $('#MoodsGallery .Active iframe').attr("src", vimeourl);
        }
    });
    $('.MoodsGalleryButtons .PrevButton').click(function () {
        $toShow = 0;
        if ($('#MoodsGallery .Active iframe').length > 0) {
            $('#MoodsGallery .Active iframe').attr("src", "");
        }
        if ($('.FlashDiv').width() == 0 || $('.FlashDiv').css("display") == "none") {

            //Hvis flash ikke er aktiv så find det forrige billlede
            $toHide = $('#MoodsGallery .Active object');
            $toShow = $('#MoodsGallery .Active').removeClass('Active').addClass('DisplayNone').prev();
        }
        else {
            //alert($('.FlashDiv').width());
            //Hvis flash er aktiv, så ta det sidste billede
            $toShow = $('#MoodsGallery > div:last').removeClass('DisplayNone');
        }
        if ($toShow.length != 0) {
            //alert($toShow.length);
            $toShow.removeClass('DisplayNone').addClass('Active');
            $('.FlashDiv').width(0);
            $('.FlashDiv').height(0);
            $('.FlashDiv').css("width", "0px");
            $('.FlashDiv').css("height", "0px");
            if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
                $('.FlashDiv').css("display", "none");
            }
            $('#MoodsContentMain').css('visibility', 'hidden');


        }
        else {
            //alert("vis flash baggrund");
            $('.FlashDiv').width(flashWidth);
            $('.FlashDiv').height(flashHeight);
            $('.FlashDiv').css("width", flashWidth);
            $('.FlashDiv').css("height", flashHeight);
            if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
                $('.FlashDiv').css("display", "block");
            }
            $('#MoodsContentMain').css('visibility', 'visible');

        }
        if ($toShow.find("img").hasClass("startiphonemovie")) {
            iphoneimagestarter = $toShow.find("img");
            $(iphoneimagestarter).click(function () {
                window.location = $toShow.find("a:first").attr('href');
            });
        }
        if ($('#MoodsGallery .Active iframe').length > 0) {
            vimeourl = $('#MoodsGallery .Active  a').html();
            $('#MoodsGallery .Active iframe').attr("src", vimeourl);
        }
    });
    //Moods Gallery End




    //Whatsup gallery Start
    //Hvis flash ikke kan vises , åben en player ved klik på billedet
    $('.ArticleGallery #Gallery .Active .startiphonemovie').live('click', function () {
        window.location = $('.ArticleGallery #Gallery .Active').find("a").attr('href');
    });

    if ($('.ArticleGallery #Gallery div').length <= 1) {
        $('.ArticleGalleryButtons').css('visibility', 'hidden');
    }
    else {
    }

    $('.ArticleGalleryButtons .NextButton').click(function () {
        //Stop film når der klikkes næste
        if ($('.ArticleGallery #Gallery .Active iframe').length > 0) {
            //flashMovieToStopID = $('.ArticleGallery #Gallery .Active object').attr("id");
            //document.getElementById(flashMovieToStopID).stopMoviePlayer();
            $('.ArticleGallery #Gallery .Active iframe').attr("src", "");
        }
        $toShow = $('#Gallery .Active').removeClass('Active').addClass('DisplayNone').next();
        if ($toShow.length != 0) {
            $toShow.removeClass('DisplayNone').addClass('Active');
        }
        else {
            $('#Gallery div:first').removeClass('DisplayNone').addClass('Active');
        }
        if ($('.ArticleGallery #Gallery .Active iframe').length > 0) {
            vimeourl = $('.ArticleGallery #Gallery .Active  a').html();
            $('.ArticleGallery #Gallery .Active iframe').attr("src", vimeourl);
        }

    });
    $('.ArticleGalleryButtons .PrevButton').click(function () {
        //Stop film når der klikkes tilbage
        if ($('.ArticleGallery #Gallery .Active iframe').length > 0) {
            //flashMovieToStopID = $('.ArticleGallery #Gallery .Active object').attr("id");
            //document.getElementById(flashMovieToStopID).stopMoviePlayer();
            $('.ArticleGallery #Gallery .Active iframe').attr("src", "");

        }
        $toShow = $('#Gallery .Active').removeClass('Active').addClass('DisplayNone').prev();
        if ($toShow.length != 0) {
            $toShow.removeClass('DisplayNone').addClass('Active');
        }
        else {
            $('#Gallery > div:last').removeClass('DisplayNone').addClass('Active');
        }
        if ($('.ArticleGallery #Gallery .Active iframe').length > 0) {
            vimeourl = $('.ArticleGallery #Gallery .Active  a').html();
            $('.ArticleGallery #Gallery .Active iframe').attr("src", vimeourl);
        }

    });
    //Whats up End 

    //Quote gallery Start
    if ($('#Gallery img').length < 1) {
        //Skjul knapperne på startsiden samt hvis der kun er et billede 
        $('#GalleryButtons').css('visibility', 'hidden');
    }

    $('#GalleryButtons .NextButton').click(function () {
        $toShow = 0;
        //$('.FlashDiv').width(0);
        if ($('.FlashDiv').width() == 0) {
            //Hvis flash ikke er aktiv så find det næste billlede
            $toShow = $('#Gallery .Active').removeClass('Active').addClass('DisplayNone').next();
        }
        else {
            //Hvis flash er aktiv, så ta det første billede
            $toShow = $('#Gallery div:first').removeClass('DisplayNone').addClass('Active');
        }
        if ($toShow.length != 0) {
            //alert($toShow.attr("id"));
            $toShow.removeClass('DisplayNone').addClass('Active');
            $('.FlashDiv').width(0);
            $('.FlashDiv').height(0);
        }
        else {
            $('.FlashDiv').width(flashWidth);
            $('.FlashDiv').height(flashHeight);
        }
        //alert("test");

    });


    $('#GalleryButtons .PrevButton').click(function () {
        $toShow = 0;
        if ($('.FlashDiv').width() == 0) {
            //Hvis flash ikke er aktiv så find det forrige billlede
            $toShow = $('#Gallery .Active').removeClass('Active').addClass('DisplayNone').prev();

        }
        else {
            //Hvis flash er aktiv, så ta det sidste billede
            $toShow = $('#Gallery div:last').removeClass('DisplayNone');
        }
        if ($toShow.length != 0) {
            $toShow.removeClass('DisplayNone').addClass('Active');
            $('.FlashDiv').width(0);
            $('.FlashDiv').height(0);

        }
        else {
            $('.FlashDiv').width(flashWidth);
            $('.FlashDiv').height(flashHeight);
        }

    });
    //Quote gallery End

    //Quote Gallery Start (udvidet)
    if ($('#QuotesGallery img').length > 0 || ('#QuotesGallery iframe').length > 0) {
        //alert("Moods test");
        $('.QuotesGalleryButtons').css('visibility', 'visible');
    }
    else {
        $('.QuotesGalleryButtons').css('visibility', 'hidden');
    }
    $('.QuotesGalleryButtons .NextButton').click(function () {
        $toShow = 0;

        if ($('#QuotesGallery .Active iframe').length > 0) {
            $('#QuotesGallery .Active iframe').attr("src", "");
        }
        if ($('.FlashDiv').width() == 0 || $('.FlashDiv').css("display") == "none") {

            //Hvis flash ikke er aktiv så find det næste billlede
            $toHide = $('#QuotesGallery .Active object');
            $toShow = $('#QuotesGallery .Active').removeClass('Active').addClass('DisplayNone').next();
        }
        else {
            //Hvis flash er aktiv, så ta det første billede
            $toShow = $('#QuotesGallery div:first').removeClass('DisplayNone').addClass('Active');
        }
        if ($toShow.length != 0) {
            $($toShow).removeClass('DisplayNone').addClass('Active');
            $('.FlashDiv').width(0);
            $('.FlashDiv').height(0);
            $('.FlashDiv').css("width", "0px");
            $('.FlashDiv').css("height", "0px");
            if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
                $('.FlashDiv').css("display", "none");
            }
            $('#QuotesContentMain').css('visibility', 'hidden');

        }
        else {
            $('.FlashDiv').width(flashWidth);
            $('.FlashDiv').height(flashHeight);
            $('.FlashDiv').css("width", flashWidth);
            $('.FlashDiv').css("height", flashHeight);
            if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
                $('.FlashDiv').css("display", "block");
            }
            $('#QuotesContentMain').css('visibility', 'visible');

        }

        //Hvis flash ikke kan vises , åben en player ved klik på billedet
        if ($toShow.find("img").hasClass("startiphonemovie")) {
            iphoneimagestarter = $toShow.find("img");
            $(iphoneimagestarter).click(function () {
                window.location = $toShow.find("a:first").attr('href');
            });
        }
        if ($('#QuotesGallery .Active iframe').length > 0) {
            vimeourl = $('#QuotesGallery .Active  a').html();
            $('#QuotesGallery .Active iframe').attr("src", vimeourl);
        }
    });
    $('.QuotesGalleryButtons .PrevButton').click(function () {
        $toShow = 0;
        if ($('#QuotesGallery .Active iframe').length > 0) {
            $('#QuotesGallery .Active iframe').attr("src", "");
        }
        if ($('.FlashDiv').width() == 0 || $('.FlashDiv').css("display") == "none") {
            //Hvis flash ikke er aktiv så find det forrige billlede
            $toHide = $('#QuotesGallery .Active object');

            $toShow = $('#QuotesGallery .Active').removeClass('Active').addClass('DisplayNone').prev();
        }
        else {
            //Hvis flash er aktiv, så ta det sidste billede
            $toShow = $('#QuotesGallery > div:last').removeClass('DisplayNone');
        }
        if ($toShow.length != 0) {
            $toShow.removeClass('DisplayNone').addClass('Active');
            $('.FlashDiv').width(0);
            $('.FlashDiv').height(0);
            $('.FlashDiv').css("width", "0px");
            $('.FlashDiv').css("height", "0px");
            if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
                $('.FlashDiv').css("display", "none");
            }
            $('#QuotesContentMain').css('visibility', 'hidden');

        }
        else {
            $('.FlashDiv').width(flashWidth);
            $('.FlashDiv').height(flashHeight);
            $('.FlashDiv').css("width", flashWidth);
            $('.FlashDiv').css("height", flashHeight); ;
            if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
                $('.FlashDiv').css("display", "block");
            }
            $('#QuotesContentMain').css('visibility', 'visible');

        }
        if ($toShow.find("img").hasClass("startiphonemovie")) {
            iphoneimagestarter = $toShow.find("img");
            $(iphoneimagestarter).click(function () {
                window.location = $toShow.find("a:first").attr('href');
            });
        }
        if ($('#QuotesGallery .Active iframe').length > 0) {
            vimeourl = $('#QuotesGallery .Active  a').html();
            $('#QuotesGallery .Active iframe').attr("src", vimeourl);
        }
    });
    //Quotes Gallery (udvidet)


    ResizeFlashMovie();

    $(window).resize(function () {
        ResizeFlashMovie();
    });


    $('ul#ArticleList li.ArticleListitemSeeMore').click(function () {
        $('ul#ArticleList li.DisplayNone').removeClass("DisplayNone");
        $(this).addClass("DisplayNone");
    });
});
//Ready End
function LaunchPopup() {
    $('.Player').css("display", "block");
    $('.Player').css("margin-left", ($WindowWidth / 2) - ($PlayerWidth / 2)); //Centrer modal popup
    $('#ModalOverlay').css("display", "block");
    //$('#Wrapper').height($("#FlashMoviePopup").height() + 100);
    $('#ModalOverlay').height($(window).height());
    $('#ModalOverlay').addClass("ModalPopUpLayer");
    //$('.Player').clone().appendTo('#ModalOverlay');
    $("#MoodsContentMain").css("display", "none");
}

//Function Start
function slideGalleryNext() {
    //Vis det næste aktive store aktive billede
    currentImage = $('#PortfolioGallery .Active').removeClass('Active').addClass('DisplayNone').next().removeClass('DisplayNone').addClass('Active');

    //Er der en næste
    toshow = currentImage.next();

    //Hvis der ikke er en næste så fjerne slider
    if (toshow.length == 0) {
        $('.PortfolioGalleryButtons .NextButton').addClass('VisiblityNone').unbind('click', handlerGallerySlideNext);
    }

    //Unbind og derefter bind slide prev
    $('.PortfolioGalleryButtons .PrevButton').unbind('click', handlerGallerySlidePrev).bind('click', handlerGallerySlidePrev).removeClass('VisiblityNone');
}

function slideGalleryPrev() {
    //Vis det næste aktive store aktive billede
    currentImage = $('#PortfolioGallery .Active').removeClass('Active').addClass('DisplayNone').prev().removeClass('DisplayNone').addClass('Active');

    //Er der en prev
    var toshow = currentImage.prev();

    //Hvis der ikke er en prev
    if (toshow.length == 0) {
        $('.PortfolioGalleryButtons .PrevButton').addClass('VisiblityNone').unbind('click', handlerGallerySlidePrev);
    }

    //Unbind og derefter bind slide next
    $('.PortfolioGalleryButtons .NextButton').unbind('click', handlerGallerySlideNext).bind('click', handlerGallerySlideNext).removeClass('VisiblityNone');
}



function ResizeFlashMovie() {
    currentWindowWidth = $(window).width();
    websiteHeight = $('#Wrapper').height();
    $("[id$='_FlashDiv']").width(currentWindowWidth);
    $("[id$='_FlashDiv']").height(websiteHeight);
    differenceWidth = 2500 - currentWindowWidth;
    $('#FlashContainter').css('margin-left', -(Math.round(differenceWidth / 2)));
}


function SetGalleryButtonsOnWhatsUp(currentArticleIndex) {
    if (currentArticleIndex == 0) {
        alert("1");
    }
    else if (currentArticleIndex == 1) {
        alert("2");

    }
    else if (currentArticleIndex == 2) {

    }
    else if (currentArticleIndex == 3) {

    }
    else if (currentArticleIndex == 4) {

    }
    else if (currentArticleIndex == 5) {

    }
    else if (currentArticleIndex == 6) {

    }
    else if (currentArticleIndex == 7) {

    }
}

function ShowMovieNoFlash() {


}

//Function End
