(function($) {
	
	var dn_footermovieelement;
	
	function dn_isNight() {
		date = new Date();
		hours = date.getHours() + (date.getTimezoneOffset()/60);
		if((hours >= 20 && hours < 24) || (hours >= 0 && hours < 7)) return true;
	}
	
	function dn_doNight() {
		$('body').addClass('bd-night');		
		swfobject.removeSWF("ft-movie");
		$('#ft-movie').empty().remove();
		dn_footermovieelement.prependTo('#footer');
		swfobject.embedSWF("swf/bottom_night_1024.swf", "ft-movie", "1024", "150", "9.0.0", false, {}, {wmode: 'transparent'});
	}
	
	function dn_doDay() {
		$('body').removeClass('bd-night');
		swfobject.removeSWF("ft-movie");
		$('#ft-movie').empty().remove();
		dn_footermovieelement.prependTo('#footer');
		swfobject.embedSWF("swf/bottom_day_1024.swf", "ft-movie", "1024", "150", "9.0.0", false, {}, {wmode: 'transparent'});
	}
	
	$(document).ready(function() {
		
		// add manual switcher button
		$('#header').append('<div id="hd-extra-daynightswitch"><a href="#">day-night-switch</a></div>');
		
		// clone alt content being replaced because swfobject.removeSWF() doesn't revert alt content
		dn_footermovieelement = $('#ft-movie').clone();
		
		// manual controls
		$('#hd-extra-daynightswitch a').click(
			
			function(event){
				
				event.preventDefault();
				
				if($('body').hasClass('bd-night')) {
					dn_doDay();
				}else {
					dn_doNight();
				}
			}
		);
		
		// init
		if(dn_isNight()) {
			dn_doNight();
		}else {
			dn_doDay();
		}
		
	});
		
})(jQuery);
