// Create the application
$.application = {
	// Initialize the main object
	init: function() {
		// Enable rounded corners for MSIE
		$('#main-navigation ul.level1 li a, #footer .container').corner('10px tl tr');
		$('div.quicklinks a').corner('10px');
		
		// Enable main menu dropdowns for all browsers
		$('#main-navigation > ul > li:not(.active)').hover(
			function() {
				$(this).addClass('show-sub-navigation');
				$(this).children('a').css('color', '#333');
				
				// Refresh Cufon when leaving the dropdown
				$(this).bind('mouseleave', function() {
					$(this).parent().children('a').css('color', '#fff');
					Cufon.refresh('#main-navigation>ul>li>a');
				});
			},
			function() {
				$(this).removeClass('show-sub-navigation');
				$(this).children('a').css('color', '#fff');
			}
		);		
		
		// Open external links in a new window
		jQuery('a.internal-link-new-window, #network-links a').attr('target','_blank');
		jQuery('a.external-link-new-window').attr('target','_blank');
		
		// Open files in a new window
		$("a[href*='uploads/media']").bind('click', function() {
			window.open(this.href);	
			return false;
		});
		
		// Open newsletters in a new window
		$("a[href*='records/nieuwsbrieven']").bind('click', function() {
			window.open(this.href);	
			return false;
		});
	
		// Enable news / agenda switching on the home page
		$('#news-agenda h2 a').bind('click', function() {
			if ($(this).hasClass('active') === false) {
				// Switch the button states
				$('#news-agenda h2 a').toggleClass('active');
				
				// Switch the shown content
				$('#news-agenda div').toggleClass('active');
			}
			
			return false;
		});
		
		// Force the footer to the bottom of the screen if it isn't already
		if ($('#footer').offset().top < $(document).height()) {
			$('#footer').offset({ top: $(document).height() - $('#footer').height() });
		}
	}
};

// Replace text with Cufon
Cufon.replace('#vyvoj h1', { fontFamily: 'TriplexSansBoldLin' });
Cufon.replace('#de-gastouderacademie h1', { fontSize: '32px', fontFamily: 'Industria LT Std' })('#e-schoolkinderopvang h1', { fontSize: '32px', fontFamily: 'Industria LT Std' });
Cufon.replace('#nvtk h1', { fontFamily: 'Gill Sans Std' });

// Initialize the application
$(window).ready(function() {
	// Initialize the main object
	$.application.init();
});
