var font = (function () {
    var test_string = 'mmmmmmmmmwwwwwww';
    var test_font = '"Comic Sans MS"';
    var notInstalledWidth = 0;
    var testbed = null;
    var guid = 0;
    
    return {
        // must be called when the dom is ready
        setup : function () {
            if ($('#fontInstalledTest').length) return;

            $('head').append('<' + 'style> #fontInstalledTest, #fontTestBed { position: absolute; left: -9999px; top: 0; visibility: hidden; } #fontInstalledTest { font-size: 50px!important; font-family: ' + test_font + ';}</' + 'style>');
            
            
            $('body').append('<div id="fontTestBed"></div>').append('<span id="fontInstalledTest" class="fonttest">' + test_string + '</span>');
            testbed = $('#fontTestBed');
            notInstalledWidth = $('#fontInstalledTest').width();
        },
        
        isInstalled : function(font) {
            guid++;
        
            var style = '<' + 'style id="fonttestStyle"> #fonttest' + guid + ' { font-size: 50px!important; font-family: ' + font + ', ' + test_font + '; } <' + '/style>';
            
            $('head').find('#fonttestStyle').remove().end().append(style);
            testbed.empty().append('<span id="fonttest' + guid + '" class="fonttest">' + test_string + '</span>');
                        
            return (testbed.find('span').width() != notInstalledWidth);
        }
    };
})();

$(document).ready(function () {
	
	font.setup(); // run setup when the DOM is ready
	if ( !font.isInstalled("calibri") && $('body').css('font-size') !== "13px" ) 
	{
		$('body').css({'font-size': 13+"px"});
		$('body').css({'line-height': 1.6+"em"});
	}

  	clearInterval(autoFadingInterval);
	var autoFadingInterval = setInterval("autoFading()", 8000);
	
});



function autoFading() {


    var $active = $('.start div.teaser .active');

    if ( $active.length == 0 ) $active = $('.start div.teaser div.current');

    var $next =  $active.next().length ? $active.next()
        : $('.start div.teaser div.slide:first');

    $active.addClass('last-active');
	
	$active.fadeOut(1750);
	
    $next.hide()
        .addClass('active')
        .fadeIn(1250, function() {
            $active.removeClass('active last-active');
        });
		
		
		
}