$(function(){
	/*
	var raysmax 			= 3
		, $pagecontainer 	= $('#page-container')
		, raydelay 			= ($.browser.msie)?200:180
		, $preloadrays 		= $('#preload .rays');
	
	function nextray () {
		var bimg 		= $pagecontainer.css('background-image')
			, num 		= parseInt(/frame\.(\d*)/g.exec(bimg)[1])
			, nextnum 	= ((num + 1) < raysmax)? num + 1: 0
			, newbimg 	= bimg.replace('frame.' + num, 'frame.' + nextnum);

		$pagecontainer.css('background-image', newbimg);
	}
	
	var raysi = null;
	function startraysinterval () {
		if (raysi) return;
		raysi = setInterval(nextray, raydelay);
		clearTimeout(raystimeout);
	}

	var raystoload = $preloadrays.length
		, preloadraysi = 0;
	if (raystoload > raysmax) raystoload = raysmax;
	var remainingraystoload  = raystoload;
	// start rays animation when images are loaded ...
	$('#preload .rays').each(function(){
		if (preloadraysi++ < raystoload) {
			var $this = $(this);
			$this.load(function(){
				if (--remainingraystoload < 1) startraysinterval();
			});
		}
	});
	// ... or after 10 seconds
	var raystimeout = setTimeout(startraysinterval, 10000);
	
	if (typeof $.jPlayer == 'function') {
		$player = $('#bg-music').jPlayer({
			ready: function() { // The $.jPlayer.event.ready event
			$(this).jPlayer("setMedia", { // Set the media
				mp3: wp.template_url + '/teaser/media/theme.mp3'
			}).jPlayer("play"); // Attempt to auto play the media
			},
			ended: function() { // The $.jPlayer.event.ended event
				$(this).jPlayer("play"); // Repeat the media
			}
			, supplied: "mp3"
			, swfPath: wp.template_url + '/teaser/js/'
		});
		
		$('#music .playpause').click(function(){
			var $this = $(this);
			if ($this.is('.mute')) {
				$player.jPlayer('play');
				$this.removeClass('mute'); 
			} else {
				$player.jPlayer('pause');
				$this.addClass('mute'); 
			}
		});
	}
	
	if (typeof $.fancybox == 'function') {
		$('#read-more a').fancybox({
			'titlePosition'		: 'inside'
			, 'transitionIn'	: 'none'
			, 'transitionOut'	: 'none'
			, 'href'			: '#letter-content'
		});
	}
	*/
	
	// countdown
	var $countdown = $('#date-header .countdown');
	var total = $countdown.attr('total');

	if (total) {
		var $s = $('.seconds', $countdown);
		var $ss = $('span', $s);
		var $m = $('.minutes', $countdown);
		var $mm = $('span', $m);
		var $h = $('.hours', $countdown);
		var $hh = $('span', $h);
		var $d = $('.days', $countdown);
		var $dd = $('span', $d);
		
		if (typeof bms_json == 'object') {
			var json = bms_json;
		} else {
			var json = [];
			json['going'] = 'Est&aacute; rolando!';
		}
		
		var done 	= [];
		done['d'] 	= $d.is('.zero');
		done['h'] 	= $h.is('.zero');
		done['m'] 	= $m.is('.zero');
		done['s'] 	= $s.is('.zero');
		function countdown () {
			
			var s = parseInt($ss.html());
			
			if (s > 0) {
				s--;
			} else if (!done['m']){
				var m = parseInt($mm.html());
				if (m > 0) {
					m--;
					
					if (done['h'] && $m <= 0) {
						$m.addClass('zero');
						done['m'] = true;
					}
					
				} else if (!done['h']) {
					var h = parseInt($hh.html());
					if (h > 0) {
						h--;
					
					if (done['d']) {
						$h.addClass('zero');
						done['h'] = true;
					}
					
					} else if (!done['d']) {
						var d = parseInt($dd.html());
						d--;
						if (d >= 0) {
							$dd.html((d>0)?d:'0');
							if (typeof json['days'] != 'undefined') {
								var dhtml = ($d.html().toString()).replace(json['days']['days'],json['days']['day']);
								if (d === 1)
									$d.html( dhtml.replace(json['days']['days'],json['days']['day']) );
								else 
									$d.html( dhtml.replace(json['days']['day'],json['days']['days']) );
							}
						}
						if (d <= 0) {
							$d.addClass('zero');
							done['d'] = true;
							$dd.html(0);
						}
						var h = 24;
					}
					
					$hh.html((h>0)?h:'0');
					var m = 59;
				}
				
				$mm.html((m>0)?m:'0');
				var s = 59;
			} else { // m = 0 and s = 0
				// COUNT FINISHED!!!
				$s.addClass('zero');
				done['s'] = true;
				clearInterval($countdown.interval);
				$countdown.html('<span>'+json['going']+'</span>');
				$countdown.addClass('going');
				
				return;
			}
			$ss.html((s>0)?s:'0');
			
			total--;
			$countdown.attr('total', total);
			if (total < 0) clearInterval($countdown.interval);
		}
		
		countdown();
		$countdown.interval = setInterval(countdown, 1000);

		
		/* ie7 hacks */
		if ($.browser.msie && $.browser.version < 8) {
			$(document).ready(function(){
			$('#date-header .date-countdown').width('100%').css('clear', 'both').css('max-height', '44px');
			})
		
		}
		
	}
	
})
