$(document).ready(function() {
/* RESIZE trying to control the staffage-divs */
    $(window).bind('load', resizeWindow);
    $(window).bind('resize', resizeWindow);

    function resizeWindow() {
        var newWindowWidth = $(window).width();
        var wrapperWidth = $('#wrapper').width();
        var ditch = (newWindowWidth - wrapperWidth) / 2;
        ditch = Math.floor(ditch);
        if (ditch >= 0) {
            $('#small_left').css('width', ditch+'px');
            $('#small_right').css('width', ditch+'px');
            $('#large_left').css('width', ditch+'px');
            $('#large_right').css('width', ditch+'px');
        } else {
            $('#small_left').css('display', 'none');
            $('#small_right').css('display', 'none');
            $('#large_left').css('display', 'none');
            $('#large_right').css('display', 'none');
        }
        // Remove white area below the viewpoint on large pages...

        var contentBottom = $('#footer').offset().top + 20;
        var height = Math.max($('#footer').offset().top, $(window).height(), contentBottom);
        
        if ( $('#footer').offset().top > 750 ) {
        //    $('html').css('height', $('#footer').offset().top + 20 + 'px');
        }

        $('html').css('height', height + 'px');
    }
/* EO RESIZE  */
    var urlParams = {};
    (function(){
        var e,
        a = /\+/g,  // Regex for replacing addition symbol with a space
        r = /([^&;=]+)=?([^&;]*)/g,
        d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
        q = window.location.search.substring(1);
        
        while (e = r.exec(q)) {
            urlParams[d(e[1])] = d(e[2]);
        }
    }());
    if (urlParams['unsubscribe'] == 1) {
	alert('Din email adresse er blevet fjernet fra vor liste over modtagere af nyhedsbreve.')
    }
/* Open sign-up forms directly */

    
    if (urlParams['cstm'] == 'nl') {
	$.fn.colorbox({
	href        :       'assets/tilm_pg_1.php',
	iframe      :       true,
	width       :       '90%',
	height      :       '90%'
    });
    }
    // AMU
    else if (urlParams['cstm'] != '' && urlParams['cstm'] != undefined ) {
        $.fn.colorbox({
            href        :       'assets/tilm_amu.php?cstm='+urlParams['cstm'],
            iframe      :       true,
            width       :       '90%',
            height      :       '90%'
        });
    } // ONLINE
    else if (urlParams['cstm_ol'] != '' && urlParams['cstm_ol'] != undefined ) {
        $.fn.colorbox({
            href        :       'assets/tilm_cert_online.php?c=1&cstm='+urlParams['cstm'],
            iframe      :       true,
            width       :       '90%',
            height      :       '90%'
        });
    } // BASIS
    else if (urlParams['cstm_b'] != '' && urlParams['cstm_b'] != undefined ) {
        $.fn.colorbox({
            href        :       'assets/tilm_cert_online.php?c=2&cstm='+urlParams['cstm'],
            iframe      :       true,
            width       :       '90%',
            height      :       '90%'
        });
    } 
/* EO Open sign-up forms directly */
    $('#content .content_img').css('height', $('#content .content_img').width());
/* MENU */
	$('#navigation ul ul').hide();
	var hoverConfig = {
		over: showSubMenu,
		interval: 100,
		sensitivity: 4,
		timeout: 500,
		out: hideSubMenu
	};
	function showSubMenu() {
		$(this).find('ul').addClass('overlay');
		$('.overlay').slideDown();
		$('.overlay li:nth-child(1)').css('border-left', '1px solid #c6c8c7');
		$(this).find('a:first').addClass('active');
	}
	function hideSubMenu() {
		$('.overlay').hide();
		$(this).find('ul').removeClass('overlay');
		$(this).find('a').removeClass('active');
	}

	$('#navigation ul > li.hasSub').hoverIntent(hoverConfig);
/* MENU */
/* COLORBOX */

    $('#cboxOverlay').css('background', '#46645f');
    if (!window.Touch) {
    $('a.colorbox').colorbox({
        iframe      :       true,
        width       :       '90%',
        height      :       '90%'
    });
    $('a.colorbox_eftudd').colorbox({
        iframe      :       true,
        width       :       '1100px',
        height      :       '100%'
    });
    }
    $('#reminder').colorbox({
        width       :       '800px',
        height      :       '500px',
        iframe      :       true
    });
/* COLORBOX */
/* print */
    $('#print_icon').attr('title', 'Klik for at printe');
    $('#print_icon').css('cursor', 'pointer');
    $('#print_icon').click(function(){ 
        window.print();
    });
/* print */
});

