﻿function blurAnchors() {
    if (document.getElementsByTagName) {
        var a = document.getElementsByTagName("a");
        for (var i = 0; i < a.length; i++) {
            a[i].onfocus = function() { this.blur() };
        }
    }
}
window.onload = blurAnchors;

jQuery(function($) {
    $("#ctl00_loginView_Login1_Password").Watermark("Passord");

    $("#ctl00_loginView_Login1_UserName").Watermark("Brukernavn");
});


$(document).ready(function() {
    $(".vertical .jCarouselLite").jCarouselLite({
        btnNext: ".vertical .next",
        btnPrev: ".vertical .prev",
        circular: false,
        visible: 12,
        vertical: true
    });

    $(".vertical .jCarouselLite").jCarouselLite({
        btnNext: ".vertical .next",
        btnPrev: ".vertical .prev",
        circular: false,
        visible: 12,
        vertical: true
    });
});

// skjule content hvis tom
$(document).ready(function() {
    var elements = $("#content > ").length;

    if (elements == 0) {
        $("#content").css("display", "none");
        // i tillegg fjern bakgrunnsfarge i .container
        $(".container").css("background", "none");
    }    
});


//$(document).ready(function() {
//    $(".auto .jCarouselLite-background").jCarouselLite({
//        auto: 2800,
//        speed: 1000
//    });
//});

/* Bckgrnd */
function rollBackground() {
    var current = $(".current-bkg");        
    var next = $(".current-bkg + img")[0];    
    
    // last element? start over then
    if (next == null && current.length != 0) {
        next = $(".auto > img")[0];
    }

    if (current.length == 0) {
        var imgs = $(".auto > img");

        var count = imgs.length;

        var rnd = Math.random() * count;
        var n = Math.ceil(rnd) - 1;

        next = imgs[n];
    }

    $(current).hide();
    $(next).show();

    var caption = $("#caption > p");

    var c = $(next).attr("alt");

    if (String(c).charAt(c.length - 1) == '_') {
        c = "";
    }
    
    $(caption).text(c);

    arrangeClasses(current, next);


    // fading - buggy
    //$(next).stop().fadeTo(3000, 1);
    //$(current).stop().fadeTo(3000, 0, arrangeClasses(current, next));
    //$(next).stop().fadeTo(10000, 1, );
}

function arrangeClasses(current, next) {
    $(next).addClass("current-bkg");
    $(next).removeClass("hidden-bkg");
    if (current != null) {
        $(current).removeClass("current-bkg");
        $(current).addClass("hidden-bkg");
    }
}

$(document).ready(function() {
    rollBackground();
    setInterval("rollBackground()", 10000);
});
    
$.fn.crossfade = function() {
    var $$ = $(this);

    $$.hover(function() {
        $$.stop().fadeTo(3000, 0);
        $$.stop().animate({
            opacity: 0
        }, 250);
    }, function() {
        $$.stop().animate({
            opacity: 1
        }, 3000);
    });
}

// hide carousel buttons if not needed
$(document).ready(function() {
    var carousel = $(".jCarouselLite > ul > li");    
    if (carousel.length < 13) {
        $(".next").css("display", "none");
        $(".prev").css("display", "none");
    }
});

// hide white content area if prosjekter.aspx and no "extra" elements
$(document).ready(function() {
    var page = jQuery.url.attr("file");
    var itemID = jQuery.url.param("itemID");
    if (page == "prosjekter.aspx" && itemID == null) {
        var childs = $("#content >");
        if (childs[0].tagName == "H2" && childs[2].tagName == "SCRIPT" && childs[3].tagName == "IMG") {
            $("#content").css("display", "none");
            $(".container").css("background", "none");
        }
    }
});
