Shadowbox.init({
	players: ['flv','swf','html'],
	flashVars: {
		skin: '/mediaplayer/skins/nacht.swf'
	},
	onOpen: function(){
		$('#home-rotator').cycle('pause');
	},
	onClose: function(){
		$('#home-rotator').cycle('resume');
	}
});

$(function(){
	// Auto set value for text fields
    $('input.autofill').each(function(){
        var $$ = $(this);
        var $l = $('label[for="'+$$.attr('id')+'"]');
        $l.hide();
        
        $$.focus(function(){
            if ($.trim($$.val()) == $l.text()) {
                $$.val('');
            }
            
            $$.removeClass('blur');
        });
        
        $$.blur(function(){
            if ($.trim($$.val()) == '') {
                $$.val($l.text());
            }
            
            $$.addClass('blur');
        });
        
        $$.blur();
    });

	$('a.popup').click(function(){
		newWin($(this).attr('href'), 400, 200, 'audio-player');
		return false;
	});

	var rotatorCount = $('#home-rotator > *').length;
	$('#home-rotator div').append('<div class="shade">');
	$('#home-rotator').css('height', '').after('<ul id="rotator-controls">');
	$('#home-rotator > :first').fadeIn(1000, function(){
		$('#home-rotator').cycle({
			timeout: 4000,
			pause: 1,
			pauseOnPagerHover: true,
			pager: 	'#rotator-controls',
			pagerAnchorBuilder: function(idx, slide) { 
				var out;
				if (idx == (rotatorCount - 1)) {
					out = '<li class="last"><a href="#"></a></li>';
				} else {
					out = '<li><a href="#"></a></li>';
				}
		        return out;
		    }
		});
	});
	
});

function newWin(url, w, h, winName) {
	l = (screen.width/2) - (w/2);
	t = (screen.height/2) - (h/2);
	var win = window.open(url, winName, 'width='+w+',height='+h+',left='+l+',top='+t+',resizable=yes,status=no,toolbar=no,menubar=no,location=no,scrollbars=no');
	win.focus();
}