// Wanneer de pagina geladen wordt, zullen volgende scripts uitgevoerd worden


// HmcOrgOverview activate hosted exchange
function showPopup(title,content,width) {
    $('body').append('<div id="show_loading_overlay"><div id="overlay"></div></div><div class="overlay-msg"><h2>'+ title +'</h2><a href="#" class="close">Close</a><div class="content">'+ content +'</div></div>');
    $('#show_loading_overlay').fadeIn(300, function () {

        if (width == null) {
            width = 400;
        }

        $('.overlay-msg').width(width).css('marginLeft',-(Math.ceil(width/2))).fadeIn(500);
    });

    $('.overlay-msg .close').click(function () {
        $('.overlay-msg').fadeOut(500, function () {
            $('#show_loading_overlay').fadeOut(300);
        });
    });
    return false;
}


// roep de functie show_overlay() op om de overlay te tonen
function show_overlay(){
	$('body').append('<div id="show_loading_overlay"><div id="overlay"></div><div id="message"><div id="loading"><span class="bar"><img src="/Images/loading.gif" alt="Loading" /></span></div></div></div>');
	$('#show_loading_overlay').fadeIn(300);
}

//roep de functie hide_overlay() op om de overlay te sluiten
function hide_overlay(){
	$('#show_loading_overlay').hide(1,function(){
		$('.bar img').remove();		
	});
}

function browser_resized(){
	
	$('body').removeClass('large');
	
	if($( window ).width() > 1240){
		$('body').addClass('large');
    }

  


}

// account switcher - hosted exchange account detail page
function handleMailAccountSwitch(checkbox) {
    // reset all account types
    $('.mail-account-type').each(function () {
        $(this).removeClass('selected');
        $(this).find('.select-account-type input[type="checkbox"]').attr('checked', false);
        $(this).find('.account-options input[type="checkbox"]').attr('disabled', true);
    });

    // set selected account type to active
    var container = $(checkbox).parent().parent();
    $(container).addClass('selected');

    if ($(container).hasClass('active') && $(container).hasClass('selected')) {
        $('.mail-account-types-info').animate({
            opacity: 0
        },500,function(){
            $(this).slideUp();
        });
        
    } else {
        $('.mail-account-types-info').slideDown(function () {
            $(this).animate({ opacity: 1 }, 500);
        });
    }

    $(checkbox).attr('checked', true);
    $(container).find('.account-options').find('input[type="checkbox"]').attr('disabled', false);
    handleBlackberryChange();
}

function handleBlackberryChange() {

    var open = false;

    // itterate all checkboxes
    $('.account-option input[type="checkbox"]').each(function () {

        if ($(this).attr('checked') == true && $(this).attr('disabled') == false) {
            // found one ... exit the loop
            open = true;
            return false;
        } else {
            open = false;
        }
    });

    // open / close blackberry field
    if (open) {
        $('.infoblackberry').fadeIn();
    } else {
        $('.infoblackberry').fadeOut();
    }

}




//Volgende functies laden onload
$(document).ready(function () {

    

    // account switcher - hide infobox
    $('.mail-account-types-info').hide().css('opacity', 0);
    // account switcher - hosted exchange account detail page
    $('.mail-account-types .mail-account-type .select-account-type input[type="checkbox"]').change(function () {
        handleMailAccountSwitch(this);
    });
    $('.mail-account-types .mail-account-type').click(function () {
        handleMailAccountSwitch($(this).find('.select-account-type input[type="checkbox"]'));
    });

    // blackberry
    $('.account-option input[type="checkbox"]').change(function () {
        handleBlackberryChange();
    });

    // tooltip hmc offerte tool
    $('.btn-show-tooltip').hover(function () {

        // get tooltip element
        var tooltip = $(this).parent().find('.quote-tooltip');

        // vertical alignment 
        var marginTop = ($(tooltip).height() / 2) + 4;

        // set margin and show
    $(tooltip).css('marginTop', -(marginTop)).stop(true, true).fadeIn(500);

    }, function () {
        $(this).parent().find('.quote-tooltip').stop(true, true).fadeOut(500);
    });

    $('#ulListExchangeAlias li input[type="image"]').hover(function () {

        var tooltip = $(this).parent().find('.mail-tooltip');

        if (!$(tooltip).hasClass('active')) {
            $(tooltip).stop(true, true).fadeIn(500);
        }

    }, function () {

        var tooltip = $(this).parent().find('.mail-tooltip');

        if (!$(tooltip).hasClass('active')) {
            $(tooltip).stop(true, true).fadeOut(500);
        }

    });


  


    // hmcOrgOverview activate hosted exchange
    //    $('#ctl00_cphMainContent_lnkActivateExchange').click(function () {
    //       
    //        showPopup('dit is een test', $('#activate-he-popup-content').html(),319);
    //        return false;
    //    });

    // Toon een loading scherm wanneer er een element met klasse 'loading_trigger' wordt aangeklikt, dit kan een link, input of eender welk element zijn
    $('.loading_trigger').click(function () { show_overlay(); });

    // Voeg klasse last en first toe aan het eerste/laatste list element
    $('ul li:first-child').addClass('first');
    $('ul li:last-child').addClass('last');

    //toon enkel eerste 5 items in een lijst
    $('ul.dashboard').each(function () {
        $('li:gt(4)', this).hide();
        if ($('li', this).size() > 5) {
            $(this).append('<li class="showmore" style="cursor:hand;cursor:pointer;">Toon meer mogelijkheden ..</li>');
        }
    });
    $('.showmore').click(function () {
        $(this).parent('ul').find('li').show();
        $(this).hide();
    });

    // Vergroot werkruimte wanneer scherm groter is dan 1250px
    $(window).wresize(browser_resized);
    browser_resized();

    //	//ADDROW
    //	//maak rijen onzichtbaar en toon enkel de eerste rij, wanneer er op een link met id 'addhmcrow' wordt geklikt, zal de volgende rij getoond worden
    //	$('.hmcrow').hide();
    //	$('.hmcrow:eq(0)').show();
    //	$('#addhmcrow').click(function() {
    //	    var rows_number = $('.hmcrow:visible').size();
    //	    var total_rows = $('.hmcrow').size();
    //	    $('.hmcrow:eq(' + rows_number + ')').show('slow', function() {
    //	        if (rows_number == total_rows - 1) {
    //	            $('#addhmcrow').fadeOut();
    //	        }
    //	    });
    //	});

});

