﻿/* Change text in input fields
****************************************************/
var newsletterMail = 'Din e-post'; //Only front page


// Read a page's GET URL variables and return them as an associative array.
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }

    return vars;
}


/* Change height of content if screen is larger than content
****************************************************/
window.onload = function() {
    changeContentHeight();

}
function changeContentHeight() {
    windowHeight = document.body.offsetHeight; //Height of browser window
    wrapperHeight = document.getElementById('wrapper').offsetHeight; //Height of div#wrapper
    mainholderHeight = document.getElementById('mainHolderHeight').offsetHeight; //Height of div#mainHolderHeight

    //If wrapper height is less than window height, the size 
    //will change to fill the height of the browser window
    if (wrapperHeight < windowHeight) {
        contentHeight = mainholderHeight + (windowHeight - wrapperHeight);
        document.getElementById('mainHolderHeight').style.minHeight = contentHeight + "px";
    }
}



/* jQuery events
****************************************************/
$(document).ready(function() {

    // Change height of content if screen is resized
    var resizeTimer = null;
    $(window).bind('resize', function() {
        if (resizeTimer) clearTimeout(resizeTimer);
        resizeTimer = setTimeout(changeContentHeight, 100);
    });


    //newsletterMail
    $('#ctl00_cphFooterText_newsletterMail').attr("value", newsletterMail).css('color', '#8d8e8d').focus(function() {
        if (newsletterMail == $(this).attr("value")) {
            $(this).attr("value", "").css('color', '#000000');
        }
    }).blur(function() {
        if ($(this).attr("value") == '') {
            $(this).attr("value", newsletterMail).css('color', '#8d8e8d');
        }
    });


    /* Dialog box for newsletter subscription
    ****************************************************/
    $("#rightMenuNewsletterLink").click(function() {
    $("#newsletterDialog").dialog({
        height: 130,
        width: 400,
        // Fix: Move dialog inside of Form to ensure PostBack
        open: function(type, data) {
            $(this).parent().appendTo("form");
            }
        });
        return false;
    });

    
    /* Fancybox iframe opener
    ****************************************************/
    $(".fancyboxFrame").fancybox({
        'width': '75%',
        'height': '75%',
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'type': 'iframe'
    });


    /* Fancybox image gallery
    ****************************************************/
    $("a.grouped_elements").fancybox({
        'titlePosition': 'inside',
        'speedIn': 600,
        'speedOut': 200,
        'titleFormat': function(title, currentArray, currentIndex, currentOpts) {
            return '<div style="font-weight:bold;padding-right:100px;text-align:left;">' + this.title + '</div><div style="position:absolute;top:10px;right:10px;color:#666666;">' + (currentIndex + 1) + '/' + currentArray.length + '</div>';
        }
    });


    /* Tabs in subscription article
    ****************************************************/
    //When page loads...
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs li").click(function() {

        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        return false;
    });
});



/* Toggles show/hide of answers in FAQ
****************************************************/
$(function() {
    $(".spm").click(function() {
        $(this).toggleClass("activeQuestion").next(".faq-answer").slideToggle();
        return false;
    });
});

