var shadowbox_restore_volume = null;
var fade_step = 3;
var fade_interval = 15;
var sound_fade = null;

function fadeVolumeOut(){
	var volume = $("#jquery_jplayer").jPlayer("getData", "volume");
	volume -= fade_step;
	// done with fading
	if (volume <= 0) {
		$("#jquery_jplayer").jPlayer("volume", 0);
		if (sound_fade != null)
			clearInterval(sound_fade);
		$("#jquery_jplayer").jPlayer("stop");
	} else {
		$("#jquery_jplayer").jPlayer("volume", volume);
	}
}

function fadeVolumeIn(){
	if (shadowbox_restore_volume==null){
		if (sound_fade != null)
			clearInterval(sound_fade);
		return;
	}
		
	var volume = $("#jquery_jplayer").jPlayer("getData", "volume");
	volume += fade_step;
	// done with fading
	if (shadowbox_restore_volume==null || volume >= shadowbox_restore_volume) {
		$("#jquery_jplayer").jPlayer("volume", shadowbox_restore_volume);
		if (sound_fade != null)
			clearInterval(sound_fade);
	} else {
		$("#jquery_jplayer").jPlayer("volume", volume);
	}
}

function shadowboxMuteBackground( cacheElem ){
	$("#jquery_jplayer").jPlayer("stop");
	$("#jquery_jplayer").css({diplay:"none"});
//	shadowbox_restore_volume = $("#jquery_jplayer").jPlayer("getData", "volume");
//	sound_fade = setInterval("fadeVolumeOut()", fade_interval);
} 

function shadowboxUnmuteBackground( cacheElem ){
	$("#jquery_jplayer").css({diplay:"block"});
	$("#jquery_jplayer").jPlayer("play");
//	sound_fade = setInterval("fadeVolumeIn()", fade_interval);
} 

function shadowboxSubmit( cacheElem ){
  document.subscribeform.submit();
} 

function show_shadowbox(url, height, width, player, title, mute){
// create and setup shoadowbox config_option object
	var config_options = {};
	config_options.overlayOpacity = 0.84;
	if (player=="form") {
		player = "iframe";
		config_options.onFinish = shadowboxSubmit;
	} 
	if (mute) {
		config_options.onOpen = shadowboxMuteBackground;
		config_options.onClose = shadowboxUnmuteBackground;
	} else {
		shadowbox_restore_volume = null;
	}
	

// create and setup jw player config_flashparams object
	config_flashparams = {};
    config_flashparams.allowscriptaccess= 'always';
    config_flashparams.allowfullscreen= 'true';

	config_options.flashParams = config_flashparams;

    Shadowbox.open({
        content:    url,
        player:     player,
        title:      title,
        height:     height,
        width:      width,
		options : 	config_options
    });
}
