$(document).ready(function() {

    // activating frontpage slideshow
    $('#frontpage_slideshow_pictures').cycle({
        fx: 'fade',
        timeout: 5000,
        speed: 1000,
        after: frontpage_slideshow_description,
        random: true,
        pause: false,
        sync: true,
        delay: 0,
        cleartype: true
    });
    
    setTimeout(function() {        
        $('#frontpage_slideshow_overlaybox_left_back').fadeTo('slow', 0.8);
    }, 700);
    
    setTimeout(function() {        
        //$('#frontpage_slideshow_description_back').fadeTo('normal', 0.7);
        //$('#frontpage_slideshow_description_content').fadeIn('normal');
    }, 200);


    // activating frontpage slideshow
    $('#imageheader').cycle({
        fx: 'fade',
        timeout: 5000,
        speed: 1000,
        random: true,
        pause: true,
        sync: true,
        delay: 0,
        cleartype: true
    });

    // adding navigation to employee lists    
    $('div#employee_list').each(function(index) {        
        var letters = ""
        
        $('div#employee_list h4').each(function(index) {
            letters += '<a href="#'+ $(this).html() +'">'+ $(this).html() +'</a>&nbsp;';
        });
        
        $('div#employee_list div#employee_list_nav').append(letters);        
    });
    
    // attaching popup menu to folder menu items
    $('li.folder').hover(function() {
        $(this).addClass("active");
    }, function() {
        $(this).removeClass("active");
    });
    
    $('li.folder div:first a')
        .addClass('nolink')
        .attr('href', '#')
        .click(function() {
            $(this).blur()
            return false
        });
    
    
    // attaching frontpage address function
    $('.address_city').hover(function() {
        $('#frontpage_address_box_content').html($(this).attr('title'));
        $(this).attr('title','');
        $('#frontpage_address_box_content, #frontpage_address_box_back').show();
    }, function() {
        $(this).attr('title',$('#frontpage_address_box_content').html());
        $('#frontpage_address_box_content, #frontpage_address_box_back').hide();
    });
    
    
    // attaching masked input to dates
    $('input.date').mask("99/99/9999");
    $('input.mkoa').mask("9999-99-99");




    
    // hiding extra tekst for spiffy activation if javascript is enabled
    $('#vaerdikaede-blok-1, #vaerdikaede-blok-2, #vaerdikaede-blok-3, #vaerdikaede-blok-4, #vaerdikaede-blok-5, #vaerdikaede-blok-6').hide();

    // hooking up services_arrow_image map and text display on clicks
    $('#services_arrow area').each(function(index) {
        $(this).click(function() {
            $('#vaerdikaede-blok-1, #vaerdikaede-blok-2, #vaerdikaede-blok-3, #vaerdikaede-blok-4, #vaerdikaede-blok-5, #vaerdikaede-blok-6').hide();
            $('#vaerdikaede-blok-' + (index + 1)).show();
        });
    });


    // attaching form validation to job application
    $('.job_application').each(function(index) {
        $(this).find('form').validate();
    });
    
 
    
    
});

// handling the switching of descriptions during transitions
function frontpage_slideshow_description(element){
    var $pic = $('#frontpage_slideshow_pictures img:visible');
    var title = $pic.attr('title');
    
    if ($pic.attr('alt')) {var description = $pic.attr('alt');} else {var description = ""};

    if (title == 'None' || title == "" || title == null) {
        $('#frontpage_slideshow_description_back').fadeTo('normal', 0.0);
        $('#frontpage_slideshow_description_content').fadeOut('normal');
    } else {
        $('#frontpage_slideshow_description_content h3').html(title);
        $('#frontpage_slideshow_description_content span').html(description);
        $('#frontpage_slideshow_description_back').fadeTo('normal', 0.7);
        $('#frontpage_slideshow_description_content').fadeIn('normal');
    };
}