/* ************************************************************************ */
/*                                                                          */
/*  SOUND.JS controlls the FLASH/JS Sound Obj.                              */
/*  (c)d.k.d 2007 // Jens Hoffmann                                          */
/*                                                                          */
/* ************************************************************************ */

soundManager.url                      = par.snd.swfURL;  // path to 1px flash palyer
soundManager.nullURL                  = par.snd.nullURL; // path to "fake" unload sounds

soundManager.debugMode                = false;       	 // Run Debug Functions
soundManager.useConsole               = true;        	 // Browser Console
soundManager.consoleOnly              = true;        	 // No Output at Screen

soundManager.allowPolling             = true;

soundManager.defaultOptions.autoLoad  = true;       	 // enable automatic loading
soundManager.defaultOptions.stream    = true;        	 // allows playing before entire file has loaded
soundManager.defaultOptions.autoPlay  = false;       	 // enable playing of file as soon as possible ( true = PlayBGsound will not be used !!! )
soundManager.defaultOptions.multiShot = true;		 	 // let sounds "restart" or layer on top of each other when played multiple times

soundManager.defaultOptions.volume    = 50;

/* ************************************************************************ */
/*  Activate Sounds Object                                                  */
/* ************************************************************************ */

var soundObj = {

	soundISon:   true,
	firstPlay:   true,
	soundBTNobj: null,	// switch sound on/off
	loopNR:		 0,

	init: function() {

		var currentZone = clientTimeZone.getZone();
		this.soundBTNobj = $(par.snd.btnID);
		
		// Get parent LI of A, and remove the no-js Fallback
		this.soundBTNobj.getParent().setStyle('display','block');

		soundManager.onload = function() {

			// Debug
			// if (window.gecko && typeof(console) == 'object') console.log("Cookie: %o // soundISon: %o", Cookie.get("soundOff"), soundObj.soundISon);

			// Get MP3 file via XML >> /fileadmin/fm-alex/musik/nachts.xml
			soundManager.loadFromXML(par.snd.xmlURL + currentZone + ".xml");
			
			// If no Cookie was found, play the BG sound
			if (Cookie.get("soundOff") === false && soundObj.soundISon === true){
				(function(){
					// Start the BG sound after some ms delay on first init ...
					soundObj.soundISon = true;
					soundObj.firstPlay = false;
					soundObj.switchToggle();
					soundObj.playBGsound();
				}).delay(par.snd.initDelay);
			} else {
				if (window.ie) {
					alert("Sound Cookie found ... SOUND = OFF");
				}
				soundObj.soundISon = false;
				soundObj.firstPlay = false;
				soundObj.switchToggle();
			}

		};
		
		
	},

	playBGsound: function() {

		if (soundManager.enabled) {
			// Play the BG sound recursive .... endless ;)
			soundManager.play( par.snd.bgSNDid, {
				onfinish:(
					function(){
						// Recursiv Call to loop BG sound
						soundObj.playBGsound();
					}
				)
			});
			// if (window.gecko && typeof(console) == 'object') console.log("Playing BG Sound with ID: %o >> Loop: %o", par.snd.bgSNDid, soundObj.loopNR++);
			// Set the Volume (0-100)
			soundManager.setVolume( par.snd.bgSNDid, 100 );
		} else {
			if (window.gecko && typeof(console) == 'object') {
				console.log("DEV ERROR: soundManager is DISABELED (SWF/XML not loaded) !!!");
			}
		}
	
	},

	soundPause: function() {

		// Toggle Play Mode Indicator
		if (soundObj.soundISon) {
			soundObj.soundISon = false;
		} else {
			soundObj.soundISon = true;
		}

		// Remove/Install Cookie
		if (soundObj.soundISon){
			Cookie.remove("soundOff");
			// if (window.gecko && typeof(console) == 'object') console.log("Sound is now ON >> Cookie was REMOVED!");
		} else {
			Cookie.set("soundOff", 'true', { duration: 64 }); // 64 Days
			// if (window.gecko && typeof(console) == 'object') console.log("Sound is now OFF << Cookie was INSTALLED!");
		}

		// Toggle Sound (ON/OFF)
		soundManager.togglePause( 'bgSND', {
			onfinish:(
				function(){
					soundObj.playBGsound();
				}
			)
		});
		soundObj.switchToggle();
		
		// Set the volume (0-100)
		soundManager.setVolume( 'bgSND', 100 );
	},

	stopAsound: function( soundID ) {
		soundObj.soundISon = false;
		soundManager.stop( soundID );
		Cookie.set("soundOff", 1, { duration: {days: 360} });
	},

	switchToggle: function() {
		if (this.soundISon) {
			this.soundBTNobj.removeClass('soundOFF');
			this.soundBTNobj.addClass('soundON');
			$E('img', this.soundBTNobj).setProperty('src', 'fileadmin/templates/alexgastro/images/menu/sound-on-no.gif');
		} else {
			this.soundBTNobj.removeClass('soundON');
			this.soundBTNobj.addClass('soundOFF');
			$E('img', this.soundBTNobj).setProperty('src', 'fileadmin/templates/alexgastro/images/menu/sound-off-no.gif');
		}
	
		// if (window.gecko && typeof(console) == 'object') console.log("SoundISon: %o - Class: %o", this.soundISon, this.soundBTNobj.getProperty("class"));
	}

};

/* ************************************************************************ */

